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

F #1176: global params for all VMs in a service (#2123)

This commit is contained in:
Alejandro Huertas Herrero 2022-06-02 18:10:53 +02:00 committed by GitHub
parent 11cedda103
commit 338765e4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -455,6 +455,9 @@ module OpenNebula
extra_template << "\nSERVICE_ID = #{@service.id}"
extra_template << "\nROLE_NAME = \"#{@body['name']}\""
# Evaluate attributes with parent roles
evaluate(extra_template)
n_nodes.times do
vm_name = @@vm_name_template
.gsub('$SERVICE_ID', @service.id.to_s)
@ -1168,6 +1171,49 @@ module OpenNebula
new_cardinality
end
# Evaluate rules that references to parent roles
#
# @param template [String] Role template with $ to replace
def evaluate(template)
client = service.client
template.scan(/\$\{(.*?)\}/).flatten.each do |value|
s_value = value.split('.') # 0 -> parent, 1..N -> XPATH
# If parent not found, instead of error, replace it by blank
unless parents.include?(s_value[0])
template.gsub!("${#{value}}", '')
next
end
found = false
p_nodes = service.roles[s_value[0]].nodes
xpath = "//#{s_value[1..-1].join('/').upcase}"
# Iterate over parent nodes to find the XPATH on their template
p_nodes.each do |node|
id = node['deploy_id']
vm = OpenNebula::VirtualMachine.new_with_id(id, client)
# If error continue searching in other nodes
next if OpenNebula.is_error?(vm.info)
next unless vm[xpath]
template.gsub!("${#{value}}", vm[xpath])
# If found, continue with next expression
found = true
break
end
next if found
# If value not found, replace it by blank to avoid issues
template.gsub!("${#{value}}", '')
end
end
end
end