コード例 #1
0
    def update(self, req, id, body):
        # Update description for a given group type.
        context = req.environ['cinder.context']
        self._check_policy(context)

        self.assert_valid_body(body, 'group_type')

        grp_type = body['group_type']
        description = grp_type.get('description')
        name = grp_type.get('name')
        is_public = grp_type.get('is_public')

        # Name and description can not be both None.
        # If name specified, name can not be empty.
        if name and len(name.strip()) == 0:
            msg = _("Group type name can not be empty.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        if name is None and description is None and is_public is None:
            msg = _("Specify group type name, description or "
                    "a combination thereof.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        if is_public is not None and not strutils.is_valid_boolstr(is_public):
            msg = _("Invalid value '%s' for is_public. Accepted values: "
                    "True or False.") % is_public
            raise webob.exc.HTTPBadRequest(explanation=msg)

        if name:
            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.update(context, id, name, description,
                               is_public=is_public)
            # Get the updated
            grp_type = group_types.get_group_type(context, id)
            req.cache_resource(grp_type, name='group_types')
            self._notify_group_type_info(
                context, 'group_type.update', grp_type)

        except exception.GroupTypeNotFound as err:
            self._notify_group_type_error(
                context, 'group_type.update', err, id=id)
            raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
        except exception.GroupTypeExists as err:
            self._notify_group_type_error(
                context, 'group_type.update', err, group_type=grp_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.GroupTypeUpdateFailed as err:
            self._notify_group_type_error(
                context, 'group_type.update', err, group_type=grp_type)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.show(req, grp_type)
コード例 #2
0
    def update(self, req, id, body):
        # Update description for a given group type.
        context = req.environ['cinder.context']
        self._check_policy(context)

        self.assert_valid_body(body, 'group_type')

        grp_type = body['group_type']
        description = grp_type.get('description')
        name = grp_type.get('name')
        is_public = grp_type.get('is_public')

        # Name and description can not be both None.
        # If name specified, name can not be empty.
        if name and len(name.strip()) == 0:
            msg = _("Group type name can not be empty.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        if name is None and description is None and is_public is None:
            msg = _("Specify group type name, description or "
                    "a combination thereof.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        if is_public is not None and not utils.is_valid_boolstr(is_public):
            msg = _("Invalid value '%s' for is_public. Accepted values: "
                    "True or False.") % is_public
            raise webob.exc.HTTPBadRequest(explanation=msg)

        if name:
            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.update(context, id, name, description,
                               is_public=is_public)
            # Get the updated
            grp_type = group_types.get_group_type(context, id)
            req.cache_resource(grp_type, name='group_types')
            self._notify_group_type_info(
                context, 'group_type.update', grp_type)

        except exception.GroupTypeNotFound as err:
            self._notify_group_type_error(
                context, 'group_type.update', err, id=id)
            raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
        except exception.GroupTypeExists as err:
            self._notify_group_type_error(
                context, 'group_type.update', err, group_type=grp_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.GroupTypeUpdateFailed as err:
            self._notify_group_type_error(
                context, 'group_type.update', err, group_type=grp_type)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.show(req, grp_type)
コード例 #3
0
    def update(self, req, id, body):
        # Update description for a given group type.
        context = req.environ['cinder.context']
        context.authorize(policy.MANAGE_POLICY)

        grp_type = body['group_type']
        description = grp_type.get('description')
        name = grp_type.get('name')
        is_public = grp_type.get('is_public')
        if is_public is not None:
            is_public = strutils.bool_from_string(is_public, strict=True)

        # If name specified, name can not be empty.
        if name and len(name.strip()) == 0:
            msg = _("Group type name can not be empty.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        # Name, description and is_public can not be None.
        # Specify one of them, or a combination thereof.
        if name is None and description is None and is_public is None:
            msg = _("Specify group type name, description or "
                    "a combination thereof.")
            raise webob.exc.HTTPBadRequest(explanation=msg)
        try:
            group_types.update(context,
                               id,
                               name,
                               description,
                               is_public=is_public)
            # Get the updated
            grp_type = group_types.get_group_type(context, id)
            req.cache_resource(grp_type, name='group_types')
            self._notify_group_type_info(context, 'group_type.update',
                                         grp_type)

        except exception.GroupTypeNotFound as err:
            self._notify_group_type_error(context,
                                          'group_type.update',
                                          err,
                                          id=id)
            raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
        except exception.GroupTypeExists as err:
            self._notify_group_type_error(context,
                                          'group_type.update',
                                          err,
                                          group_type=grp_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.GroupTypeUpdateFailed as err:
            self._notify_group_type_error(context,
                                          'group_type.update',
                                          err,
                                          group_type=grp_type)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.show(req, grp_type)
コード例 #4
0
ファイル: group_types.py プロジェクト: j-griffith/cinder
    def update(self, req, id, body):
        # Update description for a given group type.
        context = req.environ['cinder.context']
        context.authorize(policy.MANAGE_POLICY)

        grp_type = body['group_type']
        description = grp_type.get('description')
        name = grp_type.get('name')
        is_public = grp_type.get('is_public')
        if is_public is not None:
            is_public = strutils.bool_from_string(is_public, strict=True)

        # If name specified, name can not be empty.
        if name and len(name.strip()) == 0:
            msg = _("Group type name can not be empty.")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        # Name, description and is_public can not be None.
        # Specify one of them, or a combination thereof.
        if name is None and description is None and is_public is None:
            msg = _("Specify group type name, description or "
                    "a combination thereof.")
            raise webob.exc.HTTPBadRequest(explanation=msg)
        try:
            group_types.update(context, id, name, description,
                               is_public=is_public)
            # Get the updated
            grp_type = group_types.get_group_type(context, id)
            req.cache_resource(grp_type, name='group_types')
            self._notify_group_type_info(
                context, 'group_type.update', grp_type)

        except exception.GroupTypeNotFound as err:
            self._notify_group_type_error(
                context, 'group_type.update', err, id=id)
            raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
        except exception.GroupTypeExists as err:
            self._notify_group_type_error(
                context, 'group_type.update', err, group_type=grp_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.GroupTypeUpdateFailed as err:
            self._notify_group_type_error(
                context, 'group_type.update', err, group_type=grp_type)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.show(req, grp_type)
コード例 #5
0
    def update(self, req, id, body):
        # Update description for a given group type.
        context = req.environ['cinder.context']
        context.authorize(policy.MANAGE_POLICY)

        grp_type = body['group_type']
        description = grp_type.get('description')
        name = grp_type.get('name')
        is_public = grp_type.get('is_public')
        if is_public is not None:
            is_public = strutils.bool_from_string(is_public, strict=True)

        try:
            group_types.update(context,
                               id,
                               name,
                               description,
                               is_public=is_public)
            # Get the updated
            grp_type = group_types.get_group_type(context, id)
            req.cache_resource(grp_type, name='group_types')
            self._notify_group_type_info(context, 'group_type.update',
                                         grp_type)

        except exception.GroupTypeNotFound as err:
            self._notify_group_type_error(context,
                                          'group_type.update',
                                          err,
                                          id=id)
            raise webob.exc.HTTPNotFound(explanation=six.text_type(err))
        except exception.GroupTypeExists as err:
            self._notify_group_type_error(context,
                                          'group_type.update',
                                          err,
                                          group_type=grp_type)
            raise webob.exc.HTTPConflict(explanation=six.text_type(err))
        except exception.GroupTypeUpdateFailed as err:
            self._notify_group_type_error(context,
                                          'group_type.update',
                                          err,
                                          group_type=grp_type)
            raise webob.exc.HTTPInternalServerError(
                explanation=six.text_type(err))

        return self._view_builder.show(req, grp_type)
コード例 #6
0
 def save(self):
     updates = self.cinder_obj_get_changes()
     if updates:
         group_types.update(self._context, self.id, self.name,
                            self.description)
         self.obj_reset_changes()
コード例 #7
0
ファイル: group_type.py プロジェクト: sebrandon1/cinder
 def save(self):
     updates = self.cinder_obj_get_changes()
     if updates:
         group_types.update(self._context, self.id, self.name, self.description)
         self.obj_reset_changes()