Exemple #1
0
    def _find_port_dict_extensions(self,
                                   port_res,
                                   port_db,
                                   port_ext=None,
                                   switchports=None,
                                   session=None):
        """Looks up extension data and updates port_res."""
        if not port_ext:
            port_ext = db.get_port_ext(port_res["id"], session=session)
            if not port_ext:
                LOG.error("Port %s does not have extension data" %
                          port_db["id"])
                return
            port_ext = port_ext.as_dict()

        if not switchports:
            switchports = []
            if port_ext["hardware_id"]:
                switchports = db.filter_switchports(
                    hardware_id=port_ext["hardware_id"], session=session)
            switchports = [sp.as_dict() for sp in switchports]

        port_res["switch:ports"] = switchports
        port_res["switch:hardware_id"] = port_ext["hardware_id"]
        port_res["commit"] = port_ext["commit"]
        port_res["trunked"] = port_ext["trunked"]
    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)
Exemple #3
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)
    def _find_port_dict_extensions(self, port_res, port_db, port_ext=None,
                                   switchports=None, session=None):
        """Looks up extension data and updates port_res."""
        if not port_ext:
            port_ext = db.get_port_ext(port_res["id"], session=session)
            port_ext = port_ext.as_dict()

        if not switchports:
            switchports = []
            if port_ext["hardware_id"]:
                switchports = db.filter_switchports(
                    hardware_id=port_ext["hardware_id"], session=session)
            switchports = [sp.as_dict() for sp in switchports]

        port_res["switch:ports"] = switchports
        port_res["switch:hardware_id"] = port_ext["hardware_id"]
        port_res["commit"] = port_ext["commit"]
        port_res["trunked"] = port_ext["trunked"]