示例#1
0
    def _update_port(self, network_id, dpid, port, port_may_exist):
        def _known_nw_id(nw_id):
            return nw_id is not None and nw_id != self.nw_id_unknown

        self._check_nw_id_unknown(network_id)
        try:
            old_network_id = self.dpids.get(dpid, {}).get(port, None)
            if ((dpid, port) in self.networks[network_id]
                    or _known_nw_id(old_network_id)):
                if not port_may_exist:
                    raise PortAlreadyExist(network_id=network_id,
                                           dpid=dpid,
                                           port=port)

            if old_network_id != network_id:
                self.networks[network_id].add((dpid, port))
                if _known_nw_id(old_network_id):
                    self.networks[old_network_id].remove((dpid, port))
        except KeyError:
            raise NetworkNotFound(network_id=network_id)

        self._dpids_setdefault(dpid)
        self.dpids[dpid][port] = network_id
示例#2
0
文件: network.py 项目: yamahata/ryu
 def remove_network(self, network_id):
     try:
         del (self.networks[network_id])
     except KeyError:
         raise NetworkNotFound(network_id=network_id)