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)
        }
Beispiel #2
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)}