From 12b91e4484900e0d7ef5a47e86ae80c097b2cfd1 Mon Sep 17 00:00:00 2001 From: sergio semedi Date: Fri, 15 Feb 2019 15:54:37 +0100 Subject: [PATCH] F #2875: Support vCenter managed disk in DS migration --- src/vmm_mad/remotes/lib/vcenter_driver/datastore.rb | 6 ++++-- .../remotes/lib/vcenter_driver/virtual_machine.rb | 4 ---- src/vmm_mad/remotes/vcenter/cancel | 10 ---------- src/vmm_mad/remotes/vcenter/migrate | 8 +------- src/vmm_mad/remotes/vcenter/save | 12 ------------ src/vmm_mad/remotes/vcenter/shutdown | 13 ------------- 6 files changed, 5 insertions(+), 48 deletions(-) diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/datastore.rb b/src/vmm_mad/remotes/lib/vcenter_driver/datastore.rb index e3af24a07c..b2643133ca 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/datastore.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/datastore.rb @@ -385,13 +385,15 @@ class Datastore < Storage target_ds_vc = VCenterDriver::Datastore.new_from_ref(target_ds_ref, vi_client) dest_name = target_ds_vc['name'] - dest_path = "[#{dest_name}] #{dest_path}" + target_ds_vc.create_directory(File.dirname(dest_path)) + + dpath_ds = "[#{dest_name}] #{dest_path}" orig_path = "[#{self['name']}] #{disk.path}" move_params = { sourceName: orig_path, sourceDatacenter: get_dc.item, - destName: dest_path, + destName: dpath_ds, force: true } diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb index c17b5f418a..679997b987 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb @@ -2990,10 +2990,6 @@ class VirtualMachine < VCenterDriver::Template vc_vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm['/VM/DEPLOY_ID']) vc_vm.vm_id = vm_id - error = !vc_vm.disks_each(:managed?).empty? && !ds.nil? - # We know this comes from a migration from poweroff state (not a poweroff migration) - # since all the other cases are treated in vmm drivers: save, migrate and shutdown - raise 'datastore migration from poweroff state with managed disks is not supported' if error ccr_ref = dst_host['/HOST/TEMPLATE/VCENTER_CCR_REF'] vc_host = VCenterDriver::ClusterComputeResource.new_from_ref(ccr_ref, vi_client) diff --git a/src/vmm_mad/remotes/vcenter/cancel b/src/vmm_mad/remotes/vcenter/cancel index 1595620cbb..d9f9f96c2a 100755 --- a/src/vmm_mad/remotes/vcenter/cancel +++ b/src/vmm_mad/remotes/vcenter/cancel @@ -48,16 +48,6 @@ begin vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id) - if (%{'SAVE_MIGRATE'}).include?(lcm_state_str) - dst_ds = drv_action['VM/HISTORY_RECORDS/HISTORY/DS_ID'] - src_ds = drv_action['DATASTORE/ID'] - - new_ds = dst_ds != src_ds - - error = !vm.disks_each(:managed?).empty? && new_ds - raise 'cold datastore migration in poweroff hard with managed disk(s) is not supported' if error - end - vm.poweroff_hard rescue StandardError => e message = "Cancel VM #{vm_ref} failed due to "\ diff --git a/src/vmm_mad/remotes/vcenter/migrate b/src/vmm_mad/remotes/vcenter/migrate index 2c01e95421..40b33882f8 100755 --- a/src/vmm_mad/remotes/vcenter/migrate +++ b/src/vmm_mad/remotes/vcenter/migrate @@ -29,7 +29,6 @@ $LOAD_PATH << File.dirname(__FILE__) require 'vcenter_driver' -vm_ref = ARGV[0] vm_id = ARGV[-2] src_host = ARGV[-3] dst_host = ARGV[-4] @@ -41,12 +40,7 @@ dst_ds = drv_action['VM/HISTORY_RECORDS/HISTORY/DS_ID'] src_ds = drv_action['DATASTORE/ID'] begin - vi_client = VCenterDriver::VIClient.new_from_host(src_host) - vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id) - new_ds = dst_ds != src_ds - - error = !vm.disks_each(:managed?).empty? && new_ds - raise 'live datastore migration with managed disk is not supported' if error + new_ds = dst_ds != src_ds if new_ds VCenterDriver::VirtualMachine diff --git a/src/vmm_mad/remotes/vcenter/save b/src/vmm_mad/remotes/vcenter/save index 7bbb13712f..b6e0b8b497 100755 --- a/src/vmm_mad/remotes/vcenter/save +++ b/src/vmm_mad/remotes/vcenter/save @@ -55,19 +55,7 @@ begin vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref) - if (%{'SAVE_MIGRATE'}).include?(lcm_state_str) - vm.vm_id = vm_id - dst_ds = drv_action['VM/HISTORY_RECORDS/HISTORY/DS_ID'] - src_ds = drv_action['DATASTORE/ID'] - - new_ds = dst_ds != src_ds - - error = !vm.disks_each(:managed?).empty? && new_ds - raise 'cold datastore migration with managed disk(s) is not supported' if error - end - vm.suspend - rescue StandardError => e message = "Save of VM #{vm_ref} on vCenter cluster "\ "#{vc_cluster_name} failed due to "\ diff --git a/src/vmm_mad/remotes/vcenter/shutdown b/src/vmm_mad/remotes/vcenter/shutdown index 810795f9dc..817dac29d4 100755 --- a/src/vmm_mad/remotes/vcenter/shutdown +++ b/src/vmm_mad/remotes/vcenter/shutdown @@ -62,19 +62,6 @@ begin vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref) - - if (%{'SAVE_MIGRATE'}).include?(lcm_state_str) - vm.vm_id = vm_id - dst_ds = drv_action['VM/HISTORY_RECORDS/HISTORY/DS_ID'] - src_ds = drv_action['DATASTORE/ID'] - - new_ds = dst_ds != src_ds - - error = !vm.disks_each(:managed?).empty? && new_ds - raise 'cold datastore migration in poweroff with managed disk(s) is not supported' if error - end - - vm.shutdown # Undeploy, Poweroff or Terminate rescue StandardError => e message = "Shutdown of VM #{vm_ref} on vCenter cluster "\