Ian Southam c7c1f3202e Plan B
Replace chef with a python script
configure.py will read the bags and (hopefully) create the desired state
At this stage this is ipassociation
This code should work for both VR and VPCrs

TODO:
iptables
ip route throw (present in VR but not in VPCr
Determine default route
Unit tests
2015-03-16 11:35:08 +01:00

19 lines
629 B
Python

from pprint import pprint
from netaddr import *
def merge(dbag, ip):
added = False
for dev in dbag:
if dev == "id":
continue
for address in dbag[dev]:
if address['public_ip'] == ip['public_ip']:
dbag[dev].remove(address)
if ip['add']:
ipo = IPNetwork(ip['public_ip'] + '/' + ip['netmask'])
ip['device'] = 'eth' + str(ip['nic_dev_id'])
ip['cidr'] = str(ipo.ip) + '/' + str(ipo.prefixlen)
ip['network'] = str(ipo.network) + '/' + str(ipo.prefixlen)
dbag.setdefault('eth' + str(ip['nic_dev_id']), []).append( ip )
return dbag