Re: Querying network state via D-Bus; unexpected result values
- From: Jirka Klimes <jklimes redhat com>
- To: networkmanager-list gnome org
- Subject: Re: Querying network state via D-Bus; unexpected result values
- Date: Mon, 28 Nov 2011 15:44:31 +0100
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
API spec for NM 0.8:
http://projects.gnome.org/NetworkManager/developers/api/08/spec-08.html#type-
NM_DEVICE_STATE
Jirka
> #!/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
>
>
> _______________________________________________
> networkmanager-list mailing list
> networkmanager-list gnome org
> http://mail.gnome.org/mailman/listinfo/networkmanager-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]