Re: Querying network state via D-Bus; unexpected result values [SOLVED]
- From: Adam Tauno Williams <awilliam whitemice org>
- To: networkmanager-list gnome org
- Subject: Re: Querying network state via D-Bus; unexpected result values [SOLVED]
- Date: Mon, 28 Nov 2011 10:25:46 -0500
On Mon, 2011-11-28 at 15:44 +0100, Jirka Klimes wrote:
> On Monday 28 of November 2011 02:14:07 Adam Tauno Williams wrote:
> > I'm attempting to interrogate the state of the network condition via
> > Network Manager's D-Bus service. I can reliably get a value, but the
> > value seems incorrect.
> > According to
> > <http://projects.gnome.org/NetworkManager/developers/spec-07.html#type-NM_D
> > EVICE_STATE> I expect to see a value of 8 [NM_DEVICE_STATE_ACTIVATED] if
> > the device is online. But what I see from call is generally a 20 if the
> > interface [Device 0, eth0] is unplugged and a value of 100 if the
> > interface is online.
> The link you use is for NM 0.7, but according to device states value you
> apparently use NM 0.9 that changed state codes.
> So, 100 = NM_DEVICE_STATE_ACTIVATED now.
> The API spec for NM 0.9 is here:
> http://projects.gnome.org/NetworkManager/developers/api/09/spec.html#type-
> NM_DEVICE_STATE
Ah, my bad. I tried changing the version(s) in the URL, but what I
tried didn't work.
> > #!/bin/env python
> > import dbus
> >
> > bus = dbus.SystemBus()
> > proxy = bus.get_object("org.freedesktop.NetworkManager",
> > "/org/freedesktop/NetworkManager")
> > manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
> > # Get device-specific state
> > devices = manager.GetDevices()
> > for d in devices:
> > dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d)
> > prop_iface = dbus.Interface(dev_proxy,
> > "org.freedesktop.DBus.Properties") # Get the device's current state and
> > interface name
> > state = prop_iface.Get("org.freedesktop.NetworkManager.Device",
> > "State") name = prop_iface.Get("org.freedesktop.NetworkManager.Device",
> > "Interface")
> > # and print them out
> > print state
> > if state == 8: # activated
> > print "Device %s is activated" % name
> > else:
> > print "Device %s is not activated" % name
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]