summaryrefslogtreecommitdiff
path: root/examples/python/dbus/update-ip4-method.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/python/dbus/update-ip4-method.py')
-rwxr-xr-xexamples/python/dbus/update-ip4-method.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/examples/python/dbus/update-ip4-method.py b/examples/python/dbus/update-ip4-method.py
index bf14f7f9cc..28a222899b 100755
--- a/examples/python/dbus/update-ip4-method.py
+++ b/examples/python/dbus/update-ip4-method.py
@@ -21,15 +21,14 @@
#
# This example updates a connection's IPv4 method with the Update() method.
#
+# This uses the new NM 1.0 setting properties. See add-connection-compat.py
+# for a similar example using the backward-compatible properties
+#
# Configuration settings are described at
-# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html
+# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html
#
-import socket, struct, dbus, sys
-
-def ip_to_int(ip_string):
- return struct.unpack("=I", socket.inet_aton(ip_string))[0]
-
+import dbus, sys
if len(sys.argv) < 3:
print "Usage: %s <uuid> <auto|static> [address prefix gateway]" % sys.argv[0]
@@ -61,18 +60,22 @@ for c_path in settings.ListConnections():
if 'ipv4' not in c_settings:
c_settings['ipv4'] = {}
+ # clear existing address info
+ if c_settings['ipv4'].has_key('addresses'):
+ del c_settings['ipv4']['addresses']
+ if c_settings['ipv4'].has_key('address-data'):
+ del c_settings['ipv4']['address-data']
+ if c_settings['ipv4'].has_key('gateway'):
+ del c_settings['ipv4']['gateway']
+
# set the method and change properties
c_settings['ipv4']['method'] = method
- if method == "auto":
- # remove addresses
- c_settings['ipv4']['addresses'] = dbus.Array([], signature=dbus.Signature('au'))
- elif method == "manual":
+ if method == "manual":
# Add the static IP address, prefix, and (optional) gateway
- gw = 0
+ addr = dbus.Dictionary({'address': sys.argv[3], 'prefix': dbus.UInt32(int(sys.argv[4]))})
+ c_settings['ipv4']['address-data'] = dbus.Array([addr], signature=dbus.Signature('a{sv}'))
if len(sys.argv) == 6:
- gw = ip_to_int(sys.argv[5])
- addr = dbus.Array([ip_to_int(sys.argv[3]), dbus.UInt32(int(sys.argv[4])), gw], signature=dbus.Signature('u'))
- c_settings['ipv4']['addresses'] = dbus.Array([addr], signature=dbus.Signature('au'))
+ c_settings['ipv4']['gateway'] = sys.argv[5]
# Save all the updated settings back to NetworkManager
c_obj.Update(c_settings)