def test_unlimited_security_groups(self):
     self.flags(quota_security_groups=10)
     security_groups = quota.allowed_security_groups(self.context, 100)
     self.assertEqual(security_groups, 10)
     db.quota_create(self.context, self.project_id, 'security_groups', None)
     security_groups = quota.allowed_security_groups(self.context, 100)
     self.assertEqual(security_groups, 100)
     security_groups = quota.allowed_security_groups(self.context, 101)
     self.assertEqual(security_groups, 101)
Ejemplo n.º 2
0
 def test_unlimited_security_groups(self):
     self.flags(quota_security_groups=10)
     security_groups = quota.allowed_security_groups(self.context, 100)
     self.assertEqual(security_groups, 10)
     db.quota_create(self.context, self.project_id, 'security_groups', None)
     security_groups = quota.allowed_security_groups(self.context, 100)
     self.assertEqual(security_groups, 100)
     security_groups = quota.allowed_security_groups(self.context, 101)
     self.assertEqual(security_groups, 101)
Ejemplo n.º 3
0
    def create(self, req, body):
        """Creates a new security group."""
        context = req.environ['nova.context']
        authorize(context)
        if not body:
            raise exc.HTTPUnprocessableEntity()

        security_group = body.get('security_group', None)

        if security_group is None:
            raise exc.HTTPUnprocessableEntity()

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

        self._validate_security_group_property(group_name, "name")
        self._validate_security_group_property(group_description,
                                               "description")
        group_name = group_name.strip()
        group_description = group_description.strip()

        if quota.allowed_security_groups(context, 1) < 1:
            msg = _("Quota exceeded, too many security groups.")
            raise exc.HTTPBadRequest(explanation=msg)

        LOG.audit(_("Create Security Group %s"), group_name, context=context)
        self.compute_api.ensure_default_security_group(context)
        if db.security_group_exists(context, context.project_id, group_name):
            msg = _('Security group %s already exists') % group_name
            raise exc.HTTPBadRequest(explanation=msg)

        group = {
            'user_id': context.user_id,
            'project_id': context.project_id,
            'name': group_name,
            'description': group_description
        }
        group_ref = db.security_group_create(context, group)
        self.sgh.trigger_security_group_create_refresh(context, group)

        return {
            'security_group': self._format_security_group(context, group_ref)
        }
Ejemplo n.º 4
0
    def create(self, req, body):
        """Creates a new security group."""
        context = req.environ['nova.context']
        authorize(context)
        if not body:
            raise exc.HTTPUnprocessableEntity()

        security_group = body.get('security_group', None)

        if security_group is None:
            raise exc.HTTPUnprocessableEntity()

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

        self._validate_security_group_property(group_name, "name")
        self._validate_security_group_property(group_description,
                                               "description")
        group_name = group_name.strip()
        group_description = group_description.strip()

        if quota.allowed_security_groups(context, 1) < 1:
            msg = _("Quota exceeded, too many security groups.")
            raise exc.HTTPBadRequest(explanation=msg)

        LOG.audit(_("Create Security Group %s"), group_name, context=context)
        self.compute_api.ensure_default_security_group(context)
        if db.security_group_exists(context, context.project_id, group_name):
            msg = _('Security group %s already exists') % group_name
            raise exc.HTTPBadRequest(explanation=msg)

        group = {'user_id': context.user_id,
                 'project_id': context.project_id,
                 'name': group_name,
                 'description': group_description}
        group_ref = db.security_group_create(context, group)
        self.sgh.trigger_security_group_create_refresh(context, group)

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