mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
refactored connection activation
rafactoring of activate_connection function: as we now know the interface name of a connection we can pick the connection by this value and activate the connection.
This commit is contained in:
parent
5eda78a318
commit
58a10cdbca
@ -325,39 +325,14 @@ def activate_connection(connection_uuid):
|
|||||||
"""Find and activate a network connection."""
|
"""Find and activate a network connection."""
|
||||||
# Find the connection
|
# Find the connection
|
||||||
connection = get_connection(connection_uuid)
|
connection = get_connection(connection_uuid)
|
||||||
|
interface = connection.get_interface_name()
|
||||||
# ToDo: is the following code still needed? Because the connections
|
|
||||||
# are bound to an interface and for this reason, the device name should
|
|
||||||
# be available within connection object. So simply use:
|
|
||||||
# connection.get_interface_name() ??
|
|
||||||
|
|
||||||
# Find a suitable device
|
|
||||||
client = nm.Client.new(None)
|
client = nm.Client.new(None)
|
||||||
connection_type = connection.get_connection_type()
|
for device in client.get_devices():
|
||||||
if connection_type == 'vpn':
|
if device.get_iface() == interface:
|
||||||
for device in client.get_devices():
|
client.activate_connection_async(connection,
|
||||||
if device.get_state() == nm.DeviceState.ACTIVATED and \
|
device,
|
||||||
device.get_managed():
|
'/', None, _callback,
|
||||||
break
|
None)
|
||||||
else:
|
|
||||||
raise DeviceNotFound(connection)
|
|
||||||
else:
|
|
||||||
device_type = {
|
|
||||||
'802-11-wireless': nm.DeviceType.WIFI,
|
|
||||||
'802-3-ethernet': nm.DeviceType.ETHERNET,
|
|
||||||
'gsm': nm.DeviceType.MODEM,
|
|
||||||
}.get(connection_type, connection_type)
|
|
||||||
|
|
||||||
for device in client.get_devices():
|
|
||||||
logger.warn('Device - %s', device.get_hw_address())
|
|
||||||
if device.get_device_type() == device_type and \
|
|
||||||
device.get_state() == nm.DeviceState.DISCONNECTED:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise DeviceNotFound(connection)
|
|
||||||
|
|
||||||
client.activate_connection_async(connection, device, '/', None, _callback,
|
|
||||||
None)
|
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user