From 0f945c65b2c4a86f633e7cfc548d30567ca57b69 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 7 Sep 2011 13:07:10 +0200
Subject: [PATCH] =?UTF-8?q?rapi:=20Remove=20=E2=80=9C/2=E2=80=9D=20resourc?=
 =?UTF-8?q?e,=20deprecate=20=E2=80=9C/=E2=80=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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: Michael Hanselmann <hansmi@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 doc/rapi.rst                           | 26 +----------
 lib/rapi/connector.py                  | 65 +-------------------------
 lib/rapi/rlib2.py                      | 12 +++++
 test/docs_unittest.py                  |  2 +-
 test/ganeti.rapi.client_unittest.py    |  3 +-
 test/ganeti.rapi.resources_unittest.py | 14 ------
 6 files changed, 17 insertions(+), 105 deletions(-)

diff --git a/doc/rapi.rst b/doc/rapi.rst
index 7ed29a803..a9f413ca1 100644
--- a/doc/rapi.rst
+++ b/doc/rapi.rst
@@ -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``
 +++++++++++
diff --git a/lib/rapi/connector.py b/lib/rapi/connector.py
index 34c13fd1b..26a71af85 100644
--- a/lib/rapi/connector.py
+++ b/lib/rapi/connector.py
@@ -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,
diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py
index fb32e8090..b6d9abd8a 100644
--- a/lib/rapi/rlib2.py
+++ b/lib/rapi/rlib2.py
@@ -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.
 
diff --git a/test/docs_unittest.py b/test/docs_unittest.py
index 82e5a9d06..e75092dd8 100755
--- a/test/docs_unittest.py
+++ b/test/docs_unittest.py
@@ -142,7 +142,7 @@ class TestDocs(unittest.TestCase):
 
       prevline = line
 
-    prefix_exception = frozenset(["/", "/version", "/2"])
+    prefix_exception = frozenset(["/", "/version"])
 
     undocumented = []
     used_uris = []
diff --git a/test/ganeti.rapi.client_unittest.py b/test/ganeti.rapi.client_unittest.py
index d7af45ad3..7273f14da 100755
--- a/test/ganeti.rapi.client_unittest.py
+++ b/test/ganeti.rapi.client_unittest.py
@@ -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
diff --git a/test/ganeti.rapi.resources_unittest.py b/test/ganeti.rapi.resources_unittest.py
index 70f68b5b1..5d5311883 100755
--- a/test/ganeti.rapi.resources_unittest.py
+++ b/test/ganeti.rapi.resources_unittest.py
@@ -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()
-- 
GitLab