From: Ricardo Dias Date: Thu, 19 Apr 2018 07:45:40 +0000 (+0100) Subject: mgr/dashboard: restcontroller: support explicit resource ID X-Git-Tag: v13.1.0~173^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=671b1348857e30172dc06be7b9a214d7fc386bf1;p=ceph.git mgr/dashboard: restcontroller: support explicit resource ID 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 --- diff --git a/src/pybind/mgr/dashboard/controllers/__init__.py b/src/pybind/mgr/dashboard/controllers/__init__.py index 6ad5345a2ca0..67c489f0443c 100644 --- a/src/pybind/mgr/dashboard/controllers/__init__.py +++ b/src/pybind/mgr/dashboard/controllers/__init__.py @@ -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)) diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index f7e2a02393d2..aa748f51df23 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -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