Disconnect network using cNetworkManager Python library

Martin Vidner mvidner at suse.cz
Mon Jan 23 09:05:17 PST 2012


Hi Olivier,

On Mon, Jan 23, 2012 at 03:46:16PM +0100, Olivier Deckmyn wrote:
>     class Wifi(object):
> 
>         def connect(self, ssid, security="open", password=None):
>             "Connects to given Wifi network"
>             c=None # connection settings
>             us = NetworkManagerUserSettings([])

NetworkManagerUserSettings is a server, not a client. (It's a design
quirk of NM which was eliminated in NM 0.9)
You should create only one for the daemon, not for each conection
attempt.

>     def change_network_settings():
>         key="station:network:change"
>         change=cache.get(key)
>         if change is not None:
>             print "DISCONNECT"
>             kill_allconnections()
>             print "CHANGE SETTINGS"
>             wifi=cache.get(key+':wifi')
>             if wifi is not None:
>                 ssid=cache.get(key+':wifi:ssid')
>                 security=cache.get(key+':wifi:security')
>                 password=cache.get(key+':wifi:password')
>                 print "SWITCHING TO %s"%ssid
>                 Wifi().connect(ssid, security, password)
>             cache.delete(key)
>         return True

Please be warned that cnetworkmanager is obsolete as upstream now
includes its own CLI, nmcli (written in C, since about NM 0.8.1). I
haven't updated cnetworkmanager for the API changes of NM 0.9.

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20120123/e4725f9c/attachment.pgp>


More information about the dbus mailing list