Revision 05ed37c9 src/vmm_mad/remotes/vcenter/vcenter_driver.rb

View differences:

src/vmm_mad/remotes/vcenter/vcenter_driver.rb
774 774
    #  @param deploy_id vcenter identifier of the VM
775 775
    #  @param hostname name of the host (equals the vCenter cluster)
776 776
    ############################################################################
777
    def self.cancel(deploy_id, hostname, lcm_state)
777
    def self.cancel(deploy_id, hostname, lcm_state, keep_disks)
778 778
        case lcm_state
779 779
            when "SHUTDOWN_POWEROFF", "SHUTDOWN_UNDEPLOY"
780 780
                shutdown(deploy_id, hostname, lcm_state)
......
789 789
                    end
790 790
                rescue
791 791
                end
792
                detach_all_disks(vm) if keep_disks
792 793
                vm.Destroy_Task.wait_for_completion
793 794
        end
794 795
    end
......
857 858
    #  @param deploy_id vcenter identifier of the VM
858 859
    #  @param hostname name of the host (equals the vCenter cluster)
859 860
    ############################################################################
860
    def self.shutdown(deploy_id, hostname, lcm_state)
861
    def self.shutdown(deploy_id, hostname, lcm_state, keep_disks)
861 862
        hid         = VIClient::translate_hostname(hostname)
862 863
        connection  = VIClient.new(hid)
863 864

  
......
870 871
                rescue
871 872
                end
872 873
                vm.PowerOffVM_Task.wait_for_completion
874
                detach_all_disks(vm) if keep_disks
873 875
                vm.Destroy_Task.wait_for_completion
874 876
            when "SHUTDOWN_POWEROFF", "SHUTDOWN_UNDEPLOY"
875 877
                begin
......
1203 1205
    end
1204 1206

  
1205 1207
    ########################################################################
1208
    #  Checks if a RbVmomi::VIM::VirtualDevice is a disk
1209
    ########################################################################
1210
    def self.is_disk?(device)
1211
        !device.class.ancestors.index(RbVmomi::VIM::VirtualDisk).nil?
1212
    end
1213

  
1214
    ########################################################################
1206 1215
    # Returns the spec to reconfig a VM and add a NIC
1207 1216
    ########################################################################
1208 1217
    def self.calculate_addnic_spec(vm, mac, bridge, model)
......
1411 1420

  
1412 1421
        return vm_uuid
1413 1422
    end
1423

  
1424
    ############################################################################
1425
    # Detach all disks from a VM
1426
    ############################################################################
1427
    def self.detach_all_disks(vm)
1428
        disks  = vm.config.hardware.device.select { |d| is_disk?(d) }
1429

  
1430
        return if disks.nil?
1431

  
1432
        spec = { :deviceChange => [] }
1433

  
1434
        disks.each{|disk|
1435
            spec[:deviceChange] <<  {
1436
                :operation => :remove,
1437
                :device => disk
1438
            }
1439
        }
1440

  
1441
        vm.ReconfigVM_Task(:spec => spec).wait_for_completion
1442
    end
1414 1443
end
1415 1444
end

Also available in: Unified diff