From 8625e9bd3eef93ac36f2e380e58dea2d949ecb6c Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 31 May 2021 00:13:13 -0400 Subject: [PATCH] Update Delete to recursive method --- daemon-common/zkhandler.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/daemon-common/zkhandler.py b/daemon-common/zkhandler.py index 43d15035..6a557c98 100644 --- a/daemon-common/zkhandler.py +++ b/daemon-common/zkhandler.py @@ -211,13 +211,23 @@ class ZKHandler(object): self.log("ZKHandler error: Failed to commit transaction: {}".format(e), state='e') return False - def delete(self, key, recursive=True): + def delete(self, keys, recursive=True): """ - Delete a key (defaults to recursive) + Delete a key or list of keys (defaults to recursive) """ - if self.zk_conn.delete(key, recursive=recursive): + if type(keys) is not list: + keys = [keys] + + transaction = self.zk_conn.transaction() + + for key in keys: + transaction.delete(key, recursive=recursive) + + try: + transaction.commit() return True - else: + except Exception as e: + self.log("ZKHandler error: Failed to commit transaction: {}".format(e), state='e') return False def children(self, key):