def create(self, req, body): """Creates a new group type.""" context = req.environ['cinder.context'] context.authorize(policy.CREATE_POLICY) grp_type = body['group_type'] name = grp_type['name'] description = grp_type.get('description') specs = grp_type.get('group_specs', {}) is_public = strutils.bool_from_string(grp_type.get('is_public', True), strict=True) try: group_types.create(context, name, specs, is_public, description=description) grp_type = group_types.get_group_type_by_name(context, name) req.cache_resource(grp_type, name='group_types') self._notify_group_type_info( context, 'group_type.create', grp_type) except exception.GroupTypeExists as err: self._notify_group_type_error( context, 'group_type.create', err, group_type=grp_type) raise webob.exc.HTTPConflict(explanation=str(err)) except exception.GroupTypeNotFoundByName as err: self._notify_group_type_error( context, 'group_type.create', err, name=name) raise webob.exc.HTTPNotFound(explanation=err.msg) return self._view_builder.show(req, grp_type)
def create(self, req, body): """Creates a new group type.""" context = req.environ['cinder.context'] context.authorize(policy.MANAGE_POLICY) grp_type = body['group_type'] name = grp_type['name'] description = grp_type.get('description') specs = grp_type.get('group_specs', {}) is_public = strutils.bool_from_string(grp_type.get('is_public', True), strict=True) try: group_types.create(context, name, specs, is_public, description=description) grp_type = group_types.get_group_type_by_name(context, name) req.cache_resource(grp_type, name='group_types') self._notify_group_type_info( context, 'group_type.create', grp_type) except exception.GroupTypeExists as err: self._notify_group_type_error( context, 'group_type.create', err, group_type=grp_type) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.GroupTypeNotFoundByName as err: self._notify_group_type_error( context, 'group_type.create', err, name=name) raise webob.exc.HTTPNotFound(explanation=err.msg) return self._view_builder.show(req, grp_type)
def create(self, req, body): """Creates a new group type.""" context = req.environ['cinder.context'] self._check_policy(context) self.assert_valid_body(body, 'group_type') grp_type = body['group_type'] name = grp_type.get('name', None) description = grp_type.get('description') specs = grp_type.get('group_specs', {}) is_public = utils.get_bool_param('is_public', grp_type, True) if name is None or len(name.strip()) == 0: msg = _("Group type name can not be empty.") raise webob.exc.HTTPBadRequest(explanation=msg) utils.check_string_length(name, 'Type name', min_length=1, max_length=255) if description is not None: utils.check_string_length(description, 'Type description', min_length=0, max_length=255) try: group_types.create(context, name, specs, is_public, description=description) grp_type = group_types.get_group_type_by_name(context, name) req.cache_resource(grp_type, name='group_types') self._notify_group_type_info(context, 'group_type.create', grp_type) except exception.GroupTypeExists as err: self._notify_group_type_error(context, 'group_type.create', err, group_type=grp_type) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.GroupTypeNotFoundByName as err: self._notify_group_type_error(context, 'group_type.create', err, name=name) raise webob.exc.HTTPNotFound(explanation=err.msg) return self._view_builder.show(req, grp_type)
def create(self, req, body): """Create a new group.""" LOG.debug('Creating new group %s', body) self.assert_valid_body(body, 'group') context = req.environ['cinder.context'] group = body['group'] self.validate_name_and_description(group) name = group.get('name') description = group.get('description') group_type = group.get('group_type') if not group_type: msg = _("group_type must be provided to create " "group %(name)s.") % { 'name': name } raise exc.HTTPBadRequest(explanation=msg) if not uuidutils.is_uuid_like(group_type): req_group_type = group_types.get_group_type_by_name( context, group_type) group_type = req_group_type.id self._check_default_cgsnapshot_type(group_type) volume_types = group.get('volume_types') if not volume_types: msg = _("volume_types must be provided to create " "group %(name)s.") % { 'name': name } raise exc.HTTPBadRequest(explanation=msg) availability_zone = group.get('availability_zone') LOG.info(_LI("Creating group %(name)s."), {'name': name}, context=context) try: new_group = self.group_api.create( context, name, description, group_type, volume_types, availability_zone=availability_zone) except (exception.Invalid, exception.ObjectActionError) as error: raise exc.HTTPBadRequest(explanation=error.msg) except exception.NotFound: # Not found exception will be handled at the wsgi level raise retval = self._view_builder.summary(req, new_group) return retval
def create(self, req, body): """Creates a new group type.""" context = req.environ['cinder.context'] self._check_policy(context) self.assert_valid_body(body, 'group_type') grp_type = body['group_type'] name = grp_type.get('name', None) description = grp_type.get('description') specs = grp_type.get('group_specs', {}) is_public = utils.get_bool_param('is_public', grp_type, True) if name is None or len(name.strip()) == 0: msg = _("Group type name can not be empty.") raise webob.exc.HTTPBadRequest(explanation=msg) utils.check_string_length(name, 'Type name', min_length=1, max_length=255) if description is not None: utils.check_string_length(description, 'Type description', min_length=0, max_length=255) try: group_types.create(context, name, specs, is_public, description=description) grp_type = group_types.get_group_type_by_name(context, name) req.cache_resource(grp_type, name='group_types') self._notify_group_type_info( context, 'group_type.create', grp_type) except exception.GroupTypeExists as err: self._notify_group_type_error( context, 'group_type.create', err, group_type=grp_type) raise webob.exc.HTTPConflict(explanation=six.text_type(err)) except exception.GroupTypeNotFoundByName as err: self._notify_group_type_error( context, 'group_type.create', err, name=name) raise webob.exc.HTTPNotFound(explanation=err.msg) return self._view_builder.show(req, grp_type)
def create(self, req, body): """Create a new group.""" LOG.debug('Creating new group %s', body) self.assert_valid_body(body, 'group') context = req.environ['cinder.context'] group = body['group'] self.validate_name_and_description(group) name = group.get('name') description = group.get('description') group_type = group.get('group_type') if not group_type: msg = _("group_type must be provided to create " "group %(name)s.") % {'name': name} raise exc.HTTPBadRequest(explanation=msg) if not uuidutils.is_uuid_like(group_type): req_group_type = group_types.get_group_type_by_name(context, group_type) group_type = req_group_type['id'] self._check_default_cgsnapshot_type(group_type) volume_types = group.get('volume_types') if not volume_types: msg = _("volume_types must be provided to create " "group %(name)s.") % {'name': name} raise exc.HTTPBadRequest(explanation=msg) availability_zone = group.get('availability_zone') LOG.info("Creating group %(name)s.", {'name': name}, context=context) try: new_group = self.group_api.create( context, name, description, group_type, volume_types, availability_zone=availability_zone) except (exception.Invalid, exception.ObjectActionError) as error: raise exc.HTTPBadRequest(explanation=error.msg) except exception.NotFound: # Not found exception will be handled at the wsgi level raise retval = self._view_builder.summary(req, new_group) return retval
def create(self, req, body): """Create a new group.""" LOG.debug('Creating new group %s', body) context = req.environ['cinder.context'] group = body['group'] name = group.get('name') description = group.get('description') if name: name = name.strip() if description: description = description.strip() group_type = group['group_type'] if not uuidutils.is_uuid_like(group_type): req_group_type = group_types.get_group_type_by_name( context, group_type) group_type = req_group_type['id'] self._check_default_cgsnapshot_type(group_type) volume_types = group['volume_types'] availability_zone = group.get('availability_zone') LOG.info("Creating group %(name)s.", {'name': name}, context=context) try: new_group = self.group_api.create( context, name, description, group_type, volume_types, availability_zone=availability_zone) except (exception.Invalid, exception.ObjectActionError) as error: raise exc.HTTPBadRequest(explanation=error.msg) except exception.NotFound: # Not found exception will be handled at the wsgi level raise retval = self._view_builder.summary(req, new_group) return retval