Re: getting state of a VPN connection via DBus in Python

Thank you very much it worked
I will update to NM 0.9.x as soon as possible!
"ActiveConnections" of /org/freedesktop/
NetworkManager only lists active connections
what if I want to find a VPN state only by name (inactive VPNs too)? ( e.g. listing state of all VPN connections on system)

On Thu, Jun 28, 2012 at 1:11 AM, Dan Williams <dcbw redhat com> wrote:
On Sat, 2012-06-23 at 22:32 +0430, Ariyan wrote:
> I'm trying to get state of a VPN connection via DBus in Python.
> Here is my code:
>             name="testVPN"
>             proxy =
>         dbus.SystemBus().get_object('org.freedesktop.NetworkManagerUserSettings', '/org/freedesktop/NetworkManagerSettings')
>             iface = dbus.Interface(proxy,
>         'org.freedesktop.NetworkManagerSettings')
>             connections = iface.ListConnections()
>             for connection in connections:
>                 proxy =
>         dbus.SystemBus().get_object('org.freedesktop.NetworkManagerUserSettings', connection)
>                 iface = dbus.Interface(proxy,
>         'org.freedesktop.NetworkManagerSettings.Connection')
>                 con_settings = iface.GetSettings()['connection']
>                 if con_settings['type'] == 'vpn' and
>         con_settings['id'] == name:
>                     state=dbus.Interface(proxy,
>         'org.freedesktop.DBus.Properties').Get('org.freedesktop.NetworkManager.VPN.Connection', 'VpnState')

I see you're using NM 0.8.x here, which is fairly old, but the following
may also apply to NM 0.9.x.

What you're doing here is grabbing and listing the *saved configuration*
instead of any active network connections.  There are really two parts
to NM: the persistent configuration (Connections provided by the
settings service) and the runtime state (devices and ActiveConnections).

So what you want to do is roughly the following:

1) get a proxy to the /org/freedesktop/NetworkManager object's
org.freedesktop.DBus.Properties interface
2) read the value of the "ActiveConnections" property of that object;
this will be an array of object paths
3) for each of the object paths in the ActiveConnections property,
create a proxy for the org.freedesktop.DBus.Properties interface, and
read the "Vpn" property of the
"org.freedesktop.NetworkManager.Connection.Active" interface; that tells
you whether it's a VPN or not
4) if it is a VPN, use the proxy from #3 to read the "VpnState" property
of the "org.freedesktop.NetworkManager.VPN.Connection" interface


> This finds VPN connection correctly but in the last line (when trying
> to get `VpnState` property) it raises this Exception:
>             dbus.exceptions.DBusException:
>         org.freedesktop.DBus.Error.AccessDenied: Rejected send
>         message, 1 matched rules; type="method_call",
>         sender=":1.169" (uid=0 pid=20580 comm="python)
>         interface="org.freedesktop.DBus.Properties" member="Get" error
>         name="(unset)" requested_reply=0 destination=":1.36" (uid=1000
>         pid=3457 comm="nm-applet))
> What is the problem?
> _______________________________________________
> networkmanager-list mailing list
> networkmanager-list gnome org

In a world without walls or fences, what use do we have for Windows or Gates?!
Avecina: "I prefer a short life with width to a narrow one with length"

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]