doc: Migrating from cnetworkmanager to nmcli
[cnetworkmanager.git] / networkmanager / networkmanager.py
blob04f1405f91037a6e9fb642951c4e4e00259d3994
1 # -*- coding: utf-8 -*-
3 import dbus
4 from dbusclient import DBusClient, object_path
5 from dbusclient.func import *
6 from device import Device
7 from activeconnection import ActiveConnection
8 from base import Base
9 from util import Enum
11 # gratuitous convertor to test writable properties
12 def english_to_bool(v):
13 if v == "yes":
14 return True
15 elif v == "no":
16 return False
17 return v
19 class NetworkManager(Base):
20 """networkmanager
22 The NM client library
24 Methods:
25 GetDevices ( ) → ao
26 ActivateConnection ( s: service_name, o: connection, o: device, o: specific_object ) → o
27 DeactivateConnection ( o: active_connection ) → nothing
28 Sleep ( b: sleep ) → nothing
30 Signals:
31 StateChanged ( u: state )
32 PropertiesChanged ( a{sv}: properties )
33 DeviceAdded ( o: device_path )
34 DeviceRemoved ( o: device_path )
36 Properties:
37 WirelessEnabled - b - (readwrite)
38 WirelessHardwareEnabled - b - (read)
39 ActiveConnections - ao - (read)
40 State - u - (read) (NM_STATE)
42 Enumerated types:
43 NM_STATE
44 """
46 SERVICE = "org.freedesktop.NetworkManager"
47 OPATH = "/org/freedesktop/NetworkManager"
48 IFACE = "org.freedesktop.NetworkManager"
50 def __init__(self):
51 super(NetworkManager, self).__init__(self.SERVICE, self.OPATH, default_interface=self.IFACE)
54 class State(Enum):
55 UNKNOWN = 0
56 ASLEEP = 1
57 CONNECTING = 2
58 CONNECTED = 3
59 DISCONNECTED = 4
61 "TODO find a good term for 'adaptor'"
63 #from dbusclient.adaptors import *
65 NetworkManager._add_adaptors(
66 GetDevices = MA(seq_adaptor(Device._create)),
67 ActivateConnection = MA(ActiveConnection, identity, object_path, object_path, object_path),
68 DeactivateConnection = MA(void, object_path),
70 State = PA(NetworkManager.State),
71 WirelessEnabled = PA(bool, english_to_bool),
72 WirelessHardwareEnabled = PA(bool),
73 ActiveConnections = PA(seq_adaptor(ActiveConnection)),
75 StateChanged = SA(NetworkManager.State),