Re: Managing a connection using D-Bus API



On Thu, 2010-07-01 at 15:56 +0300, Ozan Çağlayan wrote:
> Hi,
> 
> I'm writing a Python script which uses python-networkmanager for communicating 
> with NetworkManager's D-Bus facilities.
> 
> I want to disconnect an active connection. Using the nm-applet, we are not 
> forced to write a MAC address for a connection.
> 
> Say that I want to disconnect the device eth0 AA:BB:CC:DD:EE:FF which is 
> currently connected to the connection with the ID "WiredConnection1".
> 
> Since the connection doesn't have an hwaddress set, I can't match the 
> connection with the device. What I want to do is sth like that:
> 
> python network.py down WiredConnection1
> 
> Is it ever possible (without providing connection UUID)?

Sort of.  There are a number of ways to get where you want.  Remember
though that the "id" (ie WiredConnection1) is not unique, that's what
the UUID is for.  So it's possible (though unlikely) that you could end
up with two WiredConnection1 connections with different UUIDs, depending
on what the user decided to call them.  The UI attempts to discourage
that, but there are some reasons for letting that happen.

Also remember that the UUID can't really be used to deactivate a
connection because connections are just *configuration* required to
connect to a specific network and can be applied to any device that's
compatible with the connection; thus you can have two ethernet devices
plugged in that are using the same NM connection, and thus the same
UUID.

To make all that somewhat simpler, NM uses the concept of
ActiveConnection objects which "own" both a device and an NMConnection.
Whenever you call the ActivateConnection() method, a new
ActiveConnection object path is returned to you; this is the same thing
you pass to DeactivateConnection() because you are stopping that active
connection, not the NMConnection configuration or the device.  An
ActiveConnection object can "own" more than one device to support
configurations like bridging and bonding.  The ActiveConnection object
is also the thing that has the "this connection owns the default route"
indicator which nm-applet uses to decide which icon to show, for
example.

In any case, you appear to have the device's interface name.  You would
then:

1) org.freedesktop.NetworkManager.GetDevices
2) iterate through the list and use org.freedesktop.DBus.Properties.Get
to retrieve the "Interface" property of the
org.freedesktop.NetworkManager.Device interface
3) when you get the device you're looking for, call the "Disconnect()"
method on that device's object path on the
org.freedesktop.NetworkManager.Device interface

I've added a python example of that here:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=72399bfa2cab6de881518b4b473c5b2a76f058b8

Dan




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