From ead0d0e41d798fe07b6864b1f5d73307e40102f6 Mon Sep 17 00:00:00 2001 From: Cory Snyder Date: Sun, 30 Apr 2023 10:45:41 +0000 Subject: [PATCH] mgr/dashboard: add 'omit_usage' query param to dashboard api 'get rbd' endpoint Allows RBD info to be retrieved without getting associated usage info. This can be useful for large RBDs where the process of gathering such usage info is sometimes very slow. Fixes: https://tracker.ceph.com/issues/59588 Signed-off-by: Cory Snyder --- src/pybind/mgr/dashboard/controllers/rbd.py | 14 +++++++++-- src/pybind/mgr/dashboard/openapi.yaml | 27 +++++++++++++++++++-- src/pybind/mgr/dashboard/services/rbd.py | 9 ++++--- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index 027361feea6..7d58380e245 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -122,8 +122,18 @@ class Rbd(RESTController): @handle_rbd_error() @handle_rados_error('pool') - def get(self, image_spec): - return RbdService.get_image(image_spec) + @EndpointDoc("Get Rbd Image Info", + parameters={ + 'image_spec': (str, 'URL-encoded "pool/rbd_name". e.g. "rbd%2Ffoo"'), + 'omit_usage': (bool, 'When true, usage information is not returned'), + }, + responses={200: RBD_SCHEMA}) + def get(self, image_spec, omit_usage=False): + try: + omit_usage_bool = str_to_bool(omit_usage) + except ValueError: + omit_usage_bool = False + return RbdService.get_image(image_spec, omit_usage_bool) @RbdTask('create', {'pool_name': '{pool_name}', 'namespace': '{namespace}', 'image_name': '{name}'}, 2.0) diff --git a/src/pybind/mgr/dashboard/openapi.yaml b/src/pybind/mgr/dashboard/openapi.yaml index 9ca2ba04403..6a7d9f7776f 100644 --- a/src/pybind/mgr/dashboard/openapi.yaml +++ b/src/pybind/mgr/dashboard/openapi.yaml @@ -526,16 +526,38 @@ paths: - Rbd get: parameters: - - in: path + - description: URL-encoded "pool/rbd_name". e.g. "rbd%2Ffoo" + in: path name: image_spec required: true schema: type: string + - default: false + description: When true, usage information is not returned + in: query + name: omit_usage + schema: + type: boolean responses: '200': content: application/vnd.ceph.api.v1.0+json: - type: object + schema: + items: + properties: + pool_name: + description: pool name + type: string + value: + description: '' + items: + type: string + type: array + type: object + required: + - value + - pool_name + type: array description: OK '400': description: Operation exception. Please check the response body for details. @@ -548,6 +570,7 @@ paths: trace. security: - jwt: [] + summary: Get Rbd Image Info tags: - Rbd put: diff --git a/src/pybind/mgr/dashboard/services/rbd.py b/src/pybind/mgr/dashboard/services/rbd.py index 98fbba83257..10c16ce56ff 100644 --- a/src/pybind/mgr/dashboard/services/rbd.py +++ b/src/pybind/mgr/dashboard/services/rbd.py @@ -269,7 +269,8 @@ class RbdService(object): return total_used_size, snap_map @classmethod - def _rbd_image(cls, ioctx, pool_name, namespace, image_name): # pylint: disable=R0912 + def _rbd_image(cls, ioctx, pool_name, namespace, image_name, # pylint: disable=R0912 + omit_usage=False): with rbd.Image(ioctx, image_name) as img: stat = img.stat() mirror_info = img.mirror_image_get_info() @@ -353,7 +354,7 @@ class RbdService(object): # disk usage img_flags = img.flags() - if 'fast-diff' in stat['features_name'] and \ + if not omit_usage and 'fast-diff' in stat['features_name'] and \ not rbd.RBD_FLAG_FAST_DIFF_INVALID & img_flags and \ mirror_mode != rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT: snaps = [(s['id'], s['size'], s['name']) @@ -481,13 +482,13 @@ class RbdService(object): return result, paginator.get_count() @classmethod - def get_image(cls, image_spec): + def get_image(cls, image_spec, omit_usage=False): pool_name, namespace, image_name = parse_image_spec(image_spec) ioctx = mgr.rados.open_ioctx(pool_name) if namespace: ioctx.set_namespace(namespace) try: - return cls._rbd_image(ioctx, pool_name, namespace, image_name) + return cls._rbd_image(ioctx, pool_name, namespace, image_name, omit_usage) except rbd.ImageNotFound: raise cherrypy.HTTPError(404, 'Image not found') -- 2.39.5