예제 #1
0
    def delete(self, req, id):
        context = req.environ['nova.context']

        self.compute_api.ensure_default_security_group(context)
        try:
            id = int(id)
            rule = db.security_group_rule_get(context, id)
        except ValueError:
            msg = _("Rule id is not integer")
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as exp:
            msg = _("Rule (%s) not found") % id
            raise exc.HTTPNotFound(explanation=msg)

        group_id = rule.parent_group_id
        self.compute_api.ensure_default_security_group(context)
        security_group = db.security_group_get(context, group_id)

        msg = _("Revoke security group ingress %s")
        LOG.audit(msg, security_group['name'], context=context)

        db.security_group_rule_destroy(context, rule['id'])
        self.compute_api.trigger_security_group_rules_refresh(context,
                                    security_group_id=security_group['id'])

        return webob.Response(status_int=202)
예제 #2
0
    def delete(self, req, id):
        context = req.environ['nova.context']
        authorize(context)

        self.compute_api.ensure_default_security_group(context)
        try:
            id = int(id)
            rule = db.security_group_rule_get(context, id)
        except ValueError:
            msg = _("Rule id is not integer")
            raise exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound:
            msg = _("Rule (%s) not found") % id
            raise exc.HTTPNotFound(explanation=msg)

        group_id = rule.parent_group_id
        self.compute_api.ensure_default_security_group(context)
        security_group = db.security_group_get(context, group_id)

        msg = _("Revoke security group ingress %s")
        LOG.audit(msg, security_group['name'], context=context)

        db.security_group_rule_destroy(context, rule['id'])
        self.sgh.trigger_security_group_rule_destroy_refresh(
            context, [rule['id']])
        self.compute_api.trigger_security_group_rules_refresh(context,
                                    security_group_id=security_group['id'])

        return webob.Response(status_int=202)
예제 #3
0
def retrieve_rule(uid, context):
    """
    Retrieve a rule.

    uid -- Id of the rule (entity.attributes['occi.core.id'])
    context -- The os context.
    """
    try:
        return db.security_group_rule_get(context,
                                          int(uid))
    except Exception:
        raise exceptions.HTTPError(404, 'Rule not found!')
예제 #4
0
    def trigger_security_group_rule_create_refresh(self, context, rule_ids):
        LOG.debug('rule_ids=%r', rule_ids)
        ctxt = context.elevated()
        tenant_id = context.to_dict()['project_id']

        for rule_id in rule_ids:
            rule = db.security_group_rule_get(ctxt, rule_id)

            group = db.security_group_get(ctxt, rule['parent_group_id'])
            sg_id = rule['parent_group_id']
            sg_name = group['name']

            self.rule_manager.create_for_sg(tenant_id, sg_id, sg_name, rule)
 def get_by_id(cls, context, rule_id):
     db_rule = db.security_group_rule_get(context, rule_id)
     return cls._from_db_object(context, cls(), db_rule)
예제 #6
0
 def get_by_id(cls, context, rule_id):
     db_rule = db.security_group_rule_get(context, rule_id)
     return cls._from_db_object(context, cls(), db_rule)