11#!/usr/bin/env python
22# SPDX-License-Identifier: LGPL-2.1-or-later
33#
4- # Update a property of a connection profile, looked up by connection id
5- #
6- # The IPv4 settings of connections profiles are documented here:
7- # https://networkmanager.dev/docs/api/latest/settings-ipv4.html
4+ # Create and delete a connection profile using the unique connection uuid
85#
96import logging
107import sdbus
118from uuid import uuid4
129from argparse import Namespace
1310from sdbus_block .networkmanager import NetworkManagerSettings
14- from sdbus_block .networkmanager import NetworkConnectionSettings
11+ from sdbus_block .networkmanager import NmSettingsInvalidConnectionError
1512
1613
1714def delete_connection_by_uuid (uuid : str ) -> bool :
1815 """Find and delete the connection identified by the given UUID"""
19- settings_manager = NetworkManagerSettings ()
20- connection_path = settings_manager . get_connection_by_uuid (uuid )
21- if not connection_path :
16+ try :
17+ NetworkManagerSettings (). delete_connection_by_uuid (uuid )
18+ except NmSettingsInvalidConnectionError :
2219 logging .getLogger ().fatal (f"Connection { uuid } for deletion not found" )
2320 return False
24- connection_settings = NetworkConnectionSettings (connection_path )
25- connection_settings .delete ()
2621 return True
2722
2823
29- def create_and_delete_wifi_psk_connection_ (args : Namespace ) -> bool :
24+ def create_and_delete_wifi_psk_connection_async (args : Namespace ) -> bool :
3025 """Add a temporary (not yet saved) network connection profile
3126 :param Namespace args: autoconnect, conn_id, psk, save, ssid, uuid
3227 :return: dbus connection path of the created connection profile
@@ -41,5 +36,5 @@ def create_and_delete_wifi_psk_connection_(args: Namespace) -> bool:
4136 logging .basicConfig (format = "%(message)s" , level = logging .WARNING )
4237 sdbus .set_default_bus (sdbus .sd_bus_open_system ())
4338 args = Namespace (conn_id = "Example" , uuid = uuid4 (), ssid = "S" , psk = "Password" )
44- if create_and_delete_wifi_psk_connection_ (args ):
39+ if create_and_delete_wifi_psk_connection_async (args ):
4540 print (f"Succeeded in creating and deleting connection { args .uuid } " )
0 commit comments