Page MenuHomePhabricator
Paste P2065

subnetter.py
ActivePublic

Authored by amckinley on Jul 14 2017, 7:58 PM.
Tags
None
Referenced Files
F5046578: subnetter.py
Jul 14 2017, 7:58 PM
Subscribers
None
from ipaddr import IPv4Network, collapse_address_list
def compute_layout():
net = IPv4Network("10.0.0.0/16")
all_26s = list(net.iter_subnets(new_prefix=26))
admin_space = all_26s[:8]
fmt_string = "{}: {} => {} ({})"
# two 256-host networks
admin1 = collapse_address_list(admin_space[:4])[0]
admin2 = collapse_address_list(admin_space[4:])[0]
print fmt_string.format(
'us-east-1a.admin-1', admin1.network, admin1.broadcast, admin1)
print fmt_string.format(
'us-east-1b.admin-2', admin2.network, admin2.broadcast, admin2)
print
customer_space = all_26s[8:]
customer_1_space = list(customer_space.pop(0).iter_subnets(new_prefix=29))
# two 8-host networks for public
public1 = customer_1_space.pop(0)
public2 = customer_1_space.pop(0)
# two 16-host networks for private
private1 = collapse_address_list([
customer_1_space.pop(0),
customer_1_space.pop(0)])[0]
private2 = collapse_address_list([
customer_1_space.pop(0),
customer_1_space.pop(0)])[0]
# one more 16-host network for spares
spare = collapse_address_list([
customer_1_space.pop(0),
customer_1_space.pop(0)])[0]
# 64 hosts total per customer
all_customer_1 = collapse_address_list([
public1,
public2,
private1,
private2,
spare])[0]
print fmt_string.format(
"us-east-1.customer-foo",
all_customer_1.network, all_customer_1.broadcast, all_customer_1)
print
print fmt_string.format(
"us-east-1a.customer-foo.public-1",
public1.network, public1.broadcast, public1)
print fmt_string.format(
"us-east-1b.customer-foo.public-2",
public2.network, public2.broadcast, public2)
print fmt_string.format(
"us-east-1a.customer-foo.private-1",
private1.network, private1.broadcast, private1)
print fmt_string.format(
"us-east-1b.customer-foo.private-2",
private2.network, private2.broadcast, private2)
print fmt_string.format(
"us-east-1.customer-foo.spare",
spare.network, spare.broadcast, spare)
def main():
compute_layout()
if __name__ == '__main__':
main()