From 9c202e3e860b3be9e1f8882630b69affbb130102 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Sun, 3 Feb 2013 14:49:22 +0100 Subject: Imported Upstream version 0.9.7.995 --- examples/python/Makefile.am | 5 ++- examples/python/Makefile.in | 62 ++++++++++++++++++------------- examples/python/add-connection.py | 63 ++++++++++++++++++++++++++++++++ examples/python/add-system-connection.py | 48 ------------------------ examples/python/nm-state.py | 21 +++++++++-- 5 files changed, 121 insertions(+), 78 deletions(-) create mode 100755 examples/python/add-connection.py delete mode 100755 examples/python/add-system-connection.py (limited to 'examples/python') diff --git a/examples/python/Makefile.am b/examples/python/Makefile.am index 2706c0f4..4c0f9c74 100644 --- a/examples/python/Makefile.am +++ b/examples/python/Makefile.am @@ -1,12 +1,13 @@ EXTRA_DIST = \ nm-state.py \ - add-system-connection.py \ + add-connection.py \ add-system-wifi-connection.py vpn.py \ + update-secrets.py \ list-connections.py \ show-bssids.py \ disconnect-device.py \ - get-active-connections.py \ + get-active-connection-uuids.py \ list-devices.py \ goi-list-connections.py \ goi-device-state-ip4config.py diff --git a/examples/python/Makefile.in b/examples/python/Makefile.in index 9ce36bf8..0df7878f 100644 --- a/examples/python/Makefile.in +++ b/examples/python/Makefile.in @@ -54,16 +54,18 @@ subdir = examples/python DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \ - $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/gtk-doc.m4 \ - $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/intlmacosx.m4 \ - $(top_srcdir)/m4/intltool.m4 $(top_srcdir)/m4/introspection.m4 \ - $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ - $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libnl-check.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \ - $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \ - $(top_srcdir)/m4/vapigen.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/gettext.m4 \ + $(top_srcdir)/m4/gnome-code-coverage.m4 \ + $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intltool.m4 \ + $(top_srcdir)/m4/introspection.m4 $(top_srcdir)/m4/lib-ld.m4 \ + $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \ + $(top_srcdir)/m4/libnl-check.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \ + $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/vapigen.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -96,6 +98,10 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ +CKDB_PATH = @CKDB_PATH@ +CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ +CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ +CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CXX = @CXX@ @@ -110,9 +116,7 @@ DBUS_SYS_DIR = @DBUS_SYS_DIR@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DHCLIENT_PATH = @DHCLIENT_PATH@ -DHCLIENT_VERSION = @DHCLIENT_VERSION@ DHCPCD_PATH = @DHCPCD_PATH@ -DISABLE_DEPRECATED = @DISABLE_DEPRECATED@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ @@ -122,17 +126,14 @@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ +GENHTML = @GENHTML@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ -GIO_CFLAGS = @GIO_CFLAGS@ -GIO_LIBS = @GIO_LIBS@ GLIB_CFLAGS = @GLIB_CFLAGS@ GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ GLIB_LIBS = @GLIB_LIBS@ GLIB_MAKEFILE = @GLIB_MAKEFILE@ GLIB_MKENUMS = @GLIB_MKENUMS@ -GMODULE_CFLAGS = @GMODULE_CFLAGS@ -GMODULE_LIBS = @GMODULE_LIBS@ GMSGFMT = @GMSGFMT@ GMSGFMT_015 = @GMSGFMT_015@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ @@ -173,6 +174,7 @@ IPTABLES_PATH = @IPTABLES_PATH@ IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ +LCOV = @LCOV@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBDL = @LIBDL@ @@ -189,11 +191,7 @@ LIBNL2_LIBS = @LIBNL2_LIBS@ LIBNL3_CFLAGS = @LIBNL3_CFLAGS@ LIBNL3_LIBS = @LIBNL3_LIBS@ LIBNL_CFLAGS = @LIBNL_CFLAGS@ -LIBNL_GENL3_CFLAGS = @LIBNL_GENL3_CFLAGS@ -LIBNL_GENL3_LIBS = @LIBNL_GENL3_LIBS@ LIBNL_LIBS = @LIBNL_LIBS@ -LIBNL_ROUTE3_CFLAGS = @LIBNL_ROUTE3_CFLAGS@ -LIBNL_ROUTE3_LIBS = @LIBNL_ROUTE3_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@ @@ -208,6 +206,8 @@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +MM_GLIB_CFLAGS = @MM_GLIB_CFLAGS@ +MM_GLIB_LIBS = @MM_GLIB_LIBS@ MOC = @MOC@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ @@ -217,6 +217,7 @@ NMEDIT = @NMEDIT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ +NM_MODIFY_SYSTEM_POLICY = @NM_MODIFY_SYSTEM_POLICY@ NM_VERSION = @NM_VERSION@ NSS_CFLAGS = @NSS_CFLAGS@ NSS_LIBS = @NSS_LIBS@ @@ -243,13 +244,14 @@ PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ QT_CFLAGS = @QT_CFLAGS@ QT_LIBS = @QT_LIBS@ RANLIB = @RANLIB@ -RESOLVCONF_PATH = @RESOLVCONF_PATH@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ -SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@ -SYSTEMD_LIBS = @SYSTEMD_LIBS@ +SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ +SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ +SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ +SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ UDEV_BASE_DIR = @UDEV_BASE_DIR@ USE_NLS = @USE_NLS@ @@ -304,6 +306,11 @@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ +nmbinary = @nmbinary@ +nmconfdir = @nmconfdir@ +nmdatadir = @nmdatadir@ +nmrundir = @nmrundir@ +nmstatedir = @nmstatedir@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ @@ -318,9 +325,13 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +with_dhclient = @with_dhclient@ +with_dhcpcd = @with_dhcpcd@ +with_netconfig = @with_netconfig@ +with_resolvconf = @with_resolvconf@ EXTRA_DIST = \ nm-state.py \ - add-system-connection.py \ + add-connection.py \ add-system-wifi-connection.py all: all-am @@ -513,10 +524,11 @@ uninstall-am: mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am vpn.py \ + update-secrets.py \ list-connections.py \ show-bssids.py \ disconnect-device.py \ - get-active-connections.py \ + get-active-connection-uuids.py \ list-devices.py \ goi-list-connections.py \ goi-device-state-ip4config.py diff --git a/examples/python/add-connection.py b/examples/python/add-connection.py new file mode 100755 index 00000000..24b3f600 --- /dev/null +++ b/examples/python/add-connection.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# 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 - 2012 Red Hat, Inc. +# + +# +# 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': 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')) +s_ip4 = dbus.Dictionary({ + 'addresses': dbus.Array([addr1], signature=dbus.Signature('au')), + 'method': 'manual'}) + +s_ip6 = dbus.Dictionary({'method': 'ignore'}) + +con = dbus.Dictionary({ + '802-3-ethernet': s_wired, + 'connection': s_con, + 'ipv4': s_ip4, + 'ipv6': s_ip6}) + + +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") + +settings.AddConnection(con) + diff --git a/examples/python/add-system-connection.py b/examples/python/add-system-connection.py deleted file mode 100755 index f55d0df0..00000000 --- a/examples/python/add-system-connection.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# 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. -# - -import dbus - -s_wired = dbus.Dictionary({'duplex': 'full'}) -s_con = dbus.Dictionary({ - 'type': '802-3-ethernet', - 'uuid': '7371bb78-c1f7-42a3-a9db-5b9566e8ca07', - 'id': 'MyConnection'}) - -addr1 = dbus.Array([dbus.UInt32(50462986L), dbus.UInt32(8L), dbus.UInt32(16908554L)], signature=dbus.Signature('u')) -s_ip4 = dbus.Dictionary({ - 'addresses': dbus.Array([addr1], signature=dbus.Signature('au')), - 'method': 'manual'}) - -s_ip6 = dbus.Dictionary({'method': 'ignore'}) - -con = dbus.Dictionary({ - '802-3-ethernet': s_wired, - 'connection': s_con, - 'ipv4': s_ip4, - 'ipv6': s_ip6}) - - -bus = dbus.SystemBus() - -proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings") -settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings") - -settings.AddConnection(con) - diff --git a/examples/python/nm-state.py b/examples/python/nm-state.py index a79b3405..94fa6309 100644 --- a/examples/python/nm-state.py +++ b/examples/python/nm-state.py @@ -14,11 +14,26 @@ # 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 +# Device states from include/NetworkManager.h +device_states = { 0: "Unknown", + 10: "Unmanaged", + 20: "Unavailable", + 30: "Disconnected", + 40: "Prepare", + 50: "Config", + 60: "Need Auth", + 70: "IP Config", + 80: "IP Check", + 90: "Secondaries", + 100: "Activated", + 110: "Deactivating", + 120: "Failed" } + bus = dbus.SystemBus() proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager") @@ -35,10 +50,10 @@ for d in devices: name = prop_iface.Get("org.freedesktop.NetworkManager.Device", "Interface") # and print them out - if state == 8: # activated + if state == 100 : # activated print "Device %s is activated" % name else: - print "Device %s is not activated" % name + print "Device %s is not activated (state=%s)" % (name, device_states[state]) # Get active connection state -- cgit 1.3.0-6-gf8a5