mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
vCenter fix migration between clusters, ds migration(WIP)
This commit is contained in:
parent
4a62a082f4
commit
ccf16a7205
@ -36,14 +36,14 @@ dsid = ARGV[3]
|
||||
|
||||
begin
|
||||
dst_path = OpenNebula.arg_path(dst)
|
||||
|
||||
host_orig = OpenNebula.arg_host(src)
|
||||
host_dest = OpenNebula.arg_host(dst)
|
||||
|
||||
exit 0 if OpenNebula.is_disk?(dst_path)
|
||||
exit 0 if src == dst
|
||||
|
||||
VCenterDriver::VirtualMachine.migrate_routine(vmid, host_orig, host_dest, dsid)
|
||||
# TODO: considerations about dsid argument, should be different to origin dsid
|
||||
VCenterDriver::VirtualMachine.migrate_routine(vmid, host_orig, host_dest)
|
||||
|
||||
rescue StandardError => e
|
||||
message = "Cannot migrate for VM #{vmid}"\
|
||||
|
@ -2457,19 +2457,24 @@ class VirtualMachine < VCenterDriver::Template
|
||||
end
|
||||
|
||||
def migrate(config = {})
|
||||
raise "You need at least 1 parameter" if config.size == 0
|
||||
raise "You need at least 1 parameter to perform a migration" if config.size == 0
|
||||
|
||||
begin
|
||||
# retrieve host from DRS
|
||||
resourcepool = config[:cluster].resourcePool
|
||||
datastore = config[:datastore]
|
||||
|
||||
relocate_spec_params = {}
|
||||
relocate_spec_params[:pool] = resourcepool
|
||||
relocate_spec_params[:datastore] = config[:datastore]
|
||||
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(relocate_spec_params)
|
||||
@item.RelocateVM_Task(spec: relocate_spec, priority: "defaultPriority").wait_for_completion
|
||||
if datastore
|
||||
relocate_spec_params = {
|
||||
pool: resourcepool,
|
||||
datastore: datastore,
|
||||
}
|
||||
|
||||
@item.MigrateVM_Task(:pool=> resourcepool, :priority => "defaultPriority").wait_for_completion
|
||||
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(relocate_spec_params)
|
||||
@item.RelocateVM_Task(spec: relocate_spec, priority: "defaultPriority").wait_for_completion
|
||||
else
|
||||
@item.MigrateVM_Task(:pool=> resourcepool, :priority => "defaultPriority").wait_for_completion
|
||||
end
|
||||
|
||||
rescue Exception => e
|
||||
raise "Cannot migrate VM #{e.message}\n#{e.backtrace.join("\n")}"
|
||||
@ -2923,12 +2928,15 @@ class VirtualMachine < VCenterDriver::Template
|
||||
pool = OpenNebula::HostPool.new(one_client)
|
||||
pool.info
|
||||
|
||||
datastores = OpenNebula::DatastorePool.new(one_client)
|
||||
datastores.info
|
||||
|
||||
src_id = pool["/HOST_POOL/HOST[NAME='#{src_host}']/ID"].to_i
|
||||
dst_id = pool["/HOST_POOL/HOST[NAME='#{dst_host}']/ID"].to_i
|
||||
datastore = datastores["/DATASTORE_POOL/DATASTORE[ID='#{ds}']/TEMPLATE/VCENTER_DS_REF"]
|
||||
|
||||
# diferent destination ds
|
||||
if ds
|
||||
ds_pool = OpenNebula::DatastorePool.new(one_client)
|
||||
ds_pool.info
|
||||
datastore = ds_pool["/DATASTORE_POOL/DATASTORE[ID='#{ds}']/TEMPLATE/VCENTER_DS_REF"]
|
||||
end
|
||||
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(src_id)
|
||||
|
||||
@ -2945,7 +2953,9 @@ class VirtualMachine < VCenterDriver::Template
|
||||
ccr_ref = dst_host['/HOST/TEMPLATE/VCENTER_CCR_REF']
|
||||
vc_host = VCenterDriver::ClusterComputeResource.new_from_ref(ccr_ref, vi_client).item
|
||||
|
||||
config = { :cluster => vc_host, :datastore => datastore }
|
||||
config = { :cluster => vc_host }
|
||||
|
||||
config[:datastore] = datastore if datastore
|
||||
vc_vm.migrate(config)
|
||||
|
||||
vm.replace({ 'VCENTER_CCR_REF' => ccr_ref})
|
||||
|
@ -34,6 +34,7 @@ src_host = ARGV[-3]
|
||||
dst_host = ARGV[-4]
|
||||
|
||||
begin
|
||||
# TODO: grab destination ds
|
||||
VCenterDriver::VirtualMachine.migrate_routine(vm_id,
|
||||
src_host,
|
||||
dst_host)
|
||||
|
Loading…
x
Reference in New Issue
Block a user