Skip to content

Commit 5e58d00

Browse files
authored
Merge pull request ceph#51294 from cfsnyder/wip-59588
mgr/dashboard: add 'omit_usage' query param to dashboard api 'get rbd' endpoint Reviewed-by: Nizamudeen A <[email protected]> Reviewed-by: Pere Diaz Bou <[email protected]>
2 parents d146d2b + ead0d0e commit 5e58d00

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/pybind/mgr/dashboard/controllers/rbd.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,18 @@ def list(self, pool_name=None, offset: int = 0, limit: int = DEFAULT_LIMIT,
122122

123123
@handle_rbd_error()
124124
@handle_rados_error('pool')
125-
def get(self, image_spec):
126-
return RbdService.get_image(image_spec)
125+
@EndpointDoc("Get Rbd Image Info",
126+
parameters={
127+
'image_spec': (str, 'URL-encoded "pool/rbd_name". e.g. "rbd%2Ffoo"'),
128+
'omit_usage': (bool, 'When true, usage information is not returned'),
129+
},
130+
responses={200: RBD_SCHEMA})
131+
def get(self, image_spec, omit_usage=False):
132+
try:
133+
omit_usage_bool = str_to_bool(omit_usage)
134+
except ValueError:
135+
omit_usage_bool = False
136+
return RbdService.get_image(image_spec, omit_usage_bool)
127137

128138
@RbdTask('create',
129139
{'pool_name': '{pool_name}', 'namespace': '{namespace}', 'image_name': '{name}'}, 2.0)

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,38 @@ paths:
526526
- Rbd
527527
get:
528528
parameters:
529-
- in: path
529+
- description: URL-encoded "pool/rbd_name". e.g. "rbd%2Ffoo"
530+
in: path
530531
name: image_spec
531532
required: true
532533
schema:
533534
type: string
535+
- default: false
536+
description: When true, usage information is not returned
537+
in: query
538+
name: omit_usage
539+
schema:
540+
type: boolean
534541
responses:
535542
'200':
536543
content:
537544
application/vnd.ceph.api.v1.0+json:
538-
type: object
545+
schema:
546+
items:
547+
properties:
548+
pool_name:
549+
description: pool name
550+
type: string
551+
value:
552+
description: ''
553+
items:
554+
type: string
555+
type: array
556+
type: object
557+
required:
558+
- value
559+
- pool_name
560+
type: array
539561
description: OK
540562
'400':
541563
description: Operation exception. Please check the response body for details.
@@ -548,6 +570,7 @@ paths:
548570
trace.
549571
security:
550572
- jwt: []
573+
summary: Get Rbd Image Info
551574
tags:
552575
- Rbd
553576
put:

src/pybind/mgr/dashboard/services/rbd.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ def __call__(self, offset, length, exists):
269269
return total_used_size, snap_map
270270

271271
@classmethod
272-
def _rbd_image(cls, ioctx, pool_name, namespace, image_name): # pylint: disable=R0912
272+
def _rbd_image(cls, ioctx, pool_name, namespace, image_name, # pylint: disable=R0912
273+
omit_usage=False):
273274
with rbd.Image(ioctx, image_name) as img:
274275
stat = img.stat()
275276
mirror_info = img.mirror_image_get_info()
@@ -353,7 +354,7 @@ def _rbd_image(cls, ioctx, pool_name, namespace, image_name): # pylint: disable
353354

354355
# disk usage
355356
img_flags = img.flags()
356-
if 'fast-diff' in stat['features_name'] and \
357+
if not omit_usage and 'fast-diff' in stat['features_name'] and \
357358
not rbd.RBD_FLAG_FAST_DIFF_INVALID & img_flags and \
358359
mirror_mode != rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT:
359360
snaps = [(s['id'], s['size'], s['name'])
@@ -481,13 +482,13 @@ def rbd_pool_list(cls, pool_names: List[str], namespace: Optional[str] = None, o
481482
return result, paginator.get_count()
482483

483484
@classmethod
484-
def get_image(cls, image_spec):
485+
def get_image(cls, image_spec, omit_usage=False):
485486
pool_name, namespace, image_name = parse_image_spec(image_spec)
486487
ioctx = mgr.rados.open_ioctx(pool_name)
487488
if namespace:
488489
ioctx.set_namespace(namespace)
489490
try:
490-
return cls._rbd_image(ioctx, pool_name, namespace, image_name)
491+
return cls._rbd_image(ioctx, pool_name, namespace, image_name, omit_usage)
491492
except rbd.ImageNotFound:
492493
raise cherrypy.HTTPError(404, 'Image not found')
493494

0 commit comments

Comments
 (0)