Exemple #1
0
    def update(self, req, id, body):
        """Update a security group."""
        context = _authorize_context(req)

        try:
            id = security_group_api.validate_id(id)
            security_group = security_group_api.get(
                context, None, id, map_exception=True)
        except exception.SecurityGroupNotFound as exp:
            raise exc.HTTPNotFound(explanation=exp.format_message())
        except exception.Invalid as exp:
            raise exc.HTTPBadRequest(explanation=exp.format_message())

        security_group_data = self._from_body(body, 'security_group')
        group_name = security_group_data.get('name', None)
        group_description = security_group_data.get('description', None)

        try:
            security_group_api.validate_property(group_name, 'name', None)
            security_group_api.validate_property(
                group_description, 'description', None)
            group_ref = security_group_api.update_security_group(
                context, security_group, group_name, group_description)
        except exception.SecurityGroupNotFound as exp:
            raise exc.HTTPNotFound(explanation=exp.format_message())
        except exception.Invalid as exp:
            raise exc.HTTPBadRequest(explanation=exp.format_message())

        return {'security_group': self._format_security_group(context,
                                                              group_ref)}
    def update(self, req, id, body):
        """Update a security group."""
        context = req.environ['nova.context']
        context.can(sg_policies.POLICY_NAME % 'update',
                    target={'project_id': context.project_id})

        try:
            id = security_group_api.validate_id(id)
            security_group = security_group_api.get(context, id)
        except exception.SecurityGroupNotFound as exp:
            raise exc.HTTPNotFound(explanation=exp.format_message())
        except exception.Invalid as exp:
            raise exc.HTTPBadRequest(explanation=exp.format_message())

        security_group_data = self._from_body(body, 'security_group')
        group_name = security_group_data.get('name', None)
        group_description = security_group_data.get('description', None)

        try:
            security_group_api.validate_property(group_name, 'name', None)
            security_group_api.validate_property(group_description,
                                                 'description', None)
            group_ref = security_group_api.update_security_group(
                context, security_group, group_name, group_description)
        except exception.SecurityGroupNotFound as exp:
            raise exc.HTTPNotFound(explanation=exp.format_message())
        except exception.Invalid as exp:
            raise exc.HTTPBadRequest(explanation=exp.format_message())

        return {
            'security_group': self._format_security_group(context, group_ref)
        }
Exemple #3
0
 def test_validate_property(self):
     sg_api.validate_property('foo', 'name', None)
     sg_api.validate_property('', 'name', None)
     self.assertRaises(exception.Invalid, sg_api.validate_property,
                       'a' * 256, 'name', None)
     self.assertRaises(exception.Invalid, sg_api.validate_property, None,
                       'name', None)
    def create(self, req, body):
        """Creates a new security group."""
        context = req.environ['nova.context']
        context.can(sg_policies.POLICY_NAME % 'create',
                    target={'project_id': context.project_id})

        security_group = self._from_body(body, 'security_group')

        group_name = security_group.get('name', None)
        group_description = security_group.get('description', None)

        try:
            security_group_api.validate_property(group_name, 'name', None)
            security_group_api.validate_property(group_description,
                                                 'description', None)
            group_ref = security_group_api.create_security_group(
                context, group_name, group_description)
        except exception.Invalid as exp:
            raise exc.HTTPBadRequest(explanation=exp.format_message())
        except exception.SecurityGroupLimitExceeded as exp:
            raise exc.HTTPForbidden(explanation=exp.format_message())

        return {
            'security_group': self._format_security_group(context, group_ref)
        }
Exemple #5
0
    def create(self, req, body):
        """Creates a new security group."""
        context = _authorize_context(req)

        security_group = self._from_body(body, 'security_group')

        group_name = security_group.get('name', None)
        group_description = security_group.get('description', None)

        try:
            security_group_api.validate_property(group_name, 'name', None)
            security_group_api.validate_property(group_description,
                                                      'description', None)
            group_ref = security_group_api.create_security_group(
                context, group_name, group_description)
        except exception.Invalid as exp:
            raise exc.HTTPBadRequest(explanation=exp.format_message())
        except exception.SecurityGroupLimitExceeded as exp:
            raise exc.HTTPForbidden(explanation=exp.format_message())

        return {'security_group': self._format_security_group(context,
                                                              group_ref)}