mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
F #4913: Remove opennebula.vm.id, get vm id from deploy_id and vcenter instance id
This commit is contained in:
parent
e8c40e9db7
commit
931523738f
@ -232,7 +232,7 @@ class ClusterComputeResource
|
||||
|
||||
rp.vm.each do |v|
|
||||
begin
|
||||
vm = VirtualMachine.new(v)
|
||||
vm = VirtualMachine.new(v, @vi_client)
|
||||
|
||||
number = -1
|
||||
|
||||
@ -251,13 +251,10 @@ class ClusterComputeResource
|
||||
matches = vm["name"].match(/^one-(\d*)(-(.*))?$/)
|
||||
number = matches[1] if matches
|
||||
|
||||
extraconfig_vmid = vm["config.extraConfig"].select do |val|
|
||||
val[:key] == "opennebula.vm.id"
|
||||
end
|
||||
# Extract vmid from ref and vcenter instance uuid if possible
|
||||
vm_id = vm.get_vm_id
|
||||
|
||||
if extraconfig_vmid.size > 0 and extraconfig_vmid[0]
|
||||
number = extraconfig_vmid[0][:value]
|
||||
end
|
||||
number = vm_id if vm_id
|
||||
|
||||
if number != -1
|
||||
next if @monitored_vms.include? number
|
||||
@ -268,7 +265,6 @@ class ClusterComputeResource
|
||||
|
||||
next if !vm["config"]
|
||||
|
||||
|
||||
str_info << %Q{
|
||||
VM = [
|
||||
ID="#{number}",
|
||||
|
@ -51,7 +51,8 @@ class VIHelper
|
||||
pool = one_pool(the_class, false) if pool.nil?
|
||||
element = pool.select{|e|
|
||||
e["#{attribute}"] == ref &&
|
||||
e["TEMPLATE/VCENTER_INSTANCE_ID"] == vcenter_uuid}.first rescue nil
|
||||
(e["TEMPLATE/VCENTER_INSTANCE_ID"] == vcenter_uuid ||
|
||||
e["USER_TEMPLATE/VCENTER_INSTANCE_ID"] == vcenter_uuid)}.first rescue nil
|
||||
|
||||
return element
|
||||
end
|
||||
|
@ -166,9 +166,18 @@ class VirtualMachine
|
||||
|
||||
# @return String the vm_id stored in vCenter
|
||||
def get_vm_id
|
||||
vm_id = self['config.extraConfig'].select do |o|
|
||||
o.key == "opennebula.vm.id"
|
||||
end.first.value rescue nil
|
||||
vm_ref = self['_ref']
|
||||
return nil if !vm_ref
|
||||
|
||||
vc_uuid = get_vcenter_instance_uuid
|
||||
|
||||
one_vm = VCenterDriver::VIHelper.find_by_ref(OpenNebula::VirtualMachinePool,
|
||||
"DEPLOY_ID",
|
||||
vm_ref,
|
||||
vc_uuid)
|
||||
return nil if !one_vm
|
||||
|
||||
return one_vm["ID"]
|
||||
end
|
||||
|
||||
def get_vcenter_instance_uuid
|
||||
@ -563,9 +572,6 @@ class VirtualMachine
|
||||
# Now reconfigure disks, nics and extraconfig for the VM
|
||||
device_change = []
|
||||
|
||||
# get vmid
|
||||
extraconfig += extraconfig_vmid
|
||||
|
||||
# get token and context
|
||||
extraconfig += extraconfig_context
|
||||
|
||||
@ -604,12 +610,6 @@ class VirtualMachine
|
||||
remove_poweroff_detached_vcenter_nets(networks) if !networks.empty?
|
||||
end
|
||||
|
||||
def extraconfig_vmid
|
||||
[
|
||||
{ :key => "opennebula.vm.id", :value => one_item['ID'] }
|
||||
]
|
||||
end
|
||||
|
||||
def extraconfig_context
|
||||
# TODO: migrator to 5.4 (create token.sh)
|
||||
context_text = "# Context variables generated by OpenNebula\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user