Revision c8d4f054 src/cli/onevm

View differences:

src/cli/onevm
342 342

  
343 343
* resume (Resumes the execution of a saved VM)
344 344
    onevm resume <vm_id>
345

  
345
    
346
* saveas (Set the specified vm's disk to be saved in a new image (image_name) 
347
            when the vm shutdowns)
348
    onevm saveas <vm_id> <disk_id> <image_name>
349
        
350
* save (Set the specified vm's disk to be saved, overwriting the original image 
351
            when the vm shutdowns)
352
    onevm saveas <vm_id> <disk_id>
353
        
346 354
* delete (Deletes a VM from the pool and DB)
347 355
    onevm delete <vm_id>
348 356

  
......
670 678
            break
671 679
        end
672 680
    end
673

  
681
    
682
when "saveas"
683
    check_parameters("saveas", 3)
684
    vm_id = get_vm_id(ARGV[0])
685
    disk_id = ARGV[1]
686
    image_name = ARGV[2]
687

  
688
    # Get the Image ID for this disk
689
    vm = OpenNebula::VirtualMachine.new(
690
                OpenNebula::VirtualMachine.build_xml(vm_id),
691
                get_one_client)
692
                
693
    result = vm.info
694
    if !is_successful?(result) 
695
        puts result.message
696
        exit -1
697
    end
698
    
699
    image_id = vm["TEMPLATE/DISK[DISK_ID=\"#{disk_id}\"]/IMAGE_ID"]
700
    
701
    # Get the image type 
702
    image = OpenNebula::Image.new(
703
                OpenNebula::Image.build_xml(image_id),
704
                get_one_client)
705
    
706
    result = image.info
707
    if !is_successful?(result) 
708
        puts result.message
709
        exit -1
710
    end
711
    
712
    if ops[:type]
713
        image_type = ops[:type]
714
    else
715
        image_type = image.type_str
716
    end
717
    
718
    # Build the template and allocate the new Image
719
    template = "NAME=#{image_name}\n"
720
    template << "TYPE=#{image_type}\n" if type
721

  
722
    
723
    image = OpenNebula::Image.new(
724
                            OpenNebula::Image.build_xml, 
725
                            get_one_client)
726
                            
727
    result = image.allocate(template)
728
    
729
    if !is_successful?(result) 
730
        puts result.message
731
        exit -1
732
    end
733
    
734
    result = vm.save_disk(disk_id.to_i, image.id)
735

  
736
when "save"
737
    check_parameters("save", 2)
738
    vm_id = get_vm_id(ARGV[0])
739
    disk_id = ARGV[1]
740

  
741
    # Get the Image ID for this disk
742
    vm = OpenNebula::VirtualMachine.new(
743
                OpenNebula::VirtualMachine.build_xml(vm_id),
744
                get_one_client)
745
                
746
    result = vm.info
747
    if !is_successful?(result) 
748
        puts result.message
749
        exit -1
750
    end
751
    
752
    image_id = vm["TEMPLATE/DISK[DISK_ID=\"#{disk_id}\"]/IMAGE_ID"]
753
    
754
    result = vm.save_disk(disk_id.to_i, image_id)
755
    
674 756
when "show"
675 757
    check_parameters("get_info", 1)
676 758
    args=expand_args(ARGV)

Also available in: Unified diff