Skip to content

Commit 46e7366

Browse files
Bernhard Kaindligo95862
authored andcommitted
Add enums.ConnectionType as basic class (no enum)
1 parent acca54c commit 46e7366

File tree

5 files changed

+69
-17
lines changed

5 files changed

+69
-17
lines changed

examples/async/add-wifi-psk-connection-async.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@
4646
import asyncio
4747
import binascii
4848
import functools
49-
import pprint
5049
import sdbus
5150
import uuid
5251
from argparse import ArgumentParser, Namespace
5352
from passlib.utils.pbkdf2 import pbkdf2 # type: ignore
53+
from pprint import pprint
5454
from sdbus_async.networkmanager import (
5555
NetworkManagerSettings as SettingsManager,
5656
ConnectionProfile,
5757
ConnectionSettings,
58+
ConnectionType,
5859
Ipv4Settings,
5960
Ipv6Settings,
6061
WirelessSettings,
@@ -79,7 +80,7 @@ async def add_wifi_psk_connection_profile_async(args: Namespace) -> None:
7980
profile = ConnectionProfile(
8081
connection=ConnectionSettings(
8182
uuid=str(uuid.uuid4()),
82-
connection_type='802-11-wireless',
83+
connection_type=ConnectionType.WIFI,
8384
connection_id=args.conn_id,
8485
autoconnect=args.auto,
8586
),
@@ -104,7 +105,7 @@ async def add_wifi_psk_connection_profile_async(args: Namespace) -> None:
104105

105106
print(f'nmcli connection show "{args.conn_id}"|grep -v -e -- -e default')
106107
print("Settings used:")
107-
functools.partial(pprint.pprint, sort_dicts=False)(profile.to_dbus())
108+
functools.partial(pprint, sort_dicts=False)(profile.to_settings_dict())
108109

109110

110111
if __name__ == "__main__":

examples/async/list-connections-async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def print_connection_profile(connection_path: str) -> None:
5353
print(f' route-metric: {profile.ipv4.route_metric}')
5454
if profile.ipv6:
5555
print("ipv6: method:", profile.ipv6.method)
56-
pprint.pprint(profile.to_dbus())
56+
pprint.pprint(profile.to_settings_dict(), sort_dicts=False)
5757

5858

5959
if __name__ == "__main__":

sdbus_async/networkmanager/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
ConnectionState,
2727
ConnectionStateFlags,
2828
ConnectionStateReason,
29+
ConnectionType,
2930
ConnectivityState,
3031
DeviceCapabilities,
3132
DeviceInterfaceFlags,
@@ -269,7 +270,7 @@
269270
__all__ = (
270271
'AccessPointCapabilities', 'BluetoothCapabilities',
271272
'ConnectionFlags', 'ConnectionState', 'ConnectionStateFlags',
272-
'ConnectionStateReason', 'ConnectivityState',
273+
'ConnectionStateReason', 'ConnectivityState', 'ConnectionType',
273274
'DeviceCapabilities', 'DeviceInterfaceFlags', 'DeviceMetered',
274275
'DeviceState', 'DeviceStateReason', 'DeviceType', 'IpTunnelMode',
275276
'ModemCapabilities', 'NetworkManagerConnectivityState',

sdbus_async/networkmanager/enums.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,59 @@ class DeviceStateReason(IntEnum):
473473
PEER_NOT_FOUND = 67
474474

475475

476+
# Connection Types, e.g. from connecion_profile.connection.type:
477+
#
478+
# There is no central list of all connection types in NM.
479+
# The best bet is to look for nm_connection_is_type() checks which use
480+
# NM_SETTING_(TYPE)_SETTING_NAME #defines (which are fined used for
481+
# settings for this connection-type. One connection_type can have several
482+
# of such settings groups, so we have to filter those to get the strings:
483+
#
484+
# Generated from NetworkManager source using:
485+
# grep -r nm_connection_is_type src/|
486+
# sed -n 's/.*NM_SETTING_/NM_SETTING_/;s/_SETTING_NAME.*/=/p' |
487+
# sort -u >.connection_is_type
488+
# grep -hr define.*_SETTING_NAME src/|
489+
# sed 's/#define //;s/_SETTING_NAME//;s/ /=/' >.setting_defines
490+
# grep -f .connection_is_type .setting_defines |
491+
# sed 's/NM_SETTING_/ /;s/6L/SIXL/;/GENERIC/d;s/=/ = /'
492+
#
493+
# One src/core/nm-device-*.c can support more than one ConnectionType,
494+
# thus there are more ConnectionTypes than DeviceTypes:
495+
496+
# From NetworkManager-1.35:
497+
class ConnectionType():
498+
ADSL = "adsl"
499+
BLUETOOTH = "bluetooth"
500+
BOND = "bond"
501+
BRIDGE = "bridge"
502+
CDMA = "cdma"
503+
DUMMY = "dummy"
504+
GSM = "gsm"
505+
INFINIBAND = "infiniband"
506+
IP_TUNNEL = "ip-tunnel"
507+
MACSEC = "macsec"
508+
MACVLAN = "macvlan"
509+
OLPC_MESH = "802-11-olpc-mesh"
510+
OVS_BRIDGE = "ovs-bridge"
511+
OVS_INTERFACE = "ovs-interface"
512+
OVS_PORT = "ovs-port"
513+
PPPOE = "pppoe"
514+
SIXLOWPAN = "6lowpan"
515+
TEAM = "team"
516+
TUN = "tun"
517+
VETH = "veth"
518+
VLAN = "vlan"
519+
VPN = "vpn"
520+
VRF = "vrf"
521+
VXLAN = "vxlan"
522+
WIFI_P2P = "wifi-p2p"
523+
WIRED = "802-3-ethernet"
524+
WIREGUARD = "wireguard"
525+
WIFI = "802-11-wireless"
526+
WPAN = "wpan"
527+
528+
476529
class DeviceType(IntEnum):
477530
"""Device Type
478531

sdbus_async/networkmanager/settings/connection.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
class ConnectionSettings(NetworkManagerSettingsMixin):
1212
"""General Connection Profile Settings"""
1313

14+
connection_id: str = field(
15+
metadata={'dbus_name': 'id', 'dbus_type': 's'},
16+
)
17+
connection_type: str = field(
18+
metadata={'dbus_name': 'type', 'dbus_type': 's'},
19+
)
20+
uuid: str = field(
21+
metadata={'dbus_name': 'uuid', 'dbus_type': 's'},
22+
)
1423
auth_retries: Optional[int] = field(
1524
metadata={'dbus_name': 'auth-retries', 'dbus_type': 'i'},
1625
default=None,
@@ -39,10 +48,6 @@ class ConnectionSettings(NetworkManagerSettingsMixin):
3948
metadata={'dbus_name': 'gateway-ping-timeout', 'dbus_type': 'u'},
4049
default=None,
4150
)
42-
connection_id: Optional[str] = field(
43-
metadata={'dbus_name': 'id', 'dbus_type': 's'},
44-
default=None,
45-
)
4651
interface_name: Optional[str] = field(
4752
metadata={'dbus_name': 'interface-name', 'dbus_type': 's'},
4853
default=None,
@@ -99,14 +104,6 @@ class ConnectionSettings(NetworkManagerSettingsMixin):
99104
metadata={'dbus_name': 'timestamp', 'dbus_type': 't'},
100105
default=None,
101106
)
102-
connection_type: Optional[str] = field(
103-
metadata={'dbus_name': 'type', 'dbus_type': 's'},
104-
default=None,
105-
)
106-
uuid: Optional[str] = field(
107-
metadata={'dbus_name': 'uuid', 'dbus_type': 's'},
108-
default=None,
109-
)
110107
wait_device_timeout: Optional[int] = field(
111108
metadata={'dbus_name': 'wait-device-timeout', 'dbus_type': 'i'},
112109
default=None,

0 commit comments

Comments
 (0)