Commit cf1af4a9 authored by Jérémie Gaidamour's avatar Jérémie Gaidamour
Browse files

[dev] Custom iterators

parent 2a39dee9
......@@ -36,7 +36,7 @@ global_hash["sites"].each { |site_uid, site_hash|
site_hash.fetch("clusters").sort.each { |cluster_uid, cluster_hash|
cluster_hash.fetch('nodes').sort_by { |item| item.to_s.split(/(\d+)/).map { |e| [e.to_i, e] } }.each { |node_uid, node_hash|
cluster_hash.fetch('nodes').each_sort_by_node_uid { |node_uid, node_hash|
network_interfaces = {}
node_hash.fetch('network_interfaces').each { |net_uid, net_hash|
......
......@@ -9,7 +9,7 @@
%>
group {
<%
data.fetch('nodes').sort_by { |item| item.to_s.split(/(\d+)/).map { |e| [e.to_i, e] } }.each { |node_uid, node_hash|
data.fetch('nodes').each_sort_by_node_uid { |node_uid, node_hash|
network_interface != 'bmc' ? node_uid_net = node_uid : node_uid_net = node_uid + '-bmc'
# Get ip and mac addresses
......
......@@ -90,4 +90,23 @@ class ::Hash
return array.reverse.inject(value) { |a, n| { n => a } }
end
# Custom iterator. Same as "each" but it sorts keys by node_uid (ie. graphene-10 after graphene-9)
def each_sort_by_node_uid
self.sort_by { |item| item.to_s.split(/(\d+)/).map { |e| [e.to_i, e] } }.each { |key, value|
yield key, value
}
end
# Custom iterator. Only consider entries corresponding to cluster_list and node_list. Sorted by node_uid.
def each_filtered_node_uid(cluster_list, node_list)
self.each_sort_by_node_uid { |node_uid, properties|
cluster_uid = node_uid.split(/-/).first
if (! cluster_list || cluster_list.include?(cluster_uid)) &&
(! node_list || node_list.include?(node_uid))
yield node_uid, properties
end
}
end
end
......@@ -126,27 +126,21 @@ nodelist_properties["to_be_updated"] = {}
nodelist_properties["ref"].each { |site_uid, site_properties|
site_properties.sort_by { |item| item.to_s.split(/(\d+)/).map { |e| [e.to_i, e] } }.each { |node_uid, node_properties_ref|
cluster_uid = node_uid.split(/-/).first
if (! options[:clusters] || options[:clusters].include?(cluster_uid)) &&
(! options[:nodes] || options[:nodes].include?(node_uid))
node_properties_oar = nodelist_properties["oar"][site_uid][node_uid]
site_properties.each_filtered_node_uid(options[:clusters], options[:nodes]) { |node_uid, node_properties_ref|
diff = diff_node_properties(node_properties_ref, node_properties_oar)
diff_keys = diff.map{ |hashdiff_array| hashdiff_array[1] }
nodelist_properties["to_be_updated"][node_uid] = node_properties_ref.select { |key, value| diff_keys.include?(key) }
node_properties_oar = nodelist_properties["oar"][site_uid][node_uid]
if (options[:verbose])
#puts "#{node_uid}: #{diff}"
puts "#{node_uid}: #{diff_keys}"
end
diff = diff_node_properties(node_properties_ref, node_properties_oar)
diff_keys = diff.map{ |hashdiff_array| hashdiff_array[1] }
nodelist_properties["to_be_updated"][node_uid] = node_properties_ref.select { |key, value| diff_keys.include?(key) }
if (options[:verbose])
#puts "#{node_uid}: #{diff}"
puts "#{node_uid}: #{diff_keys}"
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