Ejemplo n.º 1
0
    def delete(self, perform_checks=True):
        if perform_checks:
            if self.has_adresses_in_use():
                raise SubnetError(
                    "Subnet '%s/%s' cannot be deleted; it has addresses in use" %
                    (self.subnet_ip, self.subnet_mask))

        # Revoke BofhdAuthRoles associated with subnet
        baot = BofhdAuthOpTarget(self._db)
        bar = BofhdAuthRole(self._db)
        targets = [x['op_target_id'] for x in
                   baot.list(entity_id=self.entity_id)]
        if targets:
            for target in targets:
                for x in bar.list(op_target_id=target):
                    bar.revoke_auth(*x)
            bar.commit()

        # Remove BofhdAuthOpTarget associated with subnet
        for x in targets:
            baot.clear()
            try:
                baot.find(x)
                baot.delete()
                baot.commit()
            except NotFoundError:
                pass

        self._db.log_change(self.entity_id, self.const.subnet_delete, None)
        if self.__in_db:
            self.execute("""
            DELETE FROM [:table schema=cerebrum name=dns_subnet]
            WHERE entity_id=:e_id""", {'e_id': self.entity_id})
        self.__super.delete()
Ejemplo n.º 2
0
def remove_target_permissions(entity_id, db):
    """Remove all permissions (group owner/moderator) GIVEN TO entity_id.

    FIXME: what if entity_id is a group owner? If we yank it, the group
    remains ownerless.

    Cf bofhd_virthome_cmds.py:__remove_auth_role.
    """
    ar = BofhdAuthRole(db)
    aot = BofhdAuthOpTarget(db)
    for r in ar.list(entity_id):
        ar.revoke_auth(entity_id, r['op_set_id'], r['op_target_id'])
        # Also remove targets if this was the last reference from
        # auth_role.
        remaining = ar.list(op_target_id=r['op_target_id'])
        if len(remaining) == 0:
            aot.clear()
            aot.find(r['op_target_id'])
            aot.delete()
Ejemplo n.º 3
0
def remove_target_permissions(entity_id, db):
    """Remove all permissions (group owner/moderator) GIVEN TO entity_id.

    FIXME: what if entity_id is a group owner? If we yank it, the group
    remains ownerless.

    Cf bofhd_virthome_cmds.py:__remove_auth_role.
    """
    ar = BofhdAuthRole(db)
    aot = BofhdAuthOpTarget(db)
    for r in ar.list(entity_id):
        ar.revoke_auth(entity_id, r['op_set_id'], r['op_target_id'])
        # Also remove targets if this was the last reference from
        # auth_role.
        remaining = ar.list(op_target_id=r['op_target_id'])
        if len(remaining) == 0:
            aot.clear()
            aot.find(r['op_target_id'])
            aot.delete()
Ejemplo n.º 4
0
def remove_permissions_on_target(entity_id, db):
    """Remove all permissions GRANTED ON entity_id.

    remote_target_permissions() removes permissions held by entity_id. This
    function removes permissions held by other on entity_id.

    Cf bofhd_virthome_cmds.py:__remove_auth_target.
    """

    ar = BofhdAuthRole(db)
    aot = BofhdAuthOpTarget(db)
    for r in aot.list(entity_id=entity_id):
        aot.clear()
        aot.find(r['op_target_id'])
        # We remove all auth_role entries pointing to this entity_id
        # first.
        for role in ar.list(op_target_id=r["op_target_id"]):
            ar.revoke_auth(role['entity_id'], role['op_set_id'],
                           r['op_target_id'])
        aot.delete()
Ejemplo n.º 5
0
def remove_permissions_on_target(entity_id, db):
    """Remove all permissions GRANTED ON entity_id.

    remote_target_permissions() removes permissions held by entity_id. This
    function removes permissions held by other on entity_id.

    Cf bofhd_virthome_cmds.py:__remove_auth_target.
    """

    ar = BofhdAuthRole(db)
    aot = BofhdAuthOpTarget(db)
    for r in aot.list(entity_id=entity_id):
        aot.clear()
        aot.find(r['op_target_id'])
        # We remove all auth_role entries pointing to this entity_id
        # first.
        for role in ar.list(op_target_id=r["op_target_id"]):
            ar.revoke_auth(role['entity_id'], role['op_set_id'],
                           r['op_target_id'])
        aot.delete()
Ejemplo n.º 6
0
    def remove_auth_roles(self, entity_id):
        """ This method will remove all authorization roles that has been given
        to an entity. It will also remove any remaining authorization targets
        that no longer have auth roles pointing to it as a result.

        @type entity_id: int
        @param entity_id: The entity_id of an object.
        """
        ar = BofhdAuthRole(self.db)
        aot = BofhdAuthOpTarget(self.db)

        # Remove all auth-roles the entity have over other targets
        for target in ar.list(entity_ids=entity_id):
            ar.revoke_auth(entity_id, target['op_set_id'], target['op_target_id'])

            # Remove auth-target if there aren't any more auth-roles pointing
            # to it
            remaining = ar.list(op_target_id=target['op_target_id'])
            if len(remaining) == 0:
                aot.clear()
                aot.find(target['op_target_id'])
                aot.delete()
Ejemplo n.º 7
0
    def remove_auth_roles(self, entity_id):
        """ This method will remove all authorization roles that has been given
        to an entity. It will also remove any remaining authorization targets
        that no longer have auth roles pointing to it as a result.

        @type entity_id: int
        @param entity_id: The entity_id of an object.
        """
        ar = BofhdAuthRole(self.db)
        aot = BofhdAuthOpTarget(self.db)

        # Remove all auth-roles the entity have over other targets
        for target in ar.list(entity_ids=entity_id):
            ar.revoke_auth(entity_id, target['op_set_id'], target['op_target_id'])

            # Remove auth-target if there aren't any more auth-roles pointing
            # to it
            remaining = ar.list(op_target_id=target['op_target_id'])
            if len(remaining) == 0:
                aot.clear()
                aot.find(target['op_target_id'])
                aot.delete()
Ejemplo n.º 8
0
    def remove_auth_targets(self, entity_id, target_type=None):
        """ This method will remove authorization targets of type
        L{target_type} that points to the L{entity_id}. If L{target_type} is
        None, all targets regardless of type will be removed.

        @type entity_id: int
        @param entity_id: The entity_id of an object.

        @type target_type: str
        @param target_type: The target type of the authorization target
        """
        ar = BofhdAuthRole(self.db)
        aot = BofhdAuthOpTarget(self.db)

        for target in aot.list(entity_id=entity_id, target_type=target_type):
            aot.clear()
            aot.find(target['op_target_id'])

            # Before the target is removed, we must remove all roles that
            # grants access to the target.
            for role in ar.list(op_target_id=target["op_target_id"]):
                ar.revoke_auth(role['entity_id'], role['op_set_id'],
                               target['op_target_id'])
            aot.delete()
Ejemplo n.º 9
0
    def remove_auth_targets(self, entity_id, target_type=None):
        """ This method will remove authorization targets of type
        L{target_type} that points to the L{entity_id}. If L{target_type} is
        None, all targets regardless of type will be removed.

        @type entity_id: int
        @param entity_id: The entity_id of an object.

        @type target_type: str
        @param target_type: The target type of the authorization target
        """
        ar = BofhdAuthRole(self.db)
        aot = BofhdAuthOpTarget(self.db)

        for target in aot.list(entity_id=entity_id, target_type=target_type):
            aot.clear()
            aot.find(target['op_target_id'])

            # Before the target is removed, we must remove all roles that
            # grants access to the target.
            for role in ar.list(op_target_id=target["op_target_id"]):
                ar.revoke_auth(role['entity_id'], role['op_set_id'],
                               target['op_target_id'])
            aot.delete()