Commit 0f945c65 authored by Michael Hanselmann's avatar Michael Hanselmann

rapi: Remove “/2” resource, deprecate “/”

These were never really useful. Neither gave a complete list of
available resources—the documentation in doc/rapi.rst is much better at
that.

Since some monitoring code might use the “/” resource it's kept around
but will only return a JSON “null”.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 25993e57
......@@ -239,30 +239,8 @@ Resources
``/``
+++++
The root resource.
It supports the following commands: ``GET``.
``GET``
~~~~~~~
Shows the list of mapped resources.
Returns: a dictionary with 'name' and 'uri' keys for each of them.
``/2``
++++++
The ``/2`` resource, the root of the version 2 API.
It supports the following commands: ``GET``.
``GET``
~~~~~~~
Show the list of mapped resources.
Returns: a dictionary with ``name`` and ``uri`` keys for each of them.
The root resource. Has no function, but for legacy reasons the ``GET``
method is supported.
``/2/info``
+++++++++++
......
......@@ -33,7 +33,6 @@ from ganeti import constants
from ganeti import http
from ganeti import utils
from ganeti.rapi import baserlib
from ganeti.rapi import rlib2
......@@ -89,66 +88,6 @@ class Mapper:
return (handler, groups, args)
class R_root(baserlib.R_Generic):
"""/ resource.
"""
_ROOT_PATTERN = re.compile("^R_([a-zA-Z0-9]+)$")
@classmethod
def GET(cls):
"""Show the list of mapped resources.
@return: a dictionary with 'name' and 'uri' keys for each of them.
"""
rootlist = []
for handler in CONNECTOR.values():
m = cls._ROOT_PATTERN.match(handler.__name__)
if m:
name = m.group(1)
if name != "root":
rootlist.append(name)
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 resource.
This is the root of the version 2 API.
"""
@staticmethod
def GET():
"""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")
def GetHandlers(node_name_pattern, instance_name_pattern,
group_name_pattern, job_id_pattern, disk_pattern,
query_res_pattern):
......@@ -160,12 +99,10 @@ def GetHandlers(node_name_pattern, instance_name_pattern,
# is more flexible and future-compatible than versioning the whole remote
# API.
return {
"/": R_root,
"/": rlib2.R_root,
"/version": rlib2.R_version,
"/2": R_2,
"/2/nodes": rlib2.R_2_nodes,
re.compile(r"^/2/nodes/(%s)$" % node_name_pattern):
rlib2.R_2_nodes_name,
......
......@@ -148,6 +148,18 @@ ALL_FEATURES = frozenset([
_WFJC_TIMEOUT = 10
class R_root(baserlib.R_Generic):
"""/ resource.
"""
@staticmethod
def GET():
"""Supported for legacy reasons.
"""
return None
class R_version(baserlib.R_Generic):
"""/version resource.
......
......@@ -142,7 +142,7 @@ class TestDocs(unittest.TestCase):
prevline = line
prefix_exception = frozenset(["/", "/version", "/2"])
prefix_exception = frozenset(["/", "/version"])
undocumented = []
used_uris = []
......
......@@ -45,8 +45,7 @@ _URI_RE = re.compile(r"https://(?P<host>.*):(?P<port>\d+)(?P<path>/.*)")
# List of resource handlers which aren't used by the RAPI client
_KNOWN_UNUSED = set([
connector.R_root,
connector.R_2,
rlib2.R_root,
])
# Global variable for collecting used handlers
......
......@@ -69,19 +69,5 @@ class MapperTests(unittest.TestCase):
self._TestFailingUri("/instances/does/not/exist")
class R_RootTests(unittest.TestCase):
"""Testing for R_root class."""
def setUp(self):
self.root = connector.R_root(None, None, None)
def testGet(self):
expected = [
{'name': '2', 'uri': '/2'},
{'name': 'version', 'uri': '/version'},
]
self.assertEquals(self.root.GET(), expected)
if __name__ == '__main__':
testutils.GanetiTestProgram()
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