Commit 25e39bfa authored by Iustin Pop's avatar Iustin Pop
Browse files

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: default avatarIustin Pop <>
Reviewed-by: default avatarMichael Hanselmann <>
parent d27776f0
......@@ -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
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)
......@@ -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.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment