diff options
Diffstat (limited to 'examples/python/gi/add_connection.py')
| -rwxr-xr-x | examples/python/gi/add_connection.py | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/examples/python/gi/add_connection.py b/examples/python/gi/add_connection.py index 76c2e94e..bb1163db 100755 --- a/examples/python/gi/add_connection.py +++ b/examples/python/gi/add_connection.py @@ -1,5 +1,7 @@ #!/usr/bin/env python # -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# vim: ft=python ts=4 sts=4 sw=4 et ai + # # 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 @@ -15,21 +17,19 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2014 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # # # This example shows how to add a new NM connection profile. -# The code uses libnm-util (NetworkManager) and libnm-glib (NMClient) -# via GObject Introspection. +# The code uses libnm (NM) via GObject Introspection. # # Documentation links: -# https://developer.gnome.org/libnm-glib/0.9/ -# https://developer.gnome.org/libnm-util/0.9/ -# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html +# https://developer.gnome.org/libnm/1.0/ +# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html # -from gi.repository import GLib, NetworkManager, NMClient +from gi.repository import GLib, NM import sys, uuid main_loop = None @@ -39,19 +39,19 @@ def print_values(setting, key, value, flags, data): # create an Ethernet connection and return it def create_profile(name): - profile = NetworkManager.Connection.new() - s_con = NetworkManager.SettingConnection.new() - s_con.set_property(NetworkManager.SETTING_CONNECTION_ID, name) - s_con.set_property(NetworkManager.SETTING_CONNECTION_UUID, str(uuid.uuid4())) - s_con.set_property(NetworkManager.SETTING_CONNECTION_TYPE, "802-3-ethernet") + profile = NM.SimpleConnection.new() + s_con = NM.SettingConnection.new() + s_con.set_property(NM.SETTING_CONNECTION_ID, name) + s_con.set_property(NM.SETTING_CONNECTION_UUID, str(uuid.uuid4())) + s_con.set_property(NM.SETTING_CONNECTION_TYPE, "802-3-ethernet") - s_wired = NetworkManager.SettingWired.new() + s_wired = NM.SettingWired.new() - s_ip4 = NetworkManager.SettingIP4Config.new() - s_ip4.set_property(NetworkManager.SETTING_IP4_CONFIG_METHOD, "auto") + s_ip4 = NM.SettingIP4Config.new() + s_ip4.set_property(NM.SETTING_IP_CONFIG_METHOD, "auto") - s_ip6 = NetworkManager.SettingIP6Config.new() - s_ip6.set_property(NetworkManager.SETTING_IP6_CONFIG_METHOD, "auto") + s_ip6 = NM.SettingIP6Config.new() + s_ip6.set_property(NM.SETTING_IP_CONFIG_METHOD, "auto") profile.add_setting(s_con) profile.add_setting(s_ip4) @@ -64,11 +64,12 @@ def create_profile(name): return profile # callback function -def added_cb(settings, con, error, data): - if error is (None): +def added_cb(client, result, data): + try: + client.add_connection_finish(result) print("The connection profile has been succesfully added to NetworkManager.") - else: - print(error) + except Exception, e: + print("Error: %s" % e) main_loop.quit() if __name__ == "__main__": @@ -85,17 +86,14 @@ if __name__ == "__main__": main_loop = GLib.MainLoop() - # create RemoteSettings object - settings = NMClient.RemoteSettings.new(None); + # create Client object + client = NM.Client.new(None) # create a connection profile for NM con = create_profile(profile_name) # send the connection to NM - if persistent: - settings.add_connection(con, added_cb, None) - else: - settings.add_connection_unsaved(con, added_cb, None) + client.add_connection_async(con, persistent, None, added_cb, None) main_loop.run() |