Ejemplo n.º 1
0
 def test_in_use(self):
     self.mox.StubOutWithMock(db, 'security_group_in_use')
     db.security_group_in_use(self.context, 123).AndReturn(True)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup(context=self.context)
     secgroup.id = 123
     self.assertTrue(secgroup.in_use())
 def test_in_use(self):
     self.mox.StubOutWithMock(db, 'security_group_in_use')
     db.security_group_in_use(self.context, 123).AndReturn(True)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup(context=self.context)
     secgroup.id = 123
     self.assertTrue(secgroup.in_use())
 def test_in_use(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'security_group_in_use')
     db.security_group_in_use(ctxt, 123).AndReturn(True)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup()
     secgroup.id = 123
     self.assertTrue(secgroup.in_use(ctxt))
     self.assertRemotes()
Ejemplo n.º 4
0
 def test_in_use(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'security_group_in_use')
     db.security_group_in_use(ctxt, 123).AndReturn(True)
     self.mox.ReplayAll()
     secgroup = security_group.SecurityGroup()
     secgroup.id = 123
     self.assertTrue(secgroup.in_use(ctxt))
     self.assertRemotes()
Ejemplo n.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
0
 def in_use(self, context):
     return db.security_group_in_use(context, self.id)
Ejemplo n.º 11
0
 def in_use(self):
     return db.security_group_in_use(self._context, self.id)