examples: update python examples

Update the raw D-Bus python examples to use newer APIs where
appropriate (and split the add-connection example into 1.0-only and
0.9-compatible versions). Update the gi-based python examples for the
various API changes since they were last updated.

Also add a comment to the ruby add-connection example pointing out
that it's still using the old settings APIs.
This commit is contained in:
Dan Winship
2014-11-13 14:27:26 -05:00
parent 94157ce900
commit 66936decfa
12 changed files with 227 additions and 137 deletions

View File

@@ -18,20 +18,17 @@
#
#
# This example adds a new ethernet connection via AddConnection() D-Bus call.
# This example adds a new ethernet connection via the AddConnection()
# D-Bus call, using the new 'ipv4.address-data' and 'ipv4.gateway'
# settings introduced in NetworkManager 1.0. Compare
# add-connection-compat.py, which will work against older versions of
# NetworkManager as well.
#
# 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, 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))
import dbus, uuid
s_wired = dbus.Dictionary({'duplex': 'full'})
s_con = dbus.Dictionary({
@@ -39,9 +36,12 @@ s_con = dbus.Dictionary({
'uuid': str(uuid.uuid4()),
'id': 'MyConnectionExample'})
addr1 = dbus.Array([ip_to_int("10.1.2.3"), dbus.UInt32(8L), ip_to_int("10.1.2.1")], signature=dbus.Signature('u'))
addr1 = dbus.Dictionary({
'address': '10.1.2.3',
'prefix': dbus.UInt32(8L)})
s_ip4 = dbus.Dictionary({
'addresses': dbus.Array([addr1], signature=dbus.Signature('au')),
'address-data': dbus.Array([addr1], signature=dbus.Signature('a{sv}')),
'gateway': '10.1.2.1',
'method': 'manual'})
s_ip6 = dbus.Dictionary({'method': 'ignore'})