Re: Change IP address with libnm



On Wed, 2020-02-26 at 10:08 +0000, António Mendes wrote:
Hi Thomas.

Thank you for your help. I am new using this library so, your help is
much appreciated.
That's really what I was looking for because, right now, I am simply
calling system("nmcli con mod Wired\ connection\ 1 ...") in my test
application to modify settings and I wanted to replace that part.
I will keep you informed.

btw, libnm is glib based, so you can also use it via GObject
introspection, for example from Python or Javascript (gjs).

That tends to be faster for prototyping. See examples
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/tree/9add51ef16356da81a0fd5a8f3f0ddebeb093636/examples/python/gi

This is also what is done by various other projects:
https://github.com/linux-system-roles/network
https://github.com/nmstate/nmstate
https://github.com/rhinstaller/anaconda/tree/master/pyanaconda



For larger examples how to use libnm natively, look at
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/tree/9add51ef16356da81a0fd5a8f3f0ddebeb093636/clients
https://gitlab.gnome.org/GNOME/libnma
https://gitlab.gnome.org/GNOME/network-manager-applet


best,
Thomas



Thanks again,
António Pontinha Mendes
________________________________________
From: Thomas Haller <thaller redhat com>
Sent: 25 February 2020 17:34
To: António Mendes; networkmanager-list gnome org
Subject: Re: Change IP address with libnm

On Tue, 2020-02-25 at 17:02 +0000, António Mendes wrote:
Hi.
I tried to use the example add-connection-libnm-glib.c and adapt to
my case but without success...
I wanted to change an IP address from a connection already created
and add some 802.1X configurations.

Hi,

add-connection adds a new profile.
Basically, what `nmcli connection add ...` does.

The example you refer to is about usage of libnm. So, the
corresponding
API is nm_remote_connection_update2() ([1]). This maps to the D-Bus
call Update2 ([2]). This is what `nmcli connection modify ...` does.

[1] 
https://developer.gnome.org/libnm/1.22/NMRemoteConnection.html#nm-remote-connection-update2
[2] 
https://developer.gnome.org/NetworkManager/1.22/gdbus-org.freedesktop.NetworkManager.Settings.Connection.html#gdbus-method-org-freedesktop-NetworkManager-Settings-Connection.Update2


As always, connection profiles in NetworkManager are really just a
bunch of nested
dictionaries, that is the plain settings. There is no further logic
involved, just
create a suitable profile. If you use libnm, you probably create the
profile using the
NMConnection and NMSetting types. These represent the nested
dictionaries.

After you modify a profile, you usually need to activate it so that
your actual networking
configuration (`nmcli device`, `ip link`) changes.



best,
Thomas
www.eid.pt

EID, S.A.
Capital Social €1.100.000
N° de matricula unico 501 400 699

DISCLAIMER

Attachment: signature.asc
Description: This is a digitally signed message part



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