Check both ip and hosts when building dhcp bag

This commit is contained in:
Ian Southam 2015-02-18 18:36:59 +01:00 committed by wilderrodrigues
parent c1ec5b0b16
commit 748e2e51a9
1 changed files with 16 additions and 0 deletions

View File

@ -21,6 +21,7 @@ from netaddr import *
def merge(dbag, data):
search(dbag, data['host_name'])
# A duplicate ip address wil clobber the old value
# This seems desirable ....
if "add" in data and data['add'] is False and \
@ -31,3 +32,18 @@ def merge(dbag, data):
else:
dbag[data['ipv4_adress']] = data
return dbag
def search(dbag, name):
"""
Dirty hack because CS does not deprovision hosts
"""
hosts = []
for o in dbag:
if o == 'id':
continue
print "%s %s" % (dbag[o]['host_name'], name)
if dbag[o]['host_name'] == name:
hosts.append(o)
for o in hosts:
del(dbag[o])