NM 0.7 D-Bus API Mini-Tutorial

Michael Stone michael at laptop.org
Thu Jun 12 00:55:21 EDT 2008


I got curious about how NM-0.7 works so I installed it on olpc3-17 by:

  sed -i -e '6s/enabled=0/enabled=1/' /etc/yum.repos.d/fedora.repo
  iwconfig eth0 mode managed essid 'media lab 802.11'
  killall dhclient 
  dhclient eth0
  yum -yt --nogpgcheck update NetworkManager
  /etc/init.d/NetworkManager restart

Then, with help from Michael Biebl and Rob McQueen, with two important
pieces of documentation

  http://debs.michaelbiebl.de/network-manager/spec.html
  http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties

and with the excellent interactive IPython shell, I was able to create a
silly script which uses the NM-0.7 interfaces to list visible access
points. I present it on the off chance that it might serve as a helpful
introduction for other people who would like to help us port the Sugar
UI to the new API (or who would like to change NM-0.7 to better support
our hardware and networking configuration.) The script is attached.

Regards,

Michael
-------------- next part --------------

NMI = 'org.freedesktop.NetworkManager'
NMD = 'org.freedesktop.NetworkManager.Device'
NMDW = 'org.freedesktop.NetworkManager.Device.Wireless'
NMA = 'org.freedesktop.NetworkManager.AccessPoint'
DBP = 'org.freedesktop.DBus.Properties'

def ii(o):
	print o.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")

import dbus
bus = dbus.SystemBus()
nmo = bus.get_object(NMI, '/' + NMI.replace('.','/'))
ii(nmo)


nmi = dbus.Interface(nmo, NMI)
nmp = dbus.Interface(nmo, DBP)
nmp.Get(NMI, 'WirelessEnabled')
nmp.Get(NMI, 'WirelessHardwareEnabled')

for dev_pth in nmi.GetDevices():
	devo = bus.get_object(NMI, dev_pth)
	ii(devo)

	devi = dbus.Interface(devo, NMD)
	devw = dbus.Interface(devo, NMDW)
	devp = dbus.Interface(devo, DBP)
	devp.Get(NMD, 'DeviceType')
	devp.Get(NMD, 'Managed')

	for ap_pth in devw.GetAccessPoints():
    		apo = bus.get_object(NMI, ap_pth)
    		print ''.join([chr(x) for x in apo.Get(NMA, "Ssid", dbus_interface=DBP)])


More information about the Devel mailing list