forked from cloudfoundry-attic/cf-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarden_networks.rb
executable file
·57 lines (49 loc) · 1.5 KB
/
warden_networks.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env ruby
# Each Warden container is a /30 in Warden's network range, which is
# configured as 10.244.0.0/22. There are 256 available entries.
#
# We want two subnets, so I've arbitrarily divided this in half for each.
#
# cf1 will be 10.244.0.0/23
# cf2 will be 10.244.2.0/23
#
# Each network will have 128 subnets, and the first half of each subnet will
# be given static IPs.
require "yaml"
require "netaddr"
IP_ADDRESS_SUFFIX = ENV.fetch("IP_ADDRESS_SUFFIX", 4).to_i
cf1_subnets = []
cf1_start = NetAddr::CIDR.create("10.24#{IP_ADDRESS_SUFFIX}.0.0/30")
cf2_subnets = []
cf2_start = NetAddr::CIDR.create("10.24#{IP_ADDRESS_SUFFIX}.2.0/30")
128.times do
cf1_subnets << cf1_start
cf1_start = NetAddr::CIDR.create(cf1_start.next_subnet)
cf2_subnets << cf2_start
cf2_start = NetAddr::CIDR.create(cf2_start.next_subnet)
end
puts YAML.dump(
"networks" => [
{ "name" => "cf1",
"subnets" => cf1_subnets.collect.with_index do |subnet, idx|
{ "cloud_properties" => {
"name" => "random",
},
"range" => subnet.to_s,
"reserved" => [subnet[1].ip],
"static" => idx < 64 ? [subnet[2].ip] : [],
}
end
},
{ "name" => "cf2",
"subnets" => cf2_subnets.collect.with_index do |subnet, idx|
{ "cloud_properties" => {
"name" => "random",
},
"range" => subnet.to_s,
"reserved" => [subnet[1].ip],
"static" => idx < 64 ? [subnet[2].ip] : [],
}
end
},
])