Hello.
I am working on a project where I am trying to change the wifi connection of my device in the container while it is running. I am able to add a connection and I can see it in my /etc/NetworkManager/system-connections/ however, I am unable to actually use this connection. Using this code:
wifi_dev = ''
for device in self.list_devices():
if device.type == 2:
wifi_dev = device.path
connection = {
'connection': {
'id': f'Wireless-{ssid}',
'uuid': str(uuid.uuid4()),
'type': '802-11-wireless',
'autoconnect': True},
'802-11-wireless': {
'hidden': dbus.Boolean(True),
'mode': 'infrastructure',
'ssid': dbus.ByteArray(bytes(ssid) if sys.version_info < (3, 0) else bytes(ssid, 'utf-8')),},
'802-11-wireless-security': {
'auth-alg': 'open',
'key-mgmt': 'wpa-psk',
'psk': password },
'ipv4': {'method': 'auto'},
'ipv6': {'method': 'auto'}
}
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings")
settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings")
conn_path = settings.AddConnection(connection)
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager")
nm = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
acpath = nm.ActivateConnection(conn_path, wifi_dev, '/', timeout=TIMEOUT)
proxy = bus.get_object("org.freedesktop.NetworkManager", acpath)
active_props = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
state = active_props.Get("org.freedesktop.NetworkManager.Connection.Active", "State")
print(state)
all that happens is that my device goes offline for ~5s and then reboots the container, sending the wifi back to the original network and continues as if that part of my code never happened. I was wondering if someone could give me any insight into a) what is happening and/or b) how I can fix this.