-
Notifications
You must be signed in to change notification settings - Fork 7
/
crowbar-IPs
executable file
·44 lines (37 loc) · 990 Bytes
/
crowbar-IPs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/ruby
#
# Print an IP -> alias mapping from a Crowbar admin node supportconfig
require 'yaml'
require 'json'
require 'pathname'
def read_IPs(mac_to_alias, jsons)
addr_to_alias = {}
jsons.each do |json|
j = JSON.load(json)
network_name = j["id"].sub(/_network$/, "")
j["allocated"].each do |ip, data|
fqdn = data["machine"]
hostname = fqdn.sub /\..*/, ''
host_alias = mac_to_alias[hostname]
if host_alias
address = data["address"]
addr_to_alias[address] = "IP-%s-%s" % [network_name, host_alias]
end
end
end
addr_to_alias
end
def show_IPs(addr_to_alias)
puts YAML.dump(addr_to_alias)
end
def main
if ARGV.size != 1
abort "Usage: #$0 MACS-YAML"
end
macs_file = ARGV.shift
mac_to_alias = YAML.load_file(macs_file)
jsons = Pathname.glob("./rootfs/var/log/crowbar/chef-export/databag/crowbar/*_network.json")
addr_to_alias = read_IPs(mac_to_alias, jsons)
show_IPs(addr_to_alias)
end
main