Work arounds for how CS adds and removes hosts

This commit is contained in:
Ian Southam 2015-02-18 18:55:54 +01:00 committed by wilderrodrigues
parent 748e2e51a9
commit 3cc0915a01
2 changed files with 8 additions and 8 deletions

View File

@ -128,8 +128,9 @@ class CsDhcp(CsDataBag):
def write_hosts(self): def write_hosts(self):
file = CsFile("/etc/hosts") file = CsFile("/etc/hosts")
file.repopulate()
for ip in self.hosts: for ip in self.hosts:
file.search("^%s" % ip, "%s\t%s" % (ip, self.hosts[ip])) file.add("%s\t%s" % (ip, self.hosts[ip]))
file.commit() file.commit()
if file.is_changed(): if file.is_changed():
logging.info("Updated hosts file") logging.info("Updated hosts file")
@ -138,13 +139,9 @@ class CsDhcp(CsDataBag):
def add(self, entry): def add(self, entry):
self.add_host(entry['ipv4_adress'], entry['host_name']) self.add_host(entry['ipv4_adress'], entry['host_name'])
if self.cloud.search("%s," % entry['mac_address'], self.cloud.add("%s,%s,%s,infinite" % (entry['mac_address'],
"%s,%s,%s,infinite" % (entry['mac_address'],
entry['ipv4_adress'], entry['ipv4_adress'],
entry['host_name'])): entry['host_name']))
self.changed.append({'mac': entry['mac_address'],
'ip4': entry['ipv4_adress'],
'host': entry['host_name']})
i = IPAddress(entry['ipv4_adress']) i = IPAddress(entry['ipv4_adress'])
# Calculate the device # Calculate the device
for v in self.devinfo: for v in self.devinfo:

View File

@ -53,6 +53,9 @@ class CsFile:
self.config = [] self.config = []
self.new_config = [] self.new_config = []
def repopulate(self):
self.new_config = []
def commit(self): def commit(self):
if not self.is_changed(): if not self.is_changed():
return return