Skip to content

Commit 7dd4a75

Browse files
author
Bernhard Kaindl
committed
networkmanager/objects.py: Syncronice new helpers from async to block
Add missing helper methods from sdbus_async/networkmanager: - get_settings_by_uuid(): - Net a nested settings dict of a connection profile - delete_connection_by_uuid(): Delete a profile identified by the uuid - connection_profile(): Get a ConnectionProfile object containing all settings
1 parent ab3de2b commit 7dd4a75

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

sdbus_block/networkmanager/objects.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
NetworkManagerVPNConnectionInterface,
6868
NetworkManagerWifiP2PPeerInterface,
6969
)
70+
from .settings.profile import ConnectionProfile
71+
from .types import NetworkManagerConnectionProperties
7072

7173
NETWORK_MANAGER_SERVICE_NAME = 'org.freedesktop.NetworkManager'
7274

@@ -158,7 +160,7 @@ def get_connections_by_id(self, connection_id: str) -> List[str]:
158160
which use the given connection identifier.
159161
160162
:param str connection_id: The connection identifier of the connections,
161-
e.g. "Ethernet connection 1"
163+
e.g. "Wired connection 1"
162164
:return: List of connection profile paths using the given identifier.
163165
"""
164166
connection_paths_with_matching_id = []
@@ -169,6 +171,25 @@ def get_connections_by_id(self, connection_id: str) -> List[str]:
169171
connection_paths_with_matching_id.append(connection_path)
170172
return connection_paths_with_matching_id
171173

174+
def get_settings_by_uuid(
175+
self, connection_uuid: str
176+
) -> NetworkManagerConnectionProperties:
177+
"""Helper to get a nested settings dict of a connection profile by uuid.
178+
179+
:param str connection_uuid: The connection uuid of the connection profile
180+
:return: Nested dictionary of all settings of the given connection profile
181+
"""
182+
connection = self.get_connection_by_uuid(connection_uuid)
183+
return NetworkConnectionSettings(connection).get_settings()
184+
185+
def delete_connection_by_uuid(self, connection_uuid: str) -> None:
186+
"""Helper to delete a connection profile identified by the connection uuid.
187+
188+
:param str connection_uuid: The connection uuid of the connection profile
189+
"""
190+
conn_dbus_path = self.get_connection_by_uuid(connection_uuid)
191+
NetworkConnectionSettings(conn_dbus_path).delete()
192+
172193

173194
class NetworkConnectionSettings(
174195
NetworkManagerSettingsConnectionInterface):
@@ -192,6 +213,13 @@ def __init__(self, settings_path: str,
192213
settings_path,
193214
bus)
194215

216+
def connection_profile(self) -> ConnectionProfile:
217+
"""Return a ConnectionProfile object containing all profile settings
218+
219+
:return: Nested dataclass containing all settings of the profile
220+
"""
221+
return ConnectionProfile.from_dbus(self.get_settings())
222+
195223

196224
class NetworkDeviceGeneric(
197225
NetworkManagerDeviceInterface,

0 commit comments

Comments
 (0)