Skip to content

Commit

Permalink
B #3844: refactoring some functions (#3958)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos J. Herrera Matos <cherrera@opennebula.systems>
  • Loading branch information
carloshm91 authored and Tino V谩zquez committed Nov 19, 2019
1 parent 8fb2010 commit e1a6bf5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb
Expand Up @@ -930,6 +930,34 @@ def reference_unmanaged_devices(template_ref, execute = true)
{}
end

def reference_disks_all(template_ref = nil, execute = true)
extraconfig = []
spec = {}

# Get unmanaged disks in OpenNebula's VM template
xpath = "TEMPLATE/DISK[OPENNEBULA_MANAGED=\"NO\" or OPENNEBULA_MANAGED=\"no\"]"
unmanaged_disks = one_item.retrieve_xmlelements(xpath)

managed = false
extraconfig + reference_disks(template_ref, unmanaged_disks, managed)

# Get managed disks in OpenNebula's VM template
xpath = "TEMPLATE/DISK[OPENNEBULA_MANAGED=\"YES\" or OPENNEBULA_MANAGED=\"yes\"]"
managed_disks = one_item.retrieve_xmlelements(xpath)

managed = true
extraconfig + reference_disks(template_ref, managed_disks, managed)

# Save in extraconfig the key for unmanaged disks
unless extraconfig.empty?
spec[:extraConfig] = extraconfig unless extraconfig.empty?

return spec unless execute

@item.ReconfigVM_Task(:spec => spec).wait_for_completion
end
end

#聽Build extraconfig section to reference disks
# by key and avoid problems with changing paths
# (mainly due to snapshots)
Expand Down Expand Up @@ -2242,6 +2270,7 @@ def migrate(config = {})

def shutdown
if !is_powered_off?
reference_disks_all
begin
if vm_tools?
@item.ShutdownGuest
Expand All @@ -2266,6 +2295,7 @@ def mark_as_template
end

def reset
reference_disks_all
@item.ResetVM_Task.wait_for_completion
end

Expand All @@ -2274,10 +2304,12 @@ def suspend
end

def reboot
reference_disks_all
@item.RebootGuest
end

def poweron(set_running = false)
reference_disks_all
begin
@item.PowerOnVM_Task.wait_for_completion
rescue RbVmomi::Fault => e
Expand Down
3 changes: 2 additions & 1 deletion src/vmm_mad/remotes/vcenter/reboot
Expand Up @@ -37,6 +37,7 @@ require 'vcenter_driver'

vm_ref = ARGV[0]
vc_cluster_name = ARGV[1]
vm_id = ARGV[2]

drv_action = OpenNebula::XMLElement.new
drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA')
Expand All @@ -46,7 +47,7 @@ host_id = drv_action['VM/HISTORY_RECORDS/HISTORY/HID']
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)

vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id)

vm.reboot
rescue StandardError => e
Expand Down
3 changes: 2 additions & 1 deletion src/vmm_mad/remotes/vcenter/reset
Expand Up @@ -37,6 +37,7 @@ require 'vcenter_driver'

vm_ref = ARGV[0]
vc_cluster_name = ARGV[1]
vm_id = ARGV[2]

drv_action = OpenNebula::XMLElement.new
drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VMM_DRIVER_ACTION_DATA')
Expand All @@ -45,7 +46,7 @@ host_id = drv_action['VM/HISTORY_RECORDS/HISTORY/HID']

begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vm = VCenterDriver::VirtualMachine.new_without_id(vi_client, vm_ref)
vm = VCenterDriver::VirtualMachine.new(vi_client, vm_ref, vm_id)

vm.reset
rescue StandardError => e
Expand Down

0 comments on commit e1a6bf5

Please sign in to comment.