From 10b0893076e97cf612d6184c72884c0c26aa4b8d Mon Sep 17 00:00:00 2001 From: jgarriuni Date: Mon, 11 Jun 2018 13:35:44 +0200 Subject: [PATCH] F #994 Keep BOOT state for managed VMs until the running state is confirmed (#2169) * Added VCENTER_ESX_HOST field for VNC * Added VCENTER_ESX_HOST for VNC * Remove some lines --- src/sunstone/OpenNebulaVNC.rb | 13 ++++--------- src/vmm_mad/remotes/lib/vcenter_driver/importer.rb | 11 ++--------- .../remotes/lib/vcenter_driver/virtual_machine.rb | 1 - src/vmm_mad/remotes/vcenter/deploy | 13 ++----------- src/vmm_mad/remotes/vcenter/migrate | 7 +++---- 5 files changed, 11 insertions(+), 34 deletions(-) diff --git a/src/sunstone/OpenNebulaVNC.rb b/src/sunstone/OpenNebulaVNC.rb index e07f6c7ca8..31cc760c99 100644 --- a/src/sunstone/OpenNebulaVNC.rb +++ b/src/sunstone/OpenNebulaVNC.rb @@ -99,8 +99,6 @@ VNC_STATES = [ #64 #DISK_RESIZE_UNDEPLOYED ] -VNC_ESX_HOST_FOLDER = "/tmp" - class OpenNebulaVNC attr_reader :proxy_port @@ -215,15 +213,12 @@ class OpenNebulaVNC # If it is a vCenter VM if vm_resource['USER_TEMPLATE/HYPERVISOR'] == "vcenter" - if vm_resource['MONITORING/VCENTER_ESX_HOST'] + if vm_resource['USER_TEMPLATE/VCENTER_ESX_HOST'] + host = vm_resource['USER_TEMPLATE/VCENTER_ESX_HOST'] + elsif vm_resource['MONITORING/VCENTER_ESX_HOST'] host = vm_resource['MONITORING/VCENTER_ESX_HOST'] else - # F#4242 get ESX host from file if it hasn't been monitored yet - begin - host = File.read(File.join(VNC_ESX_HOST_FOLDER, "vcenter_vnc_#{vm_resource["/VM/ID"]}")) - rescue - return error(400,"Could not determine the vCenter ESX host where the VM is running. Wait till the VCENTER_ESX_HOST attribute is retrieved once the host has been monitored") - end + return error(400,"Could not determine the vCenter ESX host where the VM is running. Wait till the VCENTER_ESX_HOST attribute is retrieved once the host has been monitored") end end diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/importer.rb b/src/vmm_mad/remotes/lib/vcenter_driver/importer.rb index e2c92a8d9a..8583e736c8 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/importer.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/importer.rb @@ -1,8 +1,6 @@ module VCenterDriver class Importer -VNC_ESX_HOST_FOLDER = "/tmp" - def self.import_wild(host_id, vm_ref, one_vm, template) begin @@ -62,6 +60,7 @@ def self.import_wild(host_id, vm_ref, one_vm, template) end template << template_nics + template << "VCENTER_ESX_HOST = #{vcenter_vm["runtime.host.name"].to_s}\n" # Get DS_ID for the deployment, the wild VM needs a System DS dc_ref = vcenter_vm.get_dc.item._ref @@ -83,7 +82,7 @@ def self.import_wild(host_id, vm_ref, one_vm, template) end end end - return OpenNebula::Error.new("DS with ref #{ds_ref} is not imported in OpenNebula, aborting Wild VM import.") + return OpenNebula::Error.new("DS with ref #{ds_ref} is not imported in OpenNebula, aborting Wild VM import.") end rc = one_vm.allocate(template) @@ -137,12 +136,6 @@ def self.import_wild(host_id, vm_ref, one_vm, template) vcenter_vm.item.ReconfigVM_Task(:spec => spec).wait_for_completion end - # Add VCENTER_ESX_HOST to MONITOR info so VNC works for running VMs F#4242 - esx_host = vcenter_vm["runtime.host.name"].to_s - f = File.open(File.join(VNC_ESX_HOST_FOLDER, "vcenter_vnc_#{one_vm.id}"), 'w') - f.write(esx_host) - f.close - return one_vm.id rescue Exception => e diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb index 1ccb209a4d..357f579edf 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb @@ -3503,7 +3503,6 @@ class VmImporter < VCenterDriver::VcImporter dpool, ipool, npool, hpool = create_pools template = VCenterDriver::Template.new_from_ref(selected[:vcenter_ref], @vi_client) - # Linked clones and copy preparation if linked_clone if copy # reached this point we need to delete the template if something go wrong diff --git a/src/vmm_mad/remotes/vcenter/deploy b/src/vmm_mad/remotes/vcenter/deploy index e9821293ce..191be1373a 100755 --- a/src/vmm_mad/remotes/vcenter/deploy +++ b/src/vmm_mad/remotes/vcenter/deploy @@ -29,8 +29,6 @@ $: << File.dirname(__FILE__) require 'vcenter_driver' -VNC_ESX_HOST_FOLDER = "/tmp" - dfile = ARGV[0] cluster_name = ARGV[1] vm_id = ARGV[2] @@ -42,21 +40,18 @@ deploy_id = drv_action["DEPLOY_ID"] host_id = drv_action["HISTORY_RECORDS/HISTORY/HID"] begin - vi_client = VCenterDriver::VIClient.new_from_host(host_id) + vi_client = VCenterDriver::VIClient.new_from_host(host_id) one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id) if deploy_id && !deploy_id.empty? - # 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 vc_template_ref = drv_action['USER_TEMPLATE/VCENTER_TEMPLATE_REF'] - # VM is new # Clone the VM from template and provide XML info vm = VCenterDriver::VirtualMachine.new_from_clone(vi_client, drv_action, vm_id) - # Set reference to template disks and nics in VM template for detach ops vm.reference_unmanaged_devices(vc_template_ref) end @@ -68,11 +63,7 @@ begin vm.poweron vm.set_running(true) - # Add VCENTER_ESX_HOST to MONITOR info so VNC works for running VMs F#4242 - esx_host = vm["runtime.host.name"] - f = File.open(File.join(VNC_ESX_HOST_FOLDER, "vcenter_vnc_#{one_vm["ID"]}"), 'w') - f.write(esx_host) - f.close + vm.one_item.update("VCENTER_ESX_HOST = #{vm["runtime.host.name"]}", true) puts vm['_ref'] diff --git a/src/vmm_mad/remotes/vcenter/migrate b/src/vmm_mad/remotes/vcenter/migrate index 69d408ec24..269774df71 100755 --- a/src/vmm_mad/remotes/vcenter/migrate +++ b/src/vmm_mad/remotes/vcenter/migrate @@ -15,7 +15,6 @@ # See the License for the specific language governing permissions and # # limitations under the License. # # ---------------------------------------------------------------------------- # - ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) if !ONE_LOCATION @@ -35,7 +34,7 @@ src_host = ARGV[-3] dst_host = ARGV[-4] begin - + one_client = OpenNebula::Client.new pool = OpenNebula::HostPool.new(one_client) @@ -61,9 +60,9 @@ begin config = {:cluster => vc_host } vc_vm.migrate(config) - vm.replace({"VCENTER_CCR_REF" => dst_host["/HOST/TEMPLATE/VCENTER_CCR_REF"] }) + vm.replace({"VCENTER_CCR_REF" => dst_host["/HOST/TEMPLATE/VCENTER_CCR_REF"], "VCENTER_ESX_HOST" => dst_host["/HOST/TEMPLATE/HOST/HOSTNAME"]}) rescue Exception => e - + message = "Cannot migrate for VM #{vm_id}"\ "failed due to "\ "\"#{e.message}\"\n"