diff --git a/lib/rapi/baserlib.py b/lib/rapi/baserlib.py index 0138e64fde7067fa12fd93555766ad9ab2719e03..1914885946ebf1bd276f055192df5b041ab0c603 100644 --- a/lib/rapi/baserlib.py +++ b/lib/rapi/baserlib.py @@ -29,6 +29,8 @@ import ganeti.opcodes from ganeti import luxi from ganeti import rapi from ganeti import http +from ganeti import ssconf +from ganeti import constants def BuildUriList(ids, uri_format, uri_fields=("name", "uri")): @@ -81,8 +83,22 @@ def _Tags_GET(kind, name=""): """Helper function to retrieve tags. """ - op = ganeti.opcodes.OpGetTags(kind=kind, name=name) - tags = ganeti.cli.SubmitOpCode(op) + if kind == constants.TAG_INSTANCE or kind == constants.TAG_NODE: + if not name: + raise HttpBadRequest("Missing name on tag request") + cl = luxi.Client() + if kind == constants.TAG_INSTANCE: + fn = cl.QueryInstances + else: + fn = cl.QueryNodes + result = fn(names=[name], fields=["tags"], use_locking=False) + if not result or not result[0]: + raise http.HttpBadGateway("Invalid response from tag query") + tags = result[0][0] + elif kind == constants.TAG_CLUSTER: + ssc = ssconf.SimpleStore() + tags = ssc.GetClusterTags() + return list(tags) diff --git a/lib/ssconf.py b/lib/ssconf.py index cce1141f073d4e807d49a24a6cbb5ab275b86dad..19a95c97a90d0165a14eb102ee756e58f17ce44a 100644 --- a/lib/ssconf.py +++ b/lib/ssconf.py @@ -250,6 +250,14 @@ class SimpleStore(object): nl = data.splitlines(False) return nl + def GetClusterTags(self): + """Return the cluster tags. + + """ + data = self._ReadFile(constants.SS_CLUSTER_TAGS) + nl = data.splitlines(False) + return nl + def GetMasterAndMyself(ss=None): """Get the master node and my own hostname.