Commit 1a22ea83 authored by Christian Jung's avatar Christian Jung

handle empty list properly

parent 9fdb9a48
Pipeline #57262565 passed with stage
in 3 seconds
begin
lans = {}
# get currently selected tags
current_tag = $evm.root["dialog_tag_control_1"]
$evm.log("info", "Current Tag is: #{current_tag}")
tag_name = current_tag[0].name
$evm.vmdb(:ems_cluster).all.each do |cluster|
tags = cluster.tags
$evm.log("info", "Current cluster #{cluster.name} tags: #{tags}")
$evm.log("info", "Checking if current tag matches department/#{tag_name}")
cluster.tags.each do |tag|
if tag == "department/#{tag_name}" then
$evm.log("info", "Tag matches")
cluster.hosts.each do |host|
lans['!'] = '-- select from list --'
host.lans.each do |lan|
lans[lan.id] = "#{lan.name} (tag: #{lan.tag})"
end
end
else
$evm.log("info", "Tag does not match")
end
end
end
if lan = {} then
lans['!'] = '-- select tag first --'
end
list_values = {
'sort_by' => :value,
'data_type' => :string,
'required' => true,
'values' => lans
}
list_values.each { |key, value| $evm.object[key] = value }
rescue => err
$evm.log(:error, "[#{err}]\n#{err.backtrace.join("\n")}")
exit MIQ_STOP
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment