Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

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

[dev] new api generators: added pdus

parent 6beb2838
......@@ -59,23 +59,23 @@ class ::Hash
self.merge(other_hash, &merger)
end
# Merge keys that match "PREFIX-[a-b]" with others keys that begins by "PREFIX-"
# Merge keys that match "PREFIX[a-b]" with others keys that begins by "PREFIX"
# and that ends with x, where a<=x<=b.
# - This is done recursively (for this Hash and every Hashes it may contain).
# - PREFIX-[a-b] values have lower priority on existing PREFIX-x keys.
# - "a" and/or "b" may be omited (ie. "PREFIX-[a-]", "PREFIX-[-b]" or "PREFIX-[-]"), meaning that there are no lower and/or upper bound for x.
# - PREFIX[a-b] values have lower priority on existing PREFIXx keys.
# - "a" and/or "b" may be omited (ie. "PREFIX[a-]", "PREFIX[-b]" or "PREFIX[-]"), meaning that there are no lower and/or upper bound for x.
# * If only a is omited, a == 1.
# * If b is omited, only existing keys are modified (no keys are created). Otherwise, PREFIX-[a] to PREFIX-[b] entries are created (if missing).
# * If b is omited, only existing keys are modified (no keys are created). Otherwise, PREFIX[a] to PREFIX[b] entries are created (if missing).
# Example:
# {"foo-1": {a: 0}, "foo-2": {a: 0}, "foo-3": {a: 0}, "foo-[2-]": {b: 1}}.expand_square_brackets()
# -> {"foo-1": {a: 0}, "foo-2": {a: 0, b:1}, "foo-3": {a: 0, b: 0}}
def expand_square_brackets(keys=self.clone)
# Looking up for PREFIX-[a-b] keys
# Looking up for PREFIX[a-b] keys
# (using .clone because cannot add/remove a key from hash during iteration)
keys.clone.each { |key_ab, value_ab|
prefix, a, b = key_ab.to_s.scan(/^(.*)-\[(\d*)-(\d*)\]$/).first
prefix, a, b = key_ab.to_s.scan(/^(.*)\[(\d*)-(\d*)\]$/).first
next if not a and not b # not found
a != "" ? a = a.to_i : a = 1
b != "" ? b = b.to_i : b
......@@ -84,28 +84,28 @@ class ::Hash
# Merge keys, creating missing entries if needed.
(a..b).each { |x|
key = "#{prefix}-#{x}"
key = "#{prefix}#{x}"
key = key.to_sym if key_ab.is_a?(Symbol)
# For duplicate entries, the value of PREFIX-x is kept.
# For duplicate entries, the value of PREFIXx is kept.
self[key] = deep_merge_entries(deep_copy(value_ab), self[key]).clone
}
else
# Modify only existing keys. Looking up for PREFIX-x keys.
# Modify only existing keys. Looking up for PREFIXx keys.
self.clone.each { |key_x, value_x|
next if key_x.class != key_ab.class
x = key_x.to_s.scan(/^#{prefix}-(\d*)$/).first
x = key_x.to_s.scan(/^#{prefix}(\d*)$/).first
x = x.first if x
next if not x or x.to_i < a
# For duplicate entries, the value of PREFIX-x is kept.
# For duplicate entries, the value of PREFIXx is kept.
self[key_x] = deep_merge_entries(deep_copy(value_ab), value_x).clone
}
end
# Delete entry "PREFIX-[a-b]"
# Delete entry "PREFIX[a-b]"
self.delete(key_ab)
keys.delete(key_ab)
}
......
......@@ -58,7 +58,20 @@ global_hash["sites"].each do |site_uid, site|
site_path.mkpath()
write_json(site_path.join("#{site_uid}.json"),
site.reject {|k, v| k == "clusters" || k == "networks" || k == "dom0"})
site.reject {|k, v| k == "clusters" || k == "networks" || k == "dom0" || k == "pdu"})
#
# Write pdu info
#
pdu_path = site_path.join("pdus")
pdu_path.mkpath()
site["pdu"].each do |pdu_uid, pdu|
pdu["type"] = "pdu"
pdu["uid"] = pdu_uid
write_json(pdu_path.join("#{pdu_uid}.json"), pdu)
end if site.key?("pdu")
#
# Write network info
......@@ -155,7 +168,7 @@ global_hash["sites"].each do |site_uid, site|
node["network_adapters"].each { |key, hash| node["network_adapters"][key]["device"] = key; } # Add "device: ethX" within the hash
node["network_adapters"] = node["network_adapters"].sort_by_array(["eth0", "eth1", "eth2", "eth3", "eth4", "eth5", "eth6", "ib0", "ib1", "ib2", "ib3", "bmc"]).values
# Populate "network_address", "switch" and "switch_port" from the network equipment description for each network adapters
# For each network adapters, populate "network_address", "switch" and "switch_port" from the network equipment description
node["network_adapters"].each { |network_adapter|
network_adapter["mac"] = network_adapter["mac"].downcase if network_adapter["mac"].is_a?(String)
......@@ -210,7 +223,9 @@ global_hash["sites"].each do |site_uid, site|
end # node.key?("pdu")
if node["monitoring"].key?("metric")
node["sensors"]["power"] ||= {}
node["sensors"]["power"]["available"] = true
node["sensors"]["power"]["via"] ||= {}
node["sensors"]["power"]["via"]["api"] ||= {}
node["sensors"]["power"]["via"]["api"]["metric"] = node["monitoring"].delete("metric")
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