1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

B #2649: [vCenter]: Reduce reconfigure overhead

This commit is contained in:
sergio semedi 2018-11-27 11:03:52 +01:00 committed by Ruben S. Montero
parent 17334789d4
commit 20b37ea7cc
2 changed files with 54 additions and 13 deletions

View File

@ -458,6 +458,8 @@ class VirtualMachine < VCenterDriver::Template
end
def get_unmanaged_keys
return @keys if @keys
unmanaged_keys = {}
@item.config.extraConfig.each do |val|
if val[:key].include?("opennebula.disk")
@ -672,7 +674,6 @@ class VirtualMachine < VCenterDriver::Template
# @item is populated
@item = vm
reference_unmanaged_devices(vc_template_ref) unless instantiated_as_persistent?
return self['_ref']
end
@ -951,9 +952,10 @@ class VirtualMachine < VCenterDriver::Template
end
end
def reference_unmanaged_devices(template_ref)
def reference_unmanaged_devices(template_ref, execute = true)
extraconfig = []
device_change = []
spec = {}
# Get unmanaged disks in OpenNebula's VM template
xpath = "TEMPLATE/DISK[OPENNEBULA_MANAGED=\"NO\" or OPENNEBULA_MANAGED=\"no\"]"
@ -989,6 +991,11 @@ class VirtualMachine < VCenterDriver::Template
reference[:value] = "#{vcenter_disk[:key]}"
extraconfig << reference
end
if !execute
@keys = {}
extraconfig.each {|r| @keys[r[:key]] = r[:value]}
end
end
# Add info for existing nics in template in vm xml
@ -1018,11 +1025,15 @@ class VirtualMachine < VCenterDriver::Template
# Save in extraconfig the key for unmanaged disks
if !extraconfig.empty? || !device_change.empty?
spec = {}
spec[:extraConfig] = extraconfig if !extraconfig.empty?
spec[:deviceChange] = device_change if !device_change.empty?
return spec unless execute
@item.ReconfigVM_Task(:spec => spec).wait_for_completion
end
{}
end
def resize_unmanaged_disks
@ -1132,11 +1143,28 @@ class VirtualMachine < VCenterDriver::Template
# TODO
# Synchronize the OpenNebula VM representation with vCenter VM
def sync
def sync(deploy = {})
extraconfig = []
device_change = []
sync_disks(:all)
# deploy operation, no instantiated as persistent
if deploy[:template_ref] && !instantiated_as_persistent?
template_ref = deploy[:template_ref]
refs = reference_unmanaged_devices(template_ref)
# changes in deploy op (references)
device_change += refs[:deviceChange] if refs[:deviceChange]
extraconfig += refs[:extraConfig] if refs[:extraConfig]
end
info_disks
nresize_unmanaged_disks
disks = sync_disks(:all, false)
# changes from sync_disks
device_change += disks[:deviceChange] if disks[:deviceChange]
extraconfig += disks[:extraConfig] if disks[:extraConfig]
# get token and context
extraconfig += extraconfig_context
@ -1144,6 +1172,9 @@ class VirtualMachine < VCenterDriver::Template
# vnc configuration (for config_array hash)
extraconfig += extraconfig_vnc
# opennebula.running flag
extraconfig += set_running(true, false)
# device_change hash (nics)
device_change += device_change_nics
@ -1157,6 +1188,7 @@ class VirtualMachine < VCenterDriver::Template
}
spec = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash)
@item.ReconfigVM_Task(:spec => spec).wait_for_completion
end
@ -1674,16 +1706,17 @@ class VirtualMachine < VCenterDriver::Template
end
# Remove reference opennebula.disk if exist
extra_config << disk.config(:delete) if keys["#{d.key}"]
extra_config << d.config(:delete) if keys["#{d.key}"]
end
return detach_disk_array, extra_config
end
# TODO
def sync_disks(option = :nil)
def sync_disks(option = :nil, execute = true)
spec_hash = {}
device_change_d = []
device_change_a = []
extra_config = []
device_change_d, extra_config = detach_disks_specs if option == :all
@ -1694,7 +1727,13 @@ class VirtualMachine < VCenterDriver::Template
spec_hash[:extraConfig] = create_storagedrs_disks(device_change_spod, device_change_spod_ids)
end
spec_hash[:deviceChange] = device_change_a + device_change_d
device_change = device_change_a + device_change_d
if !device_change.empty?
spec_hash[:deviceChange] = device_change_a + device_change_d
end
return spec_hash unless execute
spec = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash)
@item.ReconfigVM_Task(:spec => spec).wait_for_completion
@ -2583,12 +2622,15 @@ class VirtualMachine < VCenterDriver::Template
@item.guest.toolsRunningStatus == 'guestToolsRunning'
end
def set_running(state)
def set_running(state, execute = true)
value = state ? "yes" : "no"
config_array = [
{ :key => "opennebula.vm.running", :value => value }
]
return config_array unless execute
spec = RbVmomi::VIM.VirtualMachineConfigSpec(
{ :extraConfig => config_array }
)

View File

@ -44,6 +44,7 @@ drv_action.initialize_xml(Base64.decode64(STDIN.read), 'VM')
deploy_id = drv_action['DEPLOY_ID']
host_id = drv_action['HISTORY_RECORDS/HISTORY/HID']
deploy = {}
begin
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
@ -53,17 +54,15 @@ begin
# VM is not new, we just need to reconfigure it and to power it on
vm = VCenterDriver::VirtualMachine.new_one(vi_client, deploy_id, one_vm)
else
# VM is new, clone the VM from template
deploy[:template_ref] = drv_action['USER_TEMPLATE/VCENTER_TEMPLATE_REF']
vm = VCenterDriver::VirtualMachine.new_from_clone(vi_client,
drv_action,
vm_id)
end
if vm.is_powered_off?
vm.nresize_unmanaged_disks
vm.sync
vm.sync(deploy)
vm.poweron
vm.set_running(true)
end
puts vm['_ref']