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:
parent
1025645ffe
commit
b737889250
|
@ -106,6 +106,23 @@ def node_list_json(zk):
|
||||||
return json.dumps([node.toDict() for node in zk.nodeIterator()])
|
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):
|
def dib_image_list(zk):
|
||||||
t = PrettyTable(["ID", "Image", "Builder", "Formats",
|
t = PrettyTable(["ID", "Image", "Builder", "Formats",
|
||||||
"State", "Age"])
|
"State", "Age"])
|
||||||
|
|
|
@ -87,6 +87,10 @@ class WebApp(threading.Thread):
|
||||||
output = status.node_list(self.nodepool.getZK())
|
output = status.node_list(self.nodepool.getZK())
|
||||||
elif path == '/node-list.json':
|
elif path == '/node-list.json':
|
||||||
output = status.node_list_json(self.nodepool.getZK())
|
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:
|
else:
|
||||||
return None
|
return None
|
||||||
return self.cache.put(path, output)
|
return self.cache.put(path, output)
|
||||||
|
|
Loading…
Reference in New Issue