Don't delete if lease is static

This commit is contained in:
Joshua Boniface 2018-09-30 11:11:33 -04:00
parent a673e38cff
commit 436dc42576
1 changed files with 7 additions and 3 deletions

View File

@ -638,9 +638,13 @@ class ZKDatabase(object):
def delete(self, pattern): def delete(self, pattern):
macaddr = pattern[0] macaddr = pattern[0]
try: try:
zkhandler.delete(self.zk_conn, '{}/{}'.format(self.key, macaddr)) timestamp = zkhandler.readdata(self.zk_conn, '{}/{}'.format(self.key, macaddr))
if timestamp != 'static':
zkhandler.delete(self.zk_conn, '{}/{}'.format(self.key, macaddr))
return True
except Exception: except Exception:
pass pass
return False
def all(self): def all(self):
leases = [] leases = []
@ -716,8 +720,8 @@ class HostDatabase(object):
return list(map(Host.from_tuple, self.db.all())) return list(map(Host.from_tuple, self.db.all()))
def replace(self, host): def replace(self, host):
self.delete(host) if self.delete(host):
self.add(host) self.add(host)
def sorted_hosts(hosts): def sorted_hosts(hosts):
hosts = list(hosts) hosts = list(hosts)