VCenterDriver::VirtualMachine one_item should be always an instance of oca vm

This commit is contained in:
sergio semedi authored and Tino Vázquez committed 2019-02-05 11:44:27 +01:00
1 parent 262c905a97
commit 64525fa705
4 files changed
+17 -16

No files matched your search

@@ -969,11 +969,13 @@ class VirtualMachine < VCenterDriver::Template
# Queries to OpenNebula the machine disks xml representation
def get_one_disks
one_item.info
one_item.retrieve_xmlelements("TEMPLATE/DISK")
end
# Queries to OpenNebula the machine nics xml representation
def get_one_nics
one_item.info
one_item.retrieve_xmlelements("TEMPLATE/NIC")
end
@@ -1685,17 +1687,13 @@ class VirtualMachine < VCenterDriver::Template
end
# Add NIC to VM
def attach_nic
def attach_nic(one_nic)
spec_hash = {}
nic = nil
# Extract nic from driver action
nic = one_item.retrieve_xmlelements("TEMPLATE/NIC[ATTACH='YES']").first
begin
# A new NIC requires a vcenter spec
attach_nic_array = []
attach_nic_array << calculate_add_nic_spec(nic)
attach_nic_array << calculate_add_nic_spec(one_nic)
spec_hash[:deviceChange] = attach_nic_array if !attach_nic_array.empty?
# Reconfigure VM
@@ -1709,12 +1707,9 @@ class VirtualMachine < VCenterDriver::Template
end
# Detach NIC from VM
def detach_nic
def detach_nic(mac)
spec_hash = {}
# Extract nic from driver action
one_nic = one_item.retrieve_xmlelements("TEMPLATE/NIC[ATTACH='YES']").first
mac = one_nic["MAC"]
nic = nic(mac) rescue nil
return if !nic || nic.no_exists?
@@ -3018,7 +3013,9 @@ class VirtualMachine < VCenterDriver::Template
id = one_item["ID"] || one_item["VM/ID"] rescue -1
self.new(vi_client, ref, id).tap do |vm|
vm.one_item = one_item
if one_item.instance_of?(OpenNebula::VirtualMachine)
vm.one_item = one_item
end
end
end
+4 -1
View File
@@ -47,7 +47,10 @@ begin
vm = VCenterDriver::VirtualMachine.new_one(vi_client, vm_ref, one_item)
vm.attach_nic
# Extract nic from driver action
nic = one_item.retrieve_xmlelements("TEMPLATE/NIC[ATTACH='YES']").first
vm.attach_nic(nic)
rescue StandardError => e
message = "Attach NIC for VM #{vm_ref} on vCenter cluster "\
"#{vc_cluster_name} failed due to \"#{e.message}\"\n"
-3
View File
@@ -48,10 +48,7 @@ begin
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id)
vm.one_item = drv_action.retrieve_xmlelements('VM').first
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']
+5 -1
View File
@@ -46,7 +46,11 @@ begin
one_item = drv_action.retrieve_xmlelements('VM').first
vm = VCenterDriver::VirtualMachine.new_one(vi_client, vm_ref, one_item)
vm.detach_nic
# Extract nic from driver action
one_nic = one_item.retrieve_xmlelements("TEMPLATE/NIC[ATTACH='YES']").first
mac = one_nic["MAC"]
vm.detach_nic(mac)
rescue StandardError => e
message = "Detach NIC for VM #{vm_ref} on vCenter cluster " \
"#{vc_cluster_name} failed due to \"#{e.message}\"."