Re: Update settings on a NM.RemoteConnection with python



On Sat, Aug 18, 2018 at 12:20:53AM +0000, infirit via networkmanager-list wrote:
Hi,

I found that there is NM.RemoteConnection.replace_settings that takes a
GLib.Variant but I can't figure out what it needs to contain.

Take the below SimpleConnection for a bluetooth dun connection how would
I update for example the apn?

conn = NM.SimpleConnection()
sett_conn = conn_sett = NM.SettingConnection(type='bluetooth', id='someid')
sett_bt = NM.SettingBluetooth(type='dun', bdaddr='bdaddr')
sett_gsm = NM.SettingGsm(apn='apn', number='number')

conn.add_setting(sett_conn)
conn.add_setting(sett_gsm)
conn.add_setting(sett_bt)

#add connection with client

remote_conn = client.get_connection_by_id('someid')
remote_conn.replace_settings(???????)

What is the correct format string for the GLib.Variant and could you
give an example for updating the apn?

Hi,

if you are trying to update a property of a connection, you can use
something like this:


c = client.get_connection_by_id(id)
s_gsm = c.get_setting_gsm()
s_gsm.set_property(NM.SETTING_GSM_APN, "xyz")
try:
    c.commit_changes(True, None)
    print("The connection profile has been updated.")
except Exception as e:
    sys.stderr.write("Error: %s\n" % e)


See some examples here [1], especially the update-ip4-method.py one.

Beniamino

[1] https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/gi

Attachment: signature.asc
Description: PGP signature



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