nm device: Delete connection profiles with no device

Devices that are dependent on other devices may be deleted implicitly,
leaving their profile inactive.
Such cases occur when an OVS bridge is removed, leaving its slaves
profiles detached from their device (OVS with an internal interface).

This patch introduces an option to delete a connection based on its ID.

Signed-off-by: Edward Haas <edwardh@redhat.com>
This commit is contained in:
Edward Haas 2019-02-18 16:53:37 +02:00
parent 7b98f20cb8
commit 476e729b5b
2 changed files with 17 additions and 3 deletions

View File

@ -294,9 +294,20 @@ def delete(dev):
mainloop.push_action(_safe_delete_async, dev)
def _safe_delete_async(dev):
# FIXME: Move the connection related functionality to the connection module.
def delete_connection(connection_id):
mainloop = nmclient.mainloop()
mainloop.push_action(
_safe_delete_async, dev=None, connection_id=connection_id)
def _safe_delete_async(dev, connection_id=None):
"""Removes all device profiles."""
connections = dev.get_available_connections()
if dev:
connections = dev.get_available_connections()
else:
conn = connection.get_connection_by_id(connection_id)
connections = [conn] if conn else []
mainloop = nmclient.mainloop()
if not connections:
# No callback is expected, so we should call the next one.

View File

@ -176,7 +176,10 @@ def _create_port_setting(port_state, port_profile_name):
def _delete_iface(devname):
nmdev = nm.device.get_device_by_name(devname)
with mainloop():
nm.device.delete(nmdev)
if nmdev:
nm.device.delete(nmdev)
else:
nm.device.delete_connection(devname)
def _get_iface_bridge_settings(bridge_options):