Add /label-list to the webapp

This change adds /label-list and /label-list.json that returns available
labels over http.

Change-Id: Iafff02d546abb34affa88310f6a97918166cbf47
This commit is contained in:
Tristan Cacqueray 2017-09-02 06:11:15 +00:00
parent 1025645ffe
commit b737889250
2 changed files with 21 additions and 0 deletions

View File

@ -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"])

View File

@ -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)