super().__init__()
self.rbd_inst = rbd.RBD()
+ @handle_rbd_error()
@EndpointDoc("Display RBD Groups by pool name",
parameters={
'pool_name': (str, 'Name of the pool'),
},
responses={200: RBD_GROUP_LIST_SCHEMA})
- def list(self, pool_name):
+ def list(self, pool_name, namespace=None):
with mgr.rados.open_ioctx(pool_name) as ioctx:
+ RbdService.validate_namespace(ioctx, namespace)
+ ioctx.set_namespace(namespace)
result = []
groups = self.rbd_inst.group_list(ioctx)
for group in groups:
})
return result
+ @handle_rbd_error()
@EndpointDoc("Create an RBD Group",
parameters={
'pool_name': (str, 'Name of the pool'),
'name': (str, 'Name of the group'),
})
- def create(self, pool_name, name):
+ def create(self, pool_name, name, namespace=None):
with mgr.rados.open_ioctx(pool_name) as ioctx:
+ RbdService.validate_namespace(ioctx, namespace)
+ ioctx.set_namespace(namespace)
return self.rbd_inst.group_create(ioctx, name)
+
+ @RESTController.Collection('POST', path='/{group_name}/image')
+ @handle_rbd_error()
+ @EndpointDoc("Add an image to an RBD Group",
+ parameters={
+ 'pool_name': (str, 'Name of the pool'),
+ 'group_name': (str, 'Name of the group'),
+ 'image_name': (str, 'Name of the image'),
+ },
+ responses={200: None})
+ def add_image(self, pool_name, group_name, image_name, namespace=None):
+ with mgr.rados.open_ioctx(pool_name) as ioctx:
+ group = rbd.Group(ioctx, group_name)
+ RbdService.validate_namespace(ioctx, namespace)
+ ioctx.set_namespace(namespace)
+ return group.add_image(ioctx, image_name)
required: true
schema:
type: string
+ - allowEmptyValue: true
+ in: query
+ name: namespace
+ schema:
+ type: string
responses:
'200':
content:
name:
description: Name of the group
type: string
+ namespace:
+ type: string
required:
- name
type: object
summary: Create an RBD Group
tags:
- RbdGroup
+ /api/block/pool/{pool_name}/group/{group_name}/image:
+ post:
+ parameters:
+ - description: Name of the pool
+ in: path
+ name: pool_name
+ required: true
+ schema:
+ type: string
+ - description: Name of the group
+ in: path
+ name: group_name
+ required: true
+ schema:
+ type: string
+ requestBody:
+ content:
+ application/json:
+ schema:
+ properties:
+ image_name:
+ description: Name of the image
+ type: string
+ namespace:
+ type: string
+ required:
+ - image_name
+ type: object
+ responses:
+ '201':
+ content:
+ application/vnd.ceph.api.v1.0+json:
+ type: object
+ description: Resource created.
+ '202':
+ content:
+ application/vnd.ceph.api.v1.0+json:
+ type: object
+ description: Operation is still executing. Please check the task queue.
+ '400':
+ description: Operation exception. Please check the response body for details.
+ '401':
+ description: Unauthenticated access. Please login first.
+ '403':
+ description: Unauthorized access. Please check your permissions.
+ '500':
+ description: Unexpected error. Please check the response body for the stack
+ trace.
+ security:
+ - jwt: []
+ summary: Add an image to an RBD Group
+ tags:
+ - RbdGroup
/api/block/pool/{pool_name}/namespace:
get:
parameters:
"""
Removes an option by name. Will not raise an error, if the option hasn't been found.
:type option_name str
+
"""
def _remove(ioctx):
try:
class RbdService(object):
_rbd_inst = rbd.RBD()
-
# set of image features that can be enable on existing images
ALLOW_ENABLE_FEATURES = {"exclusive-lock", "object-map", "fast-diff", "journaling"}
rbd_inst = cls._rbd_inst
return rbd_call(pool_name, namespace, rbd_inst.trash_move, image_name, delay)
+ @classmethod
+ def validate_namespace(cls, ioctx, namespace):
+ namespaces = cls._rbd_inst.namespace_list(ioctx)
+ if namespace and namespace not in namespaces:
+ raise DashboardException(
+ msg='Namespace not found',
+ code='namespace_not_found',
+ component='rbd')
+
class RbdSnapshotService(object):