diff options
| author | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2015-01-22 00:29:39 +0100 |
| commit | 2c032d8f1c6292c1338a615e6ec40252889ba85c (patch) | |
| tree | 1f77182220b2b0264288ba4a476ab47e5bc48716 /examples/python/dbus/update-ip4-method.py | |
| parent | 33491bc4279481db8ae47213e34a6d695a0e8830 (diff) | |
Imported Upstream version 1.0.0 upstream/1.0.0
Diffstat (limited to 'examples/python/dbus/update-ip4-method.py')
| -rwxr-xr-x | examples/python/dbus/update-ip4-method.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/examples/python/dbus/update-ip4-method.py b/examples/python/dbus/update-ip4-method.py index 243738c5..28a22289 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] @@ -58,21 +57,25 @@ for c_path in settings.ListConnections(): continue # add IPv4 setting if it doesn't yet exist - if not c_settings.has_key('ipv4'): + 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) |