On Thursday 25 of March 2010 02:46:35 Bluesky_greenleaf wrote: > Dear Dan, > > I would like to write an application based on the NM D-BUS. I have taken a > look at the document of NM, the link is shown as follows: > > http://projects.gnome.org/NetworkManager/developers/spec-08.html > and > http://projects.gnome.org/NetworkManager/developers/spec.html > > I know how to disconnect the network connection for example Ethernet, Wifi > wlan0 using the D-BUS, but How to start a connection for Eth0 or WLAN0 > based on the D-BUS. I don't find which method can do this function. I have > /org/freedesktop/NetworkManager > /org/freedesktop/NetworkManager/Device/0 > /org/freedesktop/NetworkManager/Device/1 > > Are there other documentations or sample scripts? > > Thanks > > William
You are looking for ActivateConnection method of org.freedesktop.NetworkManager interface: http://projects.gnome.org/NetworkManager/developers/spec-08.html#org.freedesktop.NetworkManager When connecting, NM uses a concept of connections, which are configured profiles that can be activated on a device. For more info see http://live.gnome.org/NetworkManagerConfiguration Here are two simple examples, how to activate a connection. You have to adjust the paths of course. 1) Python #!/usr/bin/python import dbus SERVICE = "org.freedesktop.NetworkManagerSystemSettings" OPATH = "/org/freedesktop/NetworkManager" IFACE = "org.freedesktop.NetworkManager" CONNECTION = "/org/freedesktop/NetworkManagerSettings/1" DEVICE = "/org/freedesktop/NetworkManager/Devices/0" bus = dbus.SystemBus() nm_iface = dbus.Interface(bus.get_object(SERVICE, OPATH), IFACE) # Ask NM to activate the connection active_path = nm_iface.ActivateConnection(SERVICE, CONNECTION, DEVICE, "/") if not active_path: print "Couldn't activate connection" sys.exit(1) 2) Bash #!/bin/bash SERVICE="org.freedesktop.NetworkManagerSystemSettings" CONNECTION="/org/freedesktop/NetworkManagerSettings/1" DEVICE="/org/freedesktop/NetworkManager/Devices/0" dbus-send --system --print-reply --type=method_call -- dest='org.freedesktop.NetworkManager' \ '/org/freedesktop/NetworkManager' org.freedesktop.NetworkManager.ActivateConnection \ string:"$SERVICE" objpath:"$CONNECTION" objpath:"$DEVICE" objpath:"/" Some past discussion on examples: http://mail.gnome.org/archives/networkmanager-list/2010-January/msg00212.html http://mail.gnome.org/archives/networkmanager-list/2010-February/msg00087.html http://mail.gnome.org/archives/networkmanager-list/2009-July/msg00035.html You can also find some examples in source tree of NM in examples directory. We should probably create a section on wiki with some examples to have them in one place and easy to find. Jirka _______________________________________________ NetworkManager-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/networkmanager-list
