summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2012-08-24 12:50:50 +0200
committerJiří Klimeš <jklimes@redhat.com>2012-08-24 12:50:50 +0200
commit3b3060f2a5f0ffb8872043e8fe29a4d2b1e86ed4 (patch)
tree733e3f42a4af877c340a312e6982b488eb42a2a5 /examples
parent3fe99e7ebf9c4b75807037b9095c0fa25991d052 (diff)
downloadNetworkManager-3b3060f2a5f0ffb8872043e8fe29a4d2b1e86ed4.tar.gz
examples: add IP converting functions and rename add-system-connection.py
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/python/add-connection.py (renamed from examples/python/add-system-connection.py)27
1 files changed, 21 insertions, 6 deletions
diff --git a/examples/python/add-system-connection.py b/examples/python/add-connection.py
index f55d0df0b9..24b3f600d6 100755
--- a/examples/python/add-system-connection.py
+++ b/examples/python/add-connection.py
@@ -14,18 +14,32 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
-# Copyright (C) 2010 Red Hat, Inc.
+# Copyright (C) 2010 - 2012 Red Hat, Inc.
#
-import dbus
+#
+# This example adds a new ethernet connection via AddConnection() D-Bus call.
+#
+# Configuration settings are described at
+# http://projects.gnome.org/NetworkManager/developers/api/09/ref-settings.html
+#
+
+import socket, struct, dbus, uuid
+
+# Helper functions
+def ip_to_int(ip_string):
+ return struct.unpack("=I", socket.inet_aton(ip_string))[0]
+
+def int_to_ip(ip_int):
+ return socket.inet_ntoa(struct.pack("=I", ip_int))
s_wired = dbus.Dictionary({'duplex': 'full'})
s_con = dbus.Dictionary({
'type': '802-3-ethernet',
- 'uuid': '7371bb78-c1f7-42a3-a9db-5b9566e8ca07',
- 'id': 'MyConnection'})
+ 'uuid': str(uuid.uuid4()),
+ 'id': 'MyConnectionExample'})
-addr1 = dbus.Array([dbus.UInt32(50462986L), dbus.UInt32(8L), dbus.UInt32(16908554L)], signature=dbus.Signature('u'))
+addr1 = dbus.Array([ip_to_int("10.1.2.3"), dbus.UInt32(8L), ip_to_int("10.1.2.1")], signature=dbus.Signature('u'))
s_ip4 = dbus.Dictionary({
'addresses': dbus.Array([addr1], signature=dbus.Signature('au')),
'method': 'manual'})
@@ -39,8 +53,9 @@ con = dbus.Dictionary({
'ipv6': s_ip6})
-bus = dbus.SystemBus()
+print "Creating connection:", s_con['id'], "-", s_con['uuid']
+bus = dbus.SystemBus()
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings")
settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings")