From e85c9b65315498ab4701ea31c079d198eba8d9ac Mon Sep 17 00:00:00 2001 From: Werner Llácer Date: Mon, 28 Mar 2022 13:44:10 +0200 Subject: Issues with Network Management and user management in menu (#1036) * A problem with default values treatment at superusers (and users) on the main menu * Solving issues when changing the selection of nic, ask_to_configure_network failed in several places. Solved, temporarily with the creation of __getitem__ and get methods at NetworkManager * Accept old style definitions for nic * flake8 complains * log string corrected (issue 1039) * Correct exit when no disk is selected and we don't wish to continue --- archinstall/lib/models/network_configuration.py | 46 +++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/models/network_configuration.py') diff --git a/archinstall/lib/models/network_configuration.py b/archinstall/lib/models/network_configuration.py index f1ee4c3f..4b57da00 100644 --- a/archinstall/lib/models/network_configuration.py +++ b/archinstall/lib/models/network_configuration.py @@ -40,11 +40,32 @@ class NetworkConfiguration: return self.__dict__ @classmethod - def parse_arguments(cls, config: Dict[str, str]) -> Optional["NetworkConfiguration"]: + def parse_arguments(cls, config: Union[str,Dict[str, str]]) -> Optional["NetworkConfiguration"]: nic_type = config.get('type', None) if not nic_type: - return None + # old style definitions + if isinstance(config,str): # is a ISO network + return NetworkConfiguration(NicType.ISO) + elif config.get('NetworkManager'): # is a network manager configuration + return NetworkConfiguration(NicType.NM) + elif 'ip' in config: + return NetworkConfiguration( + NicType.MANUAL, + iface=config.get('nic', ''), + ip=config.get('ip'), + gateway=config.get('gateway', ''), + dns=config.get('dns', []), + dhcp=False + ) + elif 'nic' in config: + return NetworkConfiguration( + NicType.MANUAL, + iface=config.get('nic', ''), + dhcp=True + ) + else: # not recognized + return None try: type = NicType(nic_type) @@ -95,3 +116,24 @@ class NetworkConfiguration: installation.configure_nic(self) installation.enable_service('systemd-networkd') installation.enable_service('systemd-resolved') + + def get(self, key :str, default_value :Any = None) -> Any: + result = self.__getitem__(key) + if result is None: + return default_value + else: + return result + + def __getitem__(self, key :str) -> Any: + if key == 'type': + return self.type + elif key == 'iface': + return self.iface + elif key == 'gateway': + return self.gateway + elif key == 'dns': + return self.dns + elif key == 'dhcp': + return self.dhcp + else: + raise KeyError(f"key {key} not available at NetworkConfiguration") -- cgit v1.2.3-70-g09d2