mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-25 23:21:29 +03:00
* Added VCENTER_ESX_HOST field for VNC * Added VCENTER_ESX_HOST for VNC * Remove some lines
This commit is contained in:
parent
1035df2b2f
commit
10b0893076
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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']
|
||||
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user