Ejemplo n.º 1
0
    def delete(self, req, id):
        """Delete a security group."""
        context = req.environ['nova.context']
        authorize(context)
        security_group = self._get_security_group(context, id)
        if db.security_group_in_use(context, security_group.id):
            msg = _("Security group is still in use")
            raise exc.HTTPBadRequest(explanation=msg)

        # Get reservations
        try:
            reservations = QUOTAS.reserve(context, security_groups=-1)
        except Exception:
            reservations = None
            LOG.exception(
                _("Failed to update usages deallocating "
                  "security group"))

        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, security_group.id)
        self.sgh.trigger_security_group_destroy_refresh(
            context, security_group.id)

        # Commit the reservations
        if reservations:
            QUOTAS.commit(context, reservations)

        return webob.Response(status_int=202)
Ejemplo n.º 2
0
 def delete_security_group(self, context, group_name, **kwargs):
     LOG.audit(_("Delete security group %s"), group_name, context=context)
     security_group = db.security_group_get_by_name(context,
                                                    context.project_id,
                                                    group_name)
     db.security_group_destroy(context, security_group.id)
     return True
Ejemplo n.º 3
0
Archivo: cloud.py Proyecto: yosh/nova
 def delete_security_group(self, context, group_name, **kwargs):
     LOG.audit(_("Delete security group %s"), group_name, context=context)
     security_group = db.security_group_get_by_name(context,
                                                    context.project_id,
                                                    group_name)
     db.security_group_destroy(context, security_group.id)
     return True
Ejemplo n.º 4
0
    def delete(self, req, id):
        """Delete a security group."""
        context = req.environ['nova.context']
        authorize(context)
        security_group = self._get_security_group(context, id)
        if db.security_group_in_use(context, security_group.id):
            msg = _("Security group is still in use")
            raise exc.HTTPBadRequest(explanation=msg)

        # Get reservations
        try:
            reservations = QUOTAS.reserve(context, security_groups=-1)
        except Exception:
            reservations = None
            LOG.exception(_("Failed to update usages deallocating "
                            "security group"))

        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, security_group.id)
        self.sgh.trigger_security_group_destroy_refresh(
            context, security_group.id)

        # Commit the reservations
        if reservations:
            QUOTAS.commit(context, reservations)

        return webob.Response(status_int=202)
Ejemplo n.º 5
0
    def delete(self, req, id):
        """Delete a security group."""
        context = req.environ['nova.context']
        security_group = self._get_security_group(context, id)
        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, security_group.id)

        return exc.HTTPAccepted()
Ejemplo n.º 6
0
    def delete(self, req, id):
        """Delete a security group."""
        context = req.environ['nova.context']
        security_group = self._get_security_group(context, id)
        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, security_group.id)

        return exc.HTTPAccepted()
Ejemplo n.º 7
0
    def delete(self, req, id):
        """Delete a security group."""
        context = req.environ['nova.context']
        security_group = self._get_security_group(context, id)
        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, security_group.id)

        return webob.Response(status_int=202)
Ejemplo n.º 8
0
    def delete(self, req, id):
        context = req.environ['nova.context']
        self.compute_api.ensure_default_security_group(context)

        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, id)

        return exc.HTTPAccepted()
Ejemplo n.º 9
0
    def delete(self, req, id):
        """Delete a security group."""
        context = req.environ['nova.context']
        security_group = self._get_security_group(context, id)
        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, security_group.id)

        return webob.Response(status_int=202)
Ejemplo n.º 10
0
 def scrub(self, project_id):
     """Deletes data associated with project."""
     admin_context = context.get_admin_context()
     networks = db.project_get_networks(admin_context, project_id)
     for network in networks:
         db.network_disassociate(admin_context, network['id'])
     groups = db.security_group_get_by_project(admin_context, project_id)
     for group in groups:
         db.security_group_destroy(admin_context, group['id'])
Ejemplo n.º 11
0
def remove_group(group_id, context):
    """
    Remove a security group.

    group_id -- the group.
    context -- The os context.
    """
    # TODO: check exception handling!
    if db.security_group_in_use(context, group_id):
        raise AttributeError('Security group is still in use')

    db.security_group_destroy(context, group_id)
    SEC_HANDLER.trigger_security_group_destroy_refresh(
        context, group_id)
Ejemplo n.º 12
0
    def delete(self, req, id):
        """Delete a security group."""
        context = req.environ['nova.context']
        authorize(context)
        security_group = self._get_security_group(context, id)
        if db.security_group_in_use(context, security_group.id):
            msg = _("Security group is still in use")
            raise exc.HTTPBadRequest(explanation=msg)
        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, security_group.id)
        self.sgh.trigger_security_group_destroy_refresh(
            context, security_group.id)

        return webob.Response(status_int=202)
Ejemplo n.º 13
0
    def delete(self, req, id):
        """Delete a security group."""
        context = req.environ['nova.context']
        authorize(context)
        security_group = self._get_security_group(context, id)
        if db.security_group_in_use(context, security_group.id):
            msg = _("Security group is still in use")
            raise exc.HTTPBadRequest(explanation=msg)
        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, security_group.id)
        self.sgh.trigger_security_group_destroy_refresh(
            context, security_group.id)

        return webob.Response(status_int=202)
Ejemplo n.º 14
0
 def test_describe_security_groups(self):
     """Makes sure describe_security_groups works and filters results."""
     sec = db.security_group_create(self.context, {
         'project_id': self.context.project_id,
         'name': 'test'
     })
     result = self.cloud.describe_security_groups(self.context)
     # NOTE(vish): should have the default group as well
     self.assertEqual(len(result['securityGroupInfo']), 2)
     result = self.cloud.describe_security_groups(self.context,
                                                  group_name=[sec['name']])
     self.assertEqual(len(result['securityGroupInfo']), 1)
     self.assertEqual(result['securityGroupInfo'][0]['groupName'],
                      sec['name'])
     db.security_group_destroy(self.context, sec['id'])
Ejemplo n.º 15
0
    def test_destroy_instance_disassociates_security_groups(self):
        """Make sure destroying disassociates security groups"""
        group = self._create_group()

        ref = self.compute_api.create(
            self.context,
            instance_type=instance_types.get_default_instance_type(),
            image_href=None,
            security_group=['testgroup'])
        try:
            db.instance_destroy(self.context, ref[0]['id'])
            group = db.security_group_get(self.context, group['id'])
            self.assert_(len(group.instances) == 0)
        finally:
            db.security_group_destroy(self.context, group['id'])
Ejemplo n.º 16
0
    def test_destroy_instance_disassociates_security_groups(self):
        """Make sure destroying disassociates security groups"""
        group = self._create_group()

        ref = self.compute_api.create(
                self.context,
                instance_type=instance_types.get_default_instance_type(),
                image_href=None,
                security_group=['testgroup'])
        try:
            db.instance_destroy(self.context, ref[0]['id'])
            group = db.security_group_get(self.context, group['id'])
            self.assert_(len(group.instances) == 0)
        finally:
            db.security_group_destroy(self.context, group['id'])
Ejemplo n.º 17
0
 def test_describe_security_groups(self):
     """Makes sure describe_security_groups works and filters results."""
     sec = db.security_group_create(self.context,
                                    {'project_id': self.context.project_id,
                                     'name': 'test'})
     result = self.cloud.describe_security_groups(self.context)
     # NOTE(vish): should have the default group as well
     self.assertEqual(len(result['securityGroupInfo']), 2)
     result = self.cloud.describe_security_groups(self.context,
                   group_name=[sec['name']])
     self.assertEqual(len(result['securityGroupInfo']), 1)
     self.assertEqual(
             result['securityGroupInfo'][0]['groupName'],
             sec['name'])
     db.security_group_destroy(self.context, sec['id'])
Ejemplo n.º 18
0
 def test_create_instance_associates_security_groups(self):
     """Make sure create associates security groups"""
     group = self._create_group()
     ref = self.compute_api.create(
             self.context,
             instance_type=FLAGS.default_instance_type,
             image_id=None,
             security_group=['testgroup'])
     try:
         self.assertEqual(len(db.security_group_get_by_instance(
                          self.context, ref[0]['id'])), 1)
         group = db.security_group_get(self.context, group['id'])
         self.assert_(len(group.instances) == 1)
     finally:
         db.security_group_destroy(self.context, group['id'])
         db.instance_destroy(self.context, ref[0]['id'])
Ejemplo n.º 19
0
    def delete(self, req, id):
        """Delete a security group."""
        context = req.environ['nova.context']
        try:
            id = int(id)
            security_group = db.security_group_get(context, id)
        except ValueError:
            msg = _("Security group id is not integer")
            return exc.HTTPBadRequest(explanation=msg)
        except exception.SecurityGroupNotFound as exp:
            return exc.HTTPNotFound(explanation=unicode(exp))

        LOG.audit(_("Delete security group %s"), id, context=context)
        db.security_group_destroy(context, security_group.id)

        return exc.HTTPAccepted()
Ejemplo n.º 20
0
def remove_group(group_id, context):
    """
    Remove a security group.

    group_id -- the group.
    context -- The os context.
    """
    try:
        #if db.security_group_in_use(context, group_id):
        #    raise AttributeError('Security group is still in use')

        db.security_group_destroy(context, group_id)
        SEC_HANDLER.trigger_security_group_destroy_refresh(
            context, group_id)

    except Exception as error:
        raise AttributeError(error)
Ejemplo n.º 21
0
    def test_destroy_security_group_disassociates_instances(self):
        """Make sure destroying security groups disassociates instances"""
        group = self._create_group()

        ref = self.compute_api.create(
                self.context,
                instance_type=FLAGS.default_instance_type,
                image_id=None,
                security_group=['testgroup'])

        try:
            db.security_group_destroy(self.context, group['id'])
            group = db.security_group_get(context.get_admin_context(
                                          read_deleted=True), group['id'])
            self.assert_(len(group.instances) == 0)
        finally:
            db.instance_destroy(self.context, ref[0]['id'])