mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
B #2624: [vCenter] persistency works with unmanaged disks
This commit is contained in:
parent
f850d10bfe
commit
526bfe09ee
@ -37,8 +37,10 @@ $: << File.dirname(__FILE__)
|
||||
|
||||
require 'vcenter_driver'
|
||||
|
||||
path = ARGV[0]
|
||||
vmid = ARGV[2]
|
||||
path = ARGV[0]
|
||||
im_path = ARGV[1]
|
||||
vmid = ARGV[2]
|
||||
dsid = ARGV[3]
|
||||
|
||||
check_valid path, "path"
|
||||
check_valid vmid, "vmid"
|
||||
@ -64,9 +66,16 @@ begin
|
||||
if disk
|
||||
vm.one_item = one_vm
|
||||
|
||||
# Don't detach persistent disks if the VM has snapshots,
|
||||
# or the instantiate to persistent is used
|
||||
vm.ndetach_disk(disk) if !vm.has_snapshots? && !vm.instantiated_as_persistent?
|
||||
# Don't detach persistent disks if the VM has snapshots
|
||||
# or the instantiate to persistent is used, we need the entire template and save it in delete process!
|
||||
if !vm.has_snapshots? && !vm.instantiated_as_persistent?
|
||||
vm.ndetach_disk(disk)
|
||||
|
||||
if disk.cloned?
|
||||
ds = VCenterDriver::Datastore.new(disk.ds)
|
||||
ds.move_virtual_disk(disk, im_path, dsid, vi_client)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
rescue Exception => e
|
||||
|
@ -376,6 +376,27 @@ class Datastore < Storage
|
||||
target_path
|
||||
end
|
||||
|
||||
def move_virtual_disk(disk, dest_path, dest_dsid, vi_client = nil)
|
||||
vi_client = @vi_client unless vi_client
|
||||
|
||||
target_ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore, dest_dsid, false)
|
||||
target_ds_ref = target_ds['TEMPLATE/VCENTER_DS_REF']
|
||||
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}"
|
||||
orig_path = "[#{self['name']}] #{disk.path}"
|
||||
|
||||
move_params = {
|
||||
sourceName: orig_path,
|
||||
sourceDatacenter: get_dc.item,
|
||||
destName: dest_path,
|
||||
force: true
|
||||
}
|
||||
|
||||
get_vdm.MoveVirtualDisk_Task(move_params).wait_for_completion
|
||||
end
|
||||
|
||||
def rm_directory(directory)
|
||||
ds_name = self['name']
|
||||
|
||||
|
@ -227,6 +227,10 @@ class VirtualMachine < VCenterDriver::Template
|
||||
@one_res["TYPE"] && @one_res["TYPE"].downcase == "fs"
|
||||
end
|
||||
|
||||
def cloned?
|
||||
@one_res['SOURCE'] != @vc_res[:path_wo_ds]
|
||||
end
|
||||
|
||||
def connected?
|
||||
raise @error_message unless @vc_res
|
||||
|
||||
@ -418,6 +422,10 @@ class VirtualMachine < VCenterDriver::Template
|
||||
one_item["DEPLOY_ID"].empty?
|
||||
end
|
||||
|
||||
def wild?
|
||||
!!(one_item['TEMPLATE/IMPORTED'] && one_item['TEMPLATE/IMPORTED'] == 'YES')
|
||||
end
|
||||
|
||||
# @return Boolean wheter the vm exists in OpenNebula
|
||||
def one_exist?
|
||||
!@vm_id.nil? && @vm_id != -1
|
||||
|
@ -47,7 +47,7 @@ class Template
|
||||
end
|
||||
end
|
||||
|
||||
def wild?
|
||||
def vm?
|
||||
self.class == VCenterDriver::VirtualMachine
|
||||
end
|
||||
|
||||
@ -255,7 +255,7 @@ class Template
|
||||
break
|
||||
end
|
||||
|
||||
opts = {:persistent => wild? ? "YES":"NO"}
|
||||
opts = {:persistent => vm? ? "YES":"NO"}
|
||||
image_import = VCenterDriver::Datastore.get_image_import_template(disk, ipool, type, datastore_found["ID"], opts)
|
||||
#Image is already in the datastore
|
||||
if image_import[:one]
|
||||
@ -424,7 +424,7 @@ class Template
|
||||
nic_tmp = "NIC=[\n"
|
||||
nic_tmp << "NETWORK_ID=\"#{network_found["ID"]}\",\n"
|
||||
|
||||
if wild?
|
||||
if vm?
|
||||
ar_tmp = create_ar(nic)
|
||||
network_found.add_ar(ar_tmp)
|
||||
network_found.info
|
||||
@ -462,7 +462,7 @@ class Template
|
||||
hpool)["CLUSTER_ID"] rescue -1
|
||||
end
|
||||
|
||||
if wild?
|
||||
if vm?
|
||||
unmanaged = "wild"
|
||||
else
|
||||
unmanaged = "template"
|
||||
@ -493,7 +493,7 @@ class Template
|
||||
ar_tmp << "SIZE=255\n"
|
||||
ar_tmp << "]\n"
|
||||
|
||||
if wild?
|
||||
if vm?
|
||||
ar_tmp << create_ar(nic, true)
|
||||
end
|
||||
|
||||
@ -509,7 +509,7 @@ class Template
|
||||
nic_tmp = "NIC=[\n"
|
||||
nic_tmp << "NETWORK_ID=\"#{one_vn.id}\",\n"
|
||||
|
||||
if wild?
|
||||
if vm?
|
||||
last_id = save_ar_ids(one_vn, nic, ar_ids)
|
||||
nic_tmp << "AR_ID=\"#{last_id}\",\n"
|
||||
nic_tmp << "MAC=\"#{nic[:mac]}\",\n" if nic[:mac]
|
||||
@ -665,7 +665,7 @@ class Template
|
||||
|
||||
nic = retrieve_from_device(device)
|
||||
nic[:mac] = device.macAddress rescue nil
|
||||
if wild?
|
||||
if vm?
|
||||
if online?
|
||||
inets_raw ||= @item["guest.net"].map.with_index { |x,i| [x.macAddress, x] }
|
||||
inets = parse_live.call(inets_raw) if inets.empty?
|
||||
|
Loading…
x
Reference in New Issue
Block a user