From c6a6c320026a618302bf0670f526e1661a7f3cb1 Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Wed, 28 Mar 2018 14:33:01 +0100 Subject: [PATCH] mgr/dashboard: rbd: asynchronous image create Signed-off-by: Ricardo Dias --- src/pybind/mgr/dashboard/controllers/rbd.py | 33 +++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index 974958ae7fa..5a77faf9a3f 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=too-many-arguments from __future__ import absolute_import import math @@ -8,7 +9,7 @@ import rbd from . import ApiController, AuthRequired, RESTController from .. import mgr from ..services.ceph_service import CephService -from ..tools import ViewCache +from ..tools import ViewCache, TaskManager @ApiController('rbd') @@ -53,7 +54,7 @@ class Rbd(RESTController): >>> Rbd._format_features('not a list') is None True """ - if not features or not isinstance(features, list): + if not isinstance(features, list): return None res = 0 @@ -152,27 +153,19 @@ class Rbd(RESTController): except rbd.ImageNotFound: raise cherrypy.HTTPError(404) - def create(self, data): + @classmethod + def _create_image(cls, name, pool_name, size, obj_size=None, features=None, + stripe_unit=None, stripe_count=None, data_pool=None): # pylint: disable=too-many-locals rbd_inst = rbd.RBD() - # Get input values - name = data.get('name') - pool_name = data.get('pool_name') - size = data.get('size') - obj_size = data.get('obj_size') - features = data.get('features') - stripe_unit = data.get('stripe_unit') - stripe_count = data.get('stripe_count') - data_pool = data.get('data_pool') - # Set order order = None if obj_size and obj_size > 0: order = int(round(math.log(float(obj_size), 2))) # Set features - feature_bitmask = self._format_features(features) + feature_bitmask = cls._format_features(features) ioctx = mgr.rados.open_ioctx(pool_name) @@ -181,6 +174,16 @@ class Rbd(RESTController): features=feature_bitmask, stripe_unit=stripe_unit, stripe_count=stripe_count, data_pool=data_pool) except rbd.OSError as e: - cherrypy.response.status = 400 return {'success': False, 'detail': str(e), 'errno': e.errno} return {'success': True} + + @RESTController.args_from_json + def create(self, name, pool_name, size, obj_size=None, features=None, + stripe_unit=None, stripe_count=None, data_pool=None): + task = TaskManager.run('rbd/create', + {'pool_name': pool_name, 'image_name': name}, + self._create_image, + [name, pool_name, size, obj_size, features, + stripe_unit, stripe_count, data_pool]) + status, value = task.wait(1.0) + return {'status': status, 'value': value} -- 2.39.5