Skip to content

Commit 750c25b

Browse files
committed
mgr/dashboard: add API endpoint to add images to consistency groups
Signed-off-by: Imran Imtiaz <[email protected]> Fixes: https://tracker.ceph.com/issues/73840 Create a consistency group dashboard API endpoint that enables adding RBD images to the group.
1 parent 4b56f3d commit 750c25b

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,16 @@ def __init__(self):
471471
super().__init__()
472472
self.rbd_inst = rbd.RBD()
473473

474+
@handle_rbd_error()
474475
@EndpointDoc("Display RBD Groups by pool name",
475476
parameters={
476477
'pool_name': (str, 'Name of the pool'),
477478
},
478479
responses={200: RBD_GROUP_LIST_SCHEMA})
479-
def list(self, pool_name):
480+
def list(self, pool_name, namespace=None):
480481
with mgr.rados.open_ioctx(pool_name) as ioctx:
482+
RbdService.validate_namespace(ioctx, namespace)
483+
ioctx.set_namespace(namespace)
481484
result = []
482485
groups = self.rbd_inst.group_list(ioctx)
483486
for group in groups:
@@ -487,11 +490,30 @@ def list(self, pool_name):
487490
})
488491
return result
489492

493+
@handle_rbd_error()
490494
@EndpointDoc("Create an RBD Group",
491495
parameters={
492496
'pool_name': (str, 'Name of the pool'),
493497
'name': (str, 'Name of the group'),
494498
})
495-
def create(self, pool_name, name):
499+
def create(self, pool_name, name, namespace=None):
496500
with mgr.rados.open_ioctx(pool_name) as ioctx:
501+
RbdService.validate_namespace(ioctx, namespace)
502+
ioctx.set_namespace(namespace)
497503
return self.rbd_inst.group_create(ioctx, name)
504+
505+
@RESTController.Collection('POST', path='/{group_name}/image')
506+
@handle_rbd_error()
507+
@EndpointDoc("Add an image to an RBD Group",
508+
parameters={
509+
'pool_name': (str, 'Name of the pool'),
510+
'group_name': (str, 'Name of the group'),
511+
'image_name': (str, 'Name of the image'),
512+
},
513+
responses={200: None})
514+
def add_image(self, pool_name, group_name, image_name, namespace=None):
515+
with mgr.rados.open_ioctx(pool_name) as ioctx:
516+
group = rbd.Group(ioctx, group_name)
517+
RbdService.validate_namespace(ioctx, namespace)
518+
ioctx.set_namespace(namespace)
519+
return group.add_image(ioctx, image_name)

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,11 @@ paths:
15991599
required: true
16001600
schema:
16011601
type: string
1602+
- allowEmptyValue: true
1603+
in: query
1604+
name: namespace
1605+
schema:
1606+
type: string
16021607
responses:
16031608
'200':
16041609
content:
@@ -1648,6 +1653,8 @@ paths:
16481653
name:
16491654
description: Name of the group
16501655
type: string
1656+
namespace:
1657+
type: string
16511658
required:
16521659
- name
16531660
type: object
@@ -1676,6 +1683,59 @@ paths:
16761683
summary: Create an RBD Group
16771684
tags:
16781685
- RbdGroup
1686+
/api/block/pool/{pool_name}/group/{group_name}/image:
1687+
post:
1688+
parameters:
1689+
- description: Name of the pool
1690+
in: path
1691+
name: pool_name
1692+
required: true
1693+
schema:
1694+
type: string
1695+
- description: Name of the group
1696+
in: path
1697+
name: group_name
1698+
required: true
1699+
schema:
1700+
type: string
1701+
requestBody:
1702+
content:
1703+
application/json:
1704+
schema:
1705+
properties:
1706+
image_name:
1707+
description: Name of the image
1708+
type: string
1709+
namespace:
1710+
type: string
1711+
required:
1712+
- image_name
1713+
type: object
1714+
responses:
1715+
'201':
1716+
content:
1717+
application/vnd.ceph.api.v1.0+json:
1718+
type: object
1719+
description: Resource created.
1720+
'202':
1721+
content:
1722+
application/vnd.ceph.api.v1.0+json:
1723+
type: object
1724+
description: Operation is still executing. Please check the task queue.
1725+
'400':
1726+
description: Operation exception. Please check the response body for details.
1727+
'401':
1728+
description: Unauthenticated access. Please login first.
1729+
'403':
1730+
description: Unauthorized access. Please check your permissions.
1731+
'500':
1732+
description: Unexpected error. Please check the response body for the stack
1733+
trace.
1734+
security:
1735+
- jwt: []
1736+
summary: Add an image to an RBD Group
1737+
tags:
1738+
- RbdGroup
16791739
/api/block/pool/{pool_name}/namespace:
16801740
get:
16811741
parameters:

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def remove(self, option_name):
236236
"""
237237
Removes an option by name. Will not raise an error, if the option hasn't been found.
238238
:type option_name str
239+
239240
"""
240241
def _remove(ioctx):
241242
try:
@@ -267,7 +268,6 @@ def set_configuration(self, configuration):
267268

268269
class RbdService(object):
269270
_rbd_inst = rbd.RBD()
270-
271271
# set of image features that can be enable on existing images
272272
ALLOW_ENABLE_FEATURES = {"exclusive-lock", "object-map", "fast-diff", "journaling"}
273273

@@ -694,6 +694,15 @@ def move_image_to_trash(cls, image_spec, delay):
694694
rbd_inst = cls._rbd_inst
695695
return rbd_call(pool_name, namespace, rbd_inst.trash_move, image_name, delay)
696696

697+
@classmethod
698+
def validate_namespace(cls, ioctx, namespace):
699+
namespaces = cls._rbd_inst.namespace_list(ioctx)
700+
if namespace and namespace not in namespaces:
701+
raise DashboardException(
702+
msg='Namespace not found',
703+
code='namespace_not_found',
704+
component='rbd')
705+
697706

698707
class RbdSnapshotService(object):
699708

0 commit comments

Comments
 (0)