('options', {'peer': remote_name})]
return self.add_port(local_name, *attrs)
+ def get_iface_name_list(self):
+ # get the interface name list for this bridge
+ return self.ovsdb.list_ifaces(self.br_name).execute(check_error=True)
+
def get_port_name_list(self):
+ # get the port name list for this bridge
return self.ovsdb.list_ports(self.br_name).execute(check_error=True)
def get_port_stats(self, port_name):
@abc.abstractmethod
def list_ports(self, bridge):
- """Create a command to list the names of porsts on a bridge
+ """Create a command to list the names of ports on a bridge
:param bridge: The name of the bridge
:type bridge: string
:returns: :class:`Command` with list of port names result
"""
+ @abc.abstractmethod
+ def list_ifaces(self, bridge):
+ """Create a command to list the names of interfaces on a bridge
+
+ :param bridge: The name of the bridge
+ :type bridge: string
+ :returns: :class:`Command` with list of interfaces names result
+ """
+
def val_to_py(val):
"""Convert a json ovsdb return value to native python object"""
return cmd.PortToBridgeCommand(self, name)
def iface_to_br(self, name):
- # For our purposes, ports and interfaces always have the same name
- return cmd.PortToBridgeCommand(self, name)
+ return cmd.InterfaceToBridgeCommand(self, name)
def list_br(self):
return cmd.ListBridgesCommand(self)
def list_ports(self, bridge):
return cmd.ListPortsCommand(self, bridge)
+
+ def list_ifaces(self, bridge):
+ return cmd.ListIfacesCommand(self, bridge)
def list_ports(self, bridge):
return MultiLineCommand(self.context, 'list-ports', args=[bridge])
+ def list_ifaces(self, bridge):
+ return MultiLineCommand(self.context, 'list-ifaces', args=[bridge])
+
def _set_colval_args(*col_values):
args = []
self.result = [p.name for p in br.ports if p.name != self.bridge]
+class ListIfacesCommand(BaseCommand):
+ def __init__(self, api, bridge):
+ super(ListIfacesCommand, self).__init__(api)
+ self.bridge = bridge
+
+ def run_idl(self, txn):
+ br = idlutils.row_by_value(self.api.idl, 'Bridge', 'name', self.bridge)
+ self.result = [i.name for p in br.ports if p.name != self.bridge
+ for i in p.interfaces]
+
+
class PortToBridgeCommand(BaseCommand):
def __init__(self, api, name):
super(PortToBridgeCommand, self).__init__(api)
def run_idl(self, txn):
# TODO(twilson) This is expensive!
# This traversal of all ports could be eliminated by caching the bridge
- # name on the Port's (or Interface's for iface_to_br) external_id field
+ # name on the Port's external_id field
# In fact, if we did that, the only place that uses to_br functions
# could just add the external_id field to the conditions passed to find
port = idlutils.row_by_value(self.api.idl, 'Port', 'name', self.name)
self.result = next(br.name for br in bridges if port in br.ports)
+class InterfaceToBridgeCommand(BaseCommand):
+ def __init__(self, api, name):
+ super(InterfaceToBridgeCommand, self).__init__(api)
+ self.name = name
+
+ def run_idl(self, txn):
+ interface = idlutils.row_by_value(self.api.idl, 'Interface', 'name',
+ self.name)
+ ports = self.api._tables['Port'].rows.values()
+ pname = next(
+ port for port in ports if interface in port.interfaces)
+
+ bridges = self.api._tables['Bridge'].rows.values()
+ self.result = next(br.name for br in bridges if pname in br.ports)
+
+
class DbListCommand(BaseCommand):
def __init__(self, api, table, records, columns, if_exists):
super(DbListCommand, self).__init__(api)
ports = {self.create_ovs_port()[0] for i in range(5)}
self.assertSetEqual(ports, set(self.br.get_port_name_list()))
+ def test_get_iface_name_list(self):
+ ifaces = {self.create_ovs_port()[0] for i in range(5)}
+ self.assertSetEqual(ifaces, set(self.br.get_iface_name_list()))
+
def test_get_port_stats(self):
# Nothing seems to use this function?
(port_name, ofport) = self.create_ovs_port()