]> 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 51294/head
authorCory Snyder <csnyder@1111systems.com>
Sun, 30 Apr 2023 10:45:41 +0000 (10:45 +0000)
committerCory Snyder <csnyder@1111systems.com>
Tue, 30 May 2023 15:08:29 +0000 (11:08 -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>
src/pybind/mgr/dashboard/controllers/rbd.py
src/pybind/mgr/dashboard/openapi.yaml
src/pybind/mgr/dashboard/services/rbd.py

index 027361feea69a0e63248add83f55f9db0d391d5f..7d58380e24525d906503b6e8c38a088257f47e6a 100644 (file)
@@ -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)
index 9ca2ba04403eb9453a8853a9f4baeb090c887828..6a7d9f7776f4b7799695983d0f631426ae2c2bb9 100644 (file)
@@ -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:
index 98fbba832573e8383aa01f62d944e2e12ee31e29..10c16ce56fff699dcdb8645c1f6d59444fc9a17c 100644 (file)
@@ -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')