mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-22 12:52:40 +09:00
Feature #4342: Add VM_PREFIX in Host template
This commit is contained in:
1 parent
6d258db982
commit
44bbad982c
1 file changed
+25
-3
@@ -975,9 +975,18 @@ class VCenterHost < ::OpenNebula::Host
|
||||
name = v.name
|
||||
number = -1
|
||||
|
||||
# Extract vmid if possible
|
||||
|
||||
matches = name.match(/^one-(\d*)(-(.*))?$/)
|
||||
number = matches[1] if matches
|
||||
|
||||
extraconfig_vmid = vm.config.extraConfig.select{|v|
|
||||
v[:key]=="opennebula.vm.id"}
|
||||
|
||||
if extraconfig_vmid.size > 0 and extraconfig_vmid[0]
|
||||
number = extraconfig_vmid[0][:value]
|
||||
end
|
||||
|
||||
vm = VCenterVm.new(@client, v)
|
||||
vm.monitor
|
||||
|
||||
@@ -1655,6 +1664,17 @@ private
|
||||
########################################################################
|
||||
def self.clone_vm(xml_text, hostname, datastore)
|
||||
|
||||
host_id = VCenterDriver::VIClient.translate_hostname(hostname)
|
||||
# Retrieve hostname
|
||||
host = OpenNebula::Host.new_with_id(host_id, OpenNebula::Client.new())
|
||||
host.info # Not failing if host retrieval fails
|
||||
|
||||
if host["/HOST/TEMPLATE/VM_PREFIX"] and !host["/HOST/TEMPLATE/VM_PREFIX"].empty?
|
||||
vmname_prefix = host["/HOST/TEMPLATE/VM_PREFIX"]
|
||||
else # fall back to default value
|
||||
vmname_prefix = "one-$i-"
|
||||
end
|
||||
|
||||
xml = REXML::Document.new xml_text
|
||||
pcs = xml.root.get_elements("//USER_TEMPLATE/PUBLIC_CLOUD")
|
||||
|
||||
@@ -1692,7 +1712,8 @@ private
|
||||
|
||||
uuid = uuid.text
|
||||
vmid = xml.root.elements["/VM/ID"].text
|
||||
vcenter_name = "one-#{vmid}-#{xml.root.elements["/VM/NAME"].text}"
|
||||
vmname_prefix.gsub!("$i", vmid)
|
||||
vcenter_name = "#{vmname_prefix}#{xml.root.elements["/VM/NAME"].text}"
|
||||
hid = xml.root.elements["//HISTORY_RECORDS/HISTORY/HID"]
|
||||
|
||||
raise "Cannot find host id in deployment file history." if hid.nil?
|
||||
@@ -1775,6 +1796,9 @@ private
|
||||
|
||||
vm_uuid = vm.config.uuid
|
||||
|
||||
# Add VMID to VM's extraConfig
|
||||
config_array = [{:key=>"opennebula.vm.id",:value=>vmid}]
|
||||
|
||||
# VNC Section
|
||||
|
||||
vnc_port = xml.root.elements["/VM/TEMPLATE/GRAPHICS/PORT"]
|
||||
@@ -1787,7 +1811,6 @@ private
|
||||
vnc_listen = vnc_listen.text
|
||||
end
|
||||
|
||||
config_array = []
|
||||
context_vnc_spec = {}
|
||||
|
||||
if vnc_port
|
||||
@@ -1803,7 +1826,6 @@ private
|
||||
# Context section
|
||||
|
||||
if context
|
||||
# Remove <CONTEXT> (9) and </CONTEXT>\n (11)
|
||||
context_text = "# Context variables generated by OpenNebula\n"
|
||||
context.elements.each{|context_element|
|
||||
context_text += context_element.name + "='" +
|
||||
|
||||
Reference in new issue
Block a user