Пример #1
0
    def _validate_port_can_commit(self, res_port, req_port, session=None):
        """Poorly named function that determines if a port can actually
        be configured given the state of the system. (ex. do not allow a
        non-trunked port to be committed to a running trunked config.)
        """
        switchport_ids = [p["id"] for p in res_port["switch:ports"]]

        if not switchport_ids:
            msg = ("Cannot attach, no switchports found")
            raise exc.InvalidInput(error_message=msg)

        bound_port_ids = []
        if switchport_ids:
            # Fetch all existing networks we are attached to.
            portbindings = db.filter_switchport_bindings_by_switch_port_ids(
                switchport_ids, session=session)
            portbindings = list(portbindings)
            bound_port_ids = set([pb.port_id for pb in portbindings])

        # We can't attach to a non-trunked network if the port is already
        # attached to another network.
        if bound_port_ids and (res_port["trunked"] is False):
            msg = ("Cannot attach non-trunked network, port "
                   "already bound to network(s) %s" % (bound_port_ids))
            raise exc.InvalidInput(error_message=msg)

        for bound_port_id in bound_port_ids:
            # We can't attach a trunked network if we are already attached
            # to a non-trunked network.
            port_ext = db.get_port_ext(bound_port_id, session=session)
            if not port_ext.trunked:
                msg = ("Already attached via non-trunked "
                       "port %s" % (bound_port_id))
                raise exc.InvalidInput(error_message=msg)
Пример #2
0
    def _validate_port_can_commit(self, res_port, req_port,
                                  session=None):
        """Poorly named function that determines if a port can actually
        be configured given the state of the system. (ex. do not allow a
        non-trunked port to be committed to a running trunked config.)
        """
        switchport_ids = [p["id"] for p in res_port["switch:ports"]]

        if not switchport_ids:
            msg = ("Cannot attach, no switchports found")
            raise exc.InvalidInput(error_message=msg)

        bound_port_ids = []
        if switchport_ids:
            # Fetch all existing networks we are attached to.
            portbindings = db.filter_switchport_bindings_by_switch_port_ids(
                switchport_ids, session=session)
            portbindings = list(portbindings)
            bound_port_ids = set([pb.port_id for pb in portbindings])

        # We can't attach to a non-trunked network if the port is already
        # attached to another network.
        if bound_port_ids and (res_port["trunked"] is False):
            msg = ("Cannot attach non-trunked network, port "
                   "already bound to network(s) %s" % (bound_port_ids))
            raise exc.InvalidInput(error_message=msg)

        for bound_port_id in bound_port_ids:
            # We can't attach a trunked network if we are already attached
            # to a non-trunked network.
            port_ext = db.get_port_ext(bound_port_id, session=session)
            if not port_ext.trunked:
                msg = ("Already attached via non-trunked "
                       "port %s" % (bound_port_id))
                raise exc.InvalidInput(error_message=msg)
Пример #3
0
    def delete_switchports(cls, hardware_id, switchports=None, session=None):
        if not session:
            session = db_api.get_session()

        # find portmaps and check if they are in-use before deleting.
        with session.begin(subtransactions=True):

            if not switchports:
                switchports = list(db.filter_switchports(
                    hardware_id=hardware_id, session=session))

            switchport_ids = [sp.id for sp in switchports]
            if switchport_ids:
                bindings = db.filter_switchport_bindings_by_switch_port_ids(
                    switchport_ids, session=session)
                bindings = list(bindings)
                if bindings:
                    raise exc.BadRequest(
                        resource="switchport",
                        reason=("Cannot delete, switchport(s) "
                                "'%s' in use" % (','.join(switchport_ids)))
                    )
            return db.delete_switchports(switchport_ids, session=session)
Пример #4
0
    def delete_switchports(cls, hardware_id, switchports=None, session=None):
        if not session:
            session = db_api.get_session()

        # find portmaps and check if they are in-use before deleting.
        with session.begin(subtransactions=True):

            if not switchports:
                switchports = list(
                    db.filter_switchports(hardware_id=hardware_id,
                                          session=session))

            switchport_ids = [sp.id for sp in switchports]
            if switchport_ids:
                bindings = db.filter_switchport_bindings_by_switch_port_ids(
                    switchport_ids, session=session)
                bindings = list(bindings)
                if bindings:
                    raise exc.BadRequest(
                        resource="switchport",
                        reason=("Cannot delete, switchport(s) "
                                "'%s' in use" % (','.join(switchport_ids))))
            return db.delete_switchports(switchport_ids, session=session)