From b7378892502836f257456cd277190ee75a7ca75f Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Sat, 2 Sep 2017 06:11:15 +0000 Subject: [PATCH] Add /label-list to the webapp This change adds /label-list and /label-list.json that returns available labels over http. Change-Id: Iafff02d546abb34affa88310f6a97918166cbf47 --- nodepool/status.py | 17 +++++++++++++++++ nodepool/webapp.py | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/nodepool/status.py b/nodepool/status.py index 033ab9fd8..71f3f6318 100755 --- a/nodepool/status.py +++ b/nodepool/status.py @@ -106,6 +106,23 @@ def node_list_json(zk): return json.dumps([node.toDict() for node in zk.nodeIterator()]) +def label_list(zk): + labels = set() + for node in zk.nodeIterator(): + labels.add(node.type) + t = PrettyTable(["Label"]) + for label in sorted(labels.keys()): + t.add_row((label,)) + return str(t) + + +def label_list_json(zk): + labels = set() + for node in zk.nodeIterator(): + labels.add(node.type) + return json.dumps(labels) + + def dib_image_list(zk): t = PrettyTable(["ID", "Image", "Builder", "Formats", "State", "Age"]) diff --git a/nodepool/webapp.py b/nodepool/webapp.py index 385b9871b..f6c7ef795 100644 --- a/nodepool/webapp.py +++ b/nodepool/webapp.py @@ -87,6 +87,10 @@ class WebApp(threading.Thread): output = status.node_list(self.nodepool.getZK()) elif path == '/node-list.json': output = status.node_list_json(self.nodepool.getZK()) + elif path == '/label-list': + output = status.label_list(self.nodepool.getZK()) + elif path == '/label-list.json': + output = status.label_list_json(self.nodepool.getZK()) else: return None return self.cache.put(path, output)