1
- Welcome to python-networkmanager's documentation!
2
- =================================================
1
+ Python API to talk to NetworkManager
2
+ ====================================
3
3
4
- python-networkmanager wraps NetworkManagers D-Bus interface so you can be less
5
- verbose when talking to NetworkManager from python. All interfaces have been
6
- wrapped in classes, properties are exposed as python properties and function
7
- calls are forwarded to the correct interface .
4
+ NetworkManager provides a detailed and capable D-Bus interface on the system
5
+ bus. You can use this interface to query NetworkManager about the overall state
6
+ of the network and details of network devices like current IP addresses or DHCP
7
+ options, and to activate and deactivate network connections .
8
8
9
- I wrote it to reduce a 100-line python script to 50 lines. Not realizing that
10
- the library has more lines than the ones I removed. Oh well 😊
9
+ python-networkmanager takes this D-Bus interface and wraps D-Bus interfaces in
10
+ classes and D-Bus properties in python properties. It also provides a
11
+ command-line utility to inspect the configuration and (de-)activate
12
+ connections.
11
13
12
- As of version 0.9.2, python-networkmanager also ships a command-line utility
13
- called n-m, which allows you to manipulate NetworkManager's state from the
14
- command line.
15
-
16
- :mod: `NetworkManager ` -- Easy communication with NetworkManager
17
- ---------------------------------------------------------------
14
+ The :mod: `NetworkManager ` module
15
+ --------------------------------
18
16
.. module :: NetworkManager
19
- :platform: Linux systems with NetworkManager 0.90
20
- :synopsis: Talk to NetworkManager without being verbose
17
+ :platform: Linux systems with NetworkManager 0.9.x
18
+ :synopsis: Talk to NetworkManager from python
21
19
22
20
All the code is contained in one module: :mod: `NetworkManager `. Using it is as
23
21
simple as you think it is:
@@ -26,20 +24,33 @@ simple as you think it is:
26
24
27
25
>> > import NetworkManager
28
26
>> > NetworkManager.NetworkManager.Version
29
- ' 0.9.1.90 '
27
+ ' 0.9.6.0 '
30
28
31
29
NetworkManager exposes a lot of information via D-Bus and also allows full
32
30
control of network settings. The full D-Bus API can be found on `NetworkManager
33
31
project website `_. All interfaces listed there have been wrapped in classes as
34
- listed below.
32
+ listed below. With a few exceptions, they behave exactly like the D-Bus
33
+ methods. These exceptions are for convenience and limited to this list:
34
+
35
+ * IP addresses are returned as strings of the form :data: `1.2.3.4 ` instead of
36
+ network byte ordered integers.
37
+ * Route metrics are returned in host byte order, so you can use them as
38
+ integers.
39
+ * Mac addresses and BSSIDs are always returned as strings of the form
40
+ :data: `00:11:22:33:44:55 ` instead of byte sequences.
41
+ * Wireless SSID's are returned as strings instead of byte sequences. They will
42
+ be decoded as UTF-8 data, so using any other encoding for your SSID will
43
+ result in errors.
35
44
36
45
.. class :: NMDbusInterface
37
46
38
47
This is the base class for all interface wrappers. It adds a few useful
39
48
features to standard D-Bus interfaces:
40
49
41
50
* All D-Bus properties are exposed as python properties
42
- * Return values are automatically unwrapped (so no more :data: `dbus.String `)
51
+ * Return values are automatically converted to python basic types (so no more
52
+ :data: `dbus.String `, but simple :data: `str ` (python 3) or :data: `unicode `
53
+ (python 2))
43
54
* Object paths in return values are automatically replaced with proxy objects,
44
55
so you don't need to do that manually
45
56
* ...and vice versa when sending
@@ -48,7 +59,7 @@ features to standard D-Bus interfaces:
48
59
.. function :: const(prefix, value)
49
60
50
61
Many of NetworkManagers D-Bus methods expect or return numeric constants, for
51
- which there are enums in teh C sourece code only . These constants, such as
62
+ which there are enums in the C source code. These constants, such as
52
63
:data: `NM_STATE_CONNECTED_GLOBAL `, can all be found in the
53
64
:mod: `NetworkManager ` module as well. The :func: `const ` function can help you
54
65
translate them to text. For example:
@@ -60,7 +71,7 @@ translate them to text. For example:
60
71
>> > NetworkManager.const(' device_type' , 2 )
61
72
' wifi'
62
73
63
- .. _`NetworkManager project website` : http:// projects.gnome.org/NetworkManager/developers/migrating-to- 09/spec.html
74
+ .. _`NetworkManager project website` : projects.gnome.org/NetworkManager/developers/api/ 09/spec.html
64
75
65
76
List of classes
66
77
---------------
@@ -102,9 +113,19 @@ interface.
102
113
103
114
.. class :: Bluetooth
104
115
116
+ .. class :: OlpcMesh
117
+
105
118
.. class :: Wimax
106
119
107
- .. class :: OlpcMesh
120
+ .. class :: Infiniband
121
+
122
+ .. class :: Bond
123
+
124
+ .. class :: Bridge
125
+
126
+ .. class :: Vlan
127
+
128
+ .. class :: Adsl
108
129
109
130
These classes represent D-Bus interfaces for various types of hardware. Note
110
131
that methods such as :data: `NetworkManager.GetDevices() ` will only return
@@ -118,30 +139,50 @@ that methods such as :data:`NetworkManager.GetDevices()` will only return
118
139
[(' eth0' , ' Wired' ), (' wlan0' , ' Wireless' ), (' wwan0' , ' Modem' )]
119
140
120
141
.. class :: IP4Config
142
+
121
143
.. class :: IP6Config
122
144
145
+ .. class :: DHCP4Config
146
+
147
+ .. class :: DHCP6Config
148
+
123
149
These classes represent the various IP configuration interfaces.
124
150
151
+ .. class :: AgentManager
152
+
153
+ .. class :: SecretAgent
154
+
155
+ Classes that can be used to handle and store secrets. Note that these are not
156
+ for querying NetworkManager's exisiting secret stores. For that the
157
+ :func: `GetSecrets ` method of the :class: `Connection ` class can be used.
158
+
125
159
.. class :: VPNConnection
126
160
127
161
This class represents the :data: `org.freedesktop.NetworkManager.VPN.Connection `
128
162
interface.
129
163
164
+ .. class :: VPNPlugin
165
+
166
+ A class that can be used to query VPN plugins.
167
+
130
168
.. toctree ::
131
169
:maxdepth: 2
132
170
133
171
The n-m utility
134
172
---------------
135
- n-m is a command-line tool to deal with network-manager. It can connect you to
136
- defined networks and disconnect you again.
137
-
138
- Usage: [options] action [arguments]
139
-
140
- Actions:
141
- list - List all defined and active connections
142
- activate - Activate a connection
143
- deactivate - Deactivate a connection
144
- offline - Deactivate all connections
145
- enable - Enable specific connection types
146
- disable - Disable specific connection types
147
- info - Information about a connection
173
+ n-m is a command-line tool to interact with NetworkManager. With it, you can
174
+ inspect various configuration items and (de-)activate connections.
175
+
176
+ Usage: [options] action [arguments]
177
+
178
+ Actions:
179
+ list - List all defined and active connections
180
+ activate - Activate a connection
181
+ deactivate - Deactivate a connection
182
+ offline - Deactivate all connections
183
+ enable - Enable specific connection types
184
+ disable - Disable specific connection types
185
+ info - Information about a connection
186
+ dump - Dump a python hash of connection information, suitable for
187
+ creating new connections
188
+
0 commit comments