nm, ovs: Learn the ovs bridge ports and ifaces from NM

OVS ports and interfaces have been interpreted by parsing the current
state instead of fetching it from the NM device.
Now that the `get_slaves` function is available (from NM 1.14), the
parsing and the hard-coded port name prefix assumptions are no longer
needed.

Note: The hard-coded prefix of the ovs ports names limited changes to
their name format in the future. The current change allows future
changes to the port names, keeping backward compatibility.

Signed-off-by: Edward Haas <edwardh@redhat.com>
This commit is contained in:
Edward Haas 2020-01-26 17:29:48 +02:00
parent 40e271d982
commit 32924333cf
2 changed files with 9 additions and 23 deletions

View File

@ -265,7 +265,11 @@ def _get_affected_devices(iface_state):
devs += [nmdev]
iface_type = iface_state[Interface.TYPE]
if iface_type == ovs.BRIDGE_TYPE:
devs += _get_ovs_bridge_port_devices(iface_state)
port_slaves = ovs.get_slaves(nmdev)
iface_slaves = [
iface for port in port_slaves for iface in ovs.get_slaves(port)
]
devs += port_slaves + iface_slaves
elif iface_type == LB.TYPE:
devs += bridge.get_slaves(nmdev)
elif iface_type == bond.BOND_TYPE:
@ -273,28 +277,6 @@ def _get_affected_devices(iface_state):
return devs
def _get_ovs_bridge_port_devices(iface_state):
"""
Report a list of all ovs ports and interfaces that are connected to the
OVS bridge.
Note: Ports must be activated before the ifaces (NM limitation).
"""
ifaces = [
p[Interface.NAME]
for p in iface_state.get(OvsB.CONFIG_SUBTREE, {}).get(
OvsB.PORT_SUBTREE, []
)
]
ports = [ovs.PORT_PROFILE_PREFIX + iface for iface in ifaces]
devnames = ports + ifaces
nmdevs = []
for devname in devnames:
dev = device.get_device_by_name(devname)
if dev:
nmdevs.append(dev)
return nmdevs
def prepare_proxy_ifaces_desired_state(ifaces_desired_state):
"""
Prepare the state of the "proxy" interfaces. These are interfaces that

View File

@ -154,6 +154,10 @@ def get_ovs_info(bridge_device, devices_info):
return {}
def get_slaves(nm_device):
return nm_device.get_slaves()
def _get_bridge_ports_info(port_profiles, devices_info):
ports_info = []
for p in port_profiles: