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:
Sunil Mohan Adapa authored and James Valleroy committed 2020-01-18 13:52:32 -05:00
1 parent 42569d75ec
commit f444fba6ea
1 file changed
+28
+28
View File
@@ -22,6 +22,7 @@ import collections
import logging
import socket
import struct
import time
import uuid
from django.utils.translation import ugettext_lazy as _
@@ -515,6 +516,33 @@ def deactivate_connection(connection_uuid):
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):
"""Delete an exiting connection from network manager.