Commit e8ebbd2b authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

RAPI: /2/{nodes,instances}/$name should return 404 for unknown items

Currently they return a 500 Server Error, not really useful
for detecting nonexistent items.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent d2fc26dd
......@@ -195,6 +195,20 @@ def SubmitJob(op, cl=None):
raise http.HttpGatewayTimeout("Timeout while talking to the master"
" daemon. Error: %s" % str(err))
def HandleItemQueryErrors(fn, *args, **kwargs):
"""Converts errors when querying a single item.
return fn(*args, **kwargs)
except errors.OpPrereqError, err:
if len(err.args) == 2 and err.args[1] == errors.ECODE_NOENT:
raise http.HttpNotFound()
def GetClient():
"""Geric wrapper for luxi.Client(), for better http compatiblity.
......@@ -312,7 +312,9 @@ class R_2_nodes_name(baserlib.R_Generic):
node_name = self.items[0]
client = baserlib.GetClient()
result = client.QueryNodes(names=[node_name], fields=N_FIELDS,
result = baserlib.HandleItemQueryErrors(client.QueryNodes,
names=[node_name], fields=N_FIELDS,
return baserlib.MapFields(N_FIELDS, result[0])
......@@ -699,7 +701,10 @@ class R_2_instances_name(baserlib.R_Generic):
client = baserlib.GetClient()
instance_name = self.items[0]
result = client.QueryInstances(names=[instance_name], fields=I_FIELDS,
result = baserlib.HandleItemQueryErrors(client.QueryInstances,
return baserlib.MapFields(I_FIELDS, result[0])
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