forked from miguno/wirbelsturm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wirbelsturm.rb
executable file
·31 lines (27 loc) · 968 Bytes
/
wirbelsturm.rb
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
require 'ipaddr'
require 'json'
require 'yaml'
module Wirbelsturm
# TODO: Properly implement this method (e.g. 1.1.1.254 will succ() to 1.1.1.1, which is not what we want)
def gen_ip(ip_start_range, i)
start_ip = IPAddr.new ip_start_range
# We chain-call IPAddr.succ() because IPAddr lacks a '+' operator.
i.times.inject(start_ip) { |curr_ip| curr_ip.send('succ')}.to_s
end
def compile_node_catalog(config_file='wirbelsturm.yaml')
config = YAML.load_file(config_file)
c = config['nodes']
nodes = {}
c.each do |node, opts|
num_servers = opts['count']
for i in 1..num_servers
hostname = '%s%s' % [ opts['hostname_prefix'], i.to_s]
nodes[hostname] = { 'ip' => gen_ip(opts['ip_range_start'], i), 'node_role' => opts['node_role'] }
opts['providers'].each do |provider, provider_opts|
nodes[hostname][provider] = provider_opts
end
end
end
JSON.dump(nodes)
end
end