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



Thank you very much

On Thu, Jun 28, 2012 at 7:55 PM, Dan Williams <dcbw redhat com> wrote:
On Thu, 2012-06-28 at 07:34 +0430, Ariyan wrote:
> Hi
> 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)

For listing any configured VPN connection, you use the code you posted
originally.  That talks to the configuration store.  Again, the objects
from the config store (the "settings service") are just static
configuration.  When "activating" them, you apply their configuration to
a network interface and then they are active.

If you want to list all VPN connections, and show which ones are active,
you would do something like this:

1) get all the active connections, check which ones are VPN, and then
read the 'connection' property, which is the object path of that active
connections backing configuration object (from the settings service)

2) read all connections from the settings service, and iterate through
them; when the connection's path matches the path from (1) that means
that this configuration has been applied to an interface and is
"active", and then you can show the VpnState.

Dan

>
> 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
>
>         Dan
>
>         >
>         >
>         > 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
>         > https://mail.gnome.org/mailman/listinfo/networkmanager-list
>
>
>
>
>
> --
> 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"
>
>





--
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]