mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
network: Add method to re-activate connections after an update
- When a connection is updated with newer settings, the changes don't reflect unless the connection is deactivated and reactivated. Add a convenience method to achieve this. - Don't perform any operation if the connection is not active. - Wait until connection is deactivated before reactivating Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
42569d75ec
commit
f444fba6ea
@ -22,6 +22,7 @@ import collections
|
|||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
@ -515,6 +516,33 @@ def deactivate_connection(connection_uuid):
|
|||||||
return active_connection
|
return active_connection
|
||||||
|
|
||||||
|
|
||||||
|
def reactivate_connection(connection_uuid):
|
||||||
|
"""Find and re-activate a network connection to reflect new changes.
|
||||||
|
|
||||||
|
If connection was not active to begin with, do nothing.
|
||||||
|
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
deactivate_connection(connection_uuid)
|
||||||
|
except ConnectionNotFound:
|
||||||
|
return # Connection was not active to start with
|
||||||
|
|
||||||
|
# deactivate_connection() is a synchronous call. However, it returns before
|
||||||
|
# the connection is fully deactivated. When re-activating such connections,
|
||||||
|
# sometimes, we get a "Authorization request cancelled" error. So, wait
|
||||||
|
# until the connection is fully deactivated. XXX: Perform proper
|
||||||
|
# asynchronous waiting instead of polling. Also find a way to avoid the
|
||||||
|
# problem altogether.
|
||||||
|
for index in range(10): # pylint: disable=unused-variable
|
||||||
|
try:
|
||||||
|
get_active_connection(connection_uuid)
|
||||||
|
time.sleep(0.1)
|
||||||
|
except ConnectionNotFound:
|
||||||
|
break
|
||||||
|
|
||||||
|
activate_connection(connection_uuid)
|
||||||
|
|
||||||
|
|
||||||
def delete_connection(connection_uuid):
|
def delete_connection(connection_uuid):
|
||||||
"""Delete an exiting connection from network manager.
|
"""Delete an exiting connection from network manager.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user