]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: restcontroller: support explicit resource ID
authorRicardo Dias <rdias@suse.com>
Thu, 19 Apr 2018 07:45:40 +0000 (08:45 +0100)
committerRicardo Dias <rdias@suse.com>
Thu, 19 Apr 2018 07:52:26 +0000 (08:52 +0100)
In the current implementation, RESTController tries to infer the
resource ID by looking at the declared parameters of the resource
methods (get, delete, set, and patch). This inference may not always
be correct, and therefore with this commit we can now explicitely
specify the structure of the resource ID. If the resource ID is
not explicitly specified, then we fallback to the inference algorithm.

Signed-off-by: Ricardo Dias <rdias@suse.com>
src/pybind/mgr/dashboard/controllers/__init__.py
src/pybind/mgr/dashboard/controllers/rbd.py

index 6ad5345a2ca0cecf677c454ded5fe1fd5f116953..67c489f0443c01febc31c077fecfbbb65b3c1c01 100644 (file)
@@ -421,6 +421,13 @@ class RESTController(BaseController):
 
     """
 
+    # resource id parameter for using in get, set, and delete methods
+    # should be overriden by subclasses.
+    # to specify a composite id (two parameters) use '/'. e.g., "param1/param2".
+    # If subclasses don't override this property we try to infer the structure of
+    # the resourse ID.
+    RESOURCE_ID = None
+
     _method_mapping = collections.OrderedDict([
         (('GET', False), ('list', 200)),
         (('PUT', False), ('bulk_set', 200)),
@@ -428,9 +435,9 @@ class RESTController(BaseController):
         (('POST', False), ('create', 201)),
         (('DELETE', False), ('bulk_delete', 204)),
         (('GET', True), ('get', 200)),
-        (('PUT', True), ('set', 200)),
-        (('PATCH', True), ('set', 200)),
         (('DELETE', True), ('delete', 204)),
+        (('PUT', True), ('set', 200)),
+        (('PATCH', True), ('set', 200))
     ])
 
     @classmethod
@@ -458,7 +465,10 @@ class RESTController(BaseController):
             if k[1] and hasattr(cls, v[0]):
                 methods.append(k[0])
                 if not args:
-                    args = cls._parse_function_args(getattr(cls, v[0]))
+                    if cls.RESOURCE_ID is None:
+                        args = cls._parse_function_args(getattr(cls, v[0]))
+                    else:
+                        args = cls.RESOURCE_ID.split('/')
         if methods:
             result.append((methods, None, '_element', args))
 
index f7e2a02393d24f2c4145db68ca5c1cec444857c8..aa748f51df23691925fa69c3ec43284d8df96ec6 100644 (file)
@@ -114,6 +114,8 @@ def _sort_features(features, enable=True):
 @AuthRequired()
 class Rbd(RESTController):
 
+    RESOURCE_ID = "pool_name/image_name"
+
     # set of image features that can be enable on existing images
     ALLOW_ENABLE_FEATURES = set(["exclusive-lock", "object-map", "fast-diff",
                                  "journaling"])
@@ -354,6 +356,8 @@ class Rbd(RESTController):
 @ApiController('block/image/:pool_name/:image_name/snap')
 class RbdSnapshot(RESTController):
 
+    RESOURCE_ID = "snapshot_name"
+
     @RbdTask('snap/create',
              ['{pool_name}', '{image_name}', '{snapshot_name}'], 2.0)
     @RESTController.args_from_json