From 6cc13bea65fd58cec1d11d11bad2d9815136abe4 Mon Sep 17 00:00:00 2001 From: Fioddor Superconcentrado Date: Wed, 16 Dec 2020 18:10:27 +0100 Subject: [PATCH] network: Minor refactoring, new is_primary() function Signed-off-by: Fioddor Superconcentrado [sunil: Made the method private to reduce the exposed API of the module] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/network.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plinth/network.py b/plinth/network.py index fd13a3625..1a79adfff 100644 --- a/plinth/network.py +++ b/plinth/network.py @@ -89,6 +89,12 @@ def get_interface_list(device_type): return interfaces +def _is_primary(connection): + """Return whether a connection is primary connection.""" + primary = get_nm_client().get_primary_connection() + return (primary and primary.get_uuid() == connection.get_uuid()) + + def get_status_from_connection(connection): """Return the current status of a connection.""" status = collections.defaultdict(dict) @@ -98,6 +104,7 @@ def get_status_from_connection(connection): status['type'] = connection.get_connection_type() status['zone'] = connection.get_setting_connection().get_zone() status['interface_name'] = connection.get_interface_name() + status['primary'] = _is_primary(connection) status['ipv4']['method'] = connection.get_setting_ip4_config().get_method() status['ipv6']['method'] = connection.get_setting_ip6_config().get_method() @@ -106,11 +113,6 @@ def get_status_from_connection(connection): setting_wireless = connection.get_setting_wireless() status['wireless']['ssid'] = setting_wireless.get_ssid().get_data() - primary_connection = get_nm_client().get_primary_connection() - status['primary'] = ( - primary_connection - and primary_connection.get_uuid() == connection.get_uuid()) - return status