Skip to content
Snippets Groups Projects
Commit fc72a3a3 authored by Oleksiy Mishchenko's avatar Oleksiy Mishchenko
Browse files

RAPI: Implement /2 resource

Reviewed-by: iustinp
parent dc824c9f
No related branches found
No related tags found
No related merge requests found
......@@ -114,12 +114,47 @@ class R_root(baserlib.R_Generic):
return baserlib.BuildUriList(rootlist, "/%s")
def _getResources(id):
"""Return a list of resources underneath given id.
This is to generalize querying of version resources lists.
@return: a list of resources names.
"""
r_pattern = re.compile('^R_%s_([a-zA-Z0-9]+)$' % id)
rlist = []
for handler in CONNECTOR.values():
m = r_pattern.match(handler.__name__)
if m:
name = m.group(1)
rlist.append(name)
return rlist
class R_2(baserlib.R_Generic):
""" /2 resourse.
"""
DOC_URI = "/2"
def GET(self):
"""Show the list of mapped resources.
@return: a dictionary with 'name' and 'uri' keys for each of them.
"""
return baserlib.BuildUriList(_getResources("2"), "/2/%s")
CONNECTOR.update({
"/": R_root,
"/version": rlib1.R_version,
"/2": R_2,
"/2/jobs": rlib2.R_2_jobs,
"/2/nodes": rlib2.R_2_nodes,
"/2/instances": rlib2.R_2_instances,
......
......@@ -76,7 +76,7 @@ class R_RootTests(unittest.TestCase):
def testGet(self):
expected = [
# TODO: {'name': 'info', 'uri': '/2'},
{'name': '2', 'uri': '/2'},
{'name': 'version', 'uri': '/version'},
]
self.assertEquals(self.root.GET(), expected)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment