]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: add 'omit_usage' query param to dashboard api 'get rbd' endpoint 54192/head
authorCory Snyder <csnyder@1111systems.com>
Sun, 30 Apr 2023 10:45:41 +0000 (10:45 +0000)
committerCory Snyder <csnyder@1111systems.com>
Wed, 25 Oct 2023 14:00:27 +0000 (10:00 -0400)
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 <csnyder@1111systems.com>
(cherry picked from commit ead0d0e41d798fe07b6864b1f5d73307e40102f6)

src/pybind/mgr/dashboard/controllers/rbd.py
src/pybind/mgr/dashboard/openapi.yaml
src/pybind/mgr/dashboard/services/rbd.py

index f5279aaecffc126f9bc432cd679f188b781bf05a..210531d341c7911cb62dc75fdfc24192b4a82f34 100644 (file)
@@ -118,8 +118,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)
index 0af8910376d7f0260b227e5e8b9cfdf9e6699c90..38ebd0041d9fa76a8a635bccf03a0abcff591307 100644 (file)
@@ -524,16 +524,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.
@@ -546,6 +568,7 @@ paths:
             trace.
       security:
       - jwt: []
+      summary: Get Rbd Image Info
       tags:
       - Rbd
     put:
index f14aa244f8e60b7b9b33ba1b8f49664d5b3c5545..b2181344fdd352c3778e1b6c4269f1301e9856ad 100644 (file)
@@ -289,7 +289,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_mode = img.mirror_image_get_mode()
@@ -371,7 +372,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'])
@@ -507,13 +508,13 @@ class RbdService(object):
         return result, len(image_refs)
 
     @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')