From 25e39bfaec1ce1292f77c4d9b08a49cd1ae904fd Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 25 May 2009 10:59:37 +0200 Subject: [PATCH] rapi: make tags query not use jobs Currently the rapi tags query implementation is similar to the command line one: it submits OpGetTags jobs. This not good, since this being an API it can be used a lot and can pollute the job queue with many such trivial jobs. This patch converts it to use either queries (for nodes/instances) or direct read from ssconf (for the cluster case). For ssconf, we added a function to the ssconf.SimpleStore class for reading the tags. Signed-off-by: Iustin Pop Reviewed-by: Michael Hanselmann --- lib/rapi/baserlib.py | 20 ++++++++++++++++++-- lib/ssconf.py | 8 ++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/rapi/baserlib.py b/lib/rapi/baserlib.py index 0138e64..1914885 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 cce1141..19a95c9 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. -- 1.7.10.4