Re: Setting the IP address and other IP infos through the DBus API of Network Manager version 0.9.4+



On Sat, 2014-06-07 at 12:51 -0400, Simon Pleau wrote:
Hi,

 

I'm looking to change the IP address, prefix, gateway, etc.. of a connection through the NM and its DBus 
API but the only examples I have found are for version 0.8.x in which the Update method on 
org.freedesktop.NetworkManager.Settings.Connection can be set using the parameters returned by the method 
GetSettings. Changing the IP address was done by modifying the dictionary named 'ipv4' in the settings 
returned and passing the new settings through the Update() method on the same interface.

I am using Debian and NM 0.9.4 and with the upgrade there seems to be no more ipv4 setting returned by 
GetSettings() so I'm not sure if I can insert a new dictionary entry for the ipv4 in the returned settings 
and simply return it to Update() as before. 

Correct.  You can insert the new dictionary for the "ipv4" setting and
send all the previous settings, plus the new "ipv4" setting, back with
the Update() call.  That will save it to disk.

Also, I noticed org.freedesktop.NetworkManager.IP4config does have a property name Addresses which returns 
the type of information I am looking to modify (but missing the dns infos in the old ipv4 structure) but 
there is not way to modify and set these parameters through the interface or any other. 

The IP4Config interface is the runtime configuration, after the
Connection and it's associated settings have been applied to the
interface.  So for example, the Connection settings  might specify
"method=auto" (ie, DHCP), and then when DHCP is run, the actual IP
address and DNS settings populate the IP4Config object.  The Connection
is only the saved profile configuration information used to connect to
the network, but it does not store any runtime configuration in NM 0.9.8
and lower.

Can anybody advise me on the right course to modify the IP settings in NM 0.9.4+?

Depending on the language you're working with, there are some examples
here:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples

I've just added two python examples which should show what needs to be
done:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/dbus/update-ip4-method.py
http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/gi/update-ip4-method.py

Let me know if you have more questions!

Dan



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