Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/interactions
diff options
context:
space:
mode:
authorDaniel Girtler <blackrabbit256@gmail.com>2023-07-17 17:27:21 +1000
committerGitHub <noreply@github.com>2023-07-17 09:27:21 +0200
commit2f273868d416c3309191db8c616aae683d78370a (patch)
tree9b38c0b631774d50b037bda3cef764e8cdf740d8 /archinstall/lib/interactions
parentc67bb0b549b35ce335941c9c1cbe22f99c28f7fe (diff)
Fix network settings loading from config file (#1921)
* Fix network config error and simplify code * Update schema and exmaple --------- Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
Diffstat (limited to 'archinstall/lib/interactions')
-rw-r--r--archinstall/lib/interactions/__init__.py2
-rw-r--r--archinstall/lib/interactions/network_menu.py (renamed from archinstall/lib/interactions/network_conf.py)97
2 files changed, 43 insertions, 56 deletions
diff --git a/archinstall/lib/interactions/__init__.py b/archinstall/lib/interactions/__init__.py
index 466cfa0b..53be8e7a 100644
--- a/archinstall/lib/interactions/__init__.py
+++ b/archinstall/lib/interactions/__init__.py
@@ -1,5 +1,5 @@
from .manage_users_conf import UserList, ask_for_additional_users
-from .network_conf import ManualNetworkConfig, ask_to_configure_network
+from .network_menu import ManualNetworkConfig, ask_to_configure_network
from .utils import get_password
from .disk_conf import (
diff --git a/archinstall/lib/interactions/network_conf.py b/archinstall/lib/interactions/network_menu.py
index 18a834a1..14fc5785 100644
--- a/archinstall/lib/interactions/network_conf.py
+++ b/archinstall/lib/interactions/network_menu.py
@@ -1,10 +1,10 @@
from __future__ import annotations
import ipaddress
-from typing import Any, Optional, TYPE_CHECKING, List, Union, Dict
+from typing import Any, Optional, TYPE_CHECKING, List, Dict
from ..menu import MenuSelectionType, TextInput
-from ..models.network_configuration import NetworkConfiguration, NicType
+from ..models.network_configuration import NetworkConfiguration, NicType, Nic
from ..networking import list_interfaces
from ..output import FormattedOutput, warn
@@ -19,23 +19,22 @@ class ManualNetworkConfig(ListManager):
subclass of ListManager for the managing of network configurations
"""
- def __init__(self, prompt: str, ifaces: List[NetworkConfiguration]):
+ def __init__(self, prompt: str, preset: List[Nic]):
self._actions = [
str(_('Add interface')),
str(_('Edit interface')),
str(_('Delete interface'))
]
+ super().__init__(prompt, preset, [self._actions[0]], self._actions[1:])
- super().__init__(prompt, ifaces, [self._actions[0]], self._actions[1:])
-
- def reformat(self, data: List[NetworkConfiguration]) -> Dict[str, Optional[NetworkConfiguration]]:
+ def reformat(self, data: List[Nic]) -> Dict[str, Optional[Nic]]:
table = FormattedOutput.as_table(data)
rows = table.split('\n')
# these are the header rows of the table and do not map to any User obviously
# we're adding 2 spaces as prefix because the menu selector '> ' will be put before
# the selectable rows so the header has to be aligned
- display_data: Dict[str, Optional[NetworkConfiguration]] = {f' {rows[0]}': None, f' {rows[1]}': None}
+ display_data: Dict[str, Optional[Nic]] = {f' {rows[0]}': None, f' {rows[1]}': None}
for row, iface in zip(rows[2:], data):
row = row.replace('|', '\\|')
@@ -43,16 +42,16 @@ class ManualNetworkConfig(ListManager):
return display_data
- def selected_action_display(self, iface: NetworkConfiguration) -> str:
- return iface.iface if iface.iface else ''
+ def selected_action_display(self, nic: Nic) -> str:
+ return nic.iface if nic.iface else ''
- def handle_action(self, action: str, entry: Optional[NetworkConfiguration], data: List[NetworkConfiguration]):
+ def handle_action(self, action: str, entry: Optional[Nic], data: List[Nic]):
if action == self._actions[0]: # add
- iface_name = self._select_iface(data)
- if iface_name:
- iface = NetworkConfiguration(NicType.MANUAL, iface=iface_name)
- iface = self._edit_iface(iface)
- data += [iface]
+ iface = self._select_iface(data)
+ if iface:
+ nic = Nic(iface=iface)
+ nic = self._edit_iface(nic)
+ data += [nic]
elif entry:
if action == self._actions[1]: # edit interface
data = [d for d in data if d.iface != entry.iface]
@@ -62,7 +61,7 @@ class ManualNetworkConfig(ListManager):
return data
- def _select_iface(self, data: List[NetworkConfiguration]) -> Optional[Any]:
+ def _select_iface(self, data: List[Nic]) -> Optional[str]:
all_ifaces = list_interfaces().values()
existing_ifaces = [d.iface for d in data]
available = set(all_ifaces) - set(existing_ifaces)
@@ -71,10 +70,10 @@ class ManualNetworkConfig(ListManager):
if choice.type_ == MenuSelectionType.Skip:
return None
- return choice.value
+ return choice.single_value
- def _edit_iface(self, edit_iface: NetworkConfiguration):
- iface_name = edit_iface.iface
+ def _edit_iface(self, edit_nic: Nic) -> Nic:
+ iface_name = edit_nic.iface
modes = ['DHCP (auto detect)', 'IP (static)']
default_mode = 'DHCP (auto detect)'
@@ -84,7 +83,7 @@ class ManualNetworkConfig(ListManager):
if mode.value == 'IP (static)':
while 1:
prompt = _('Enter the IP and subnet for {} (example: 192.168.0.5/24): ').format(iface_name)
- ip = TextInput(prompt, edit_iface.ip).run().strip()
+ ip = TextInput(prompt, edit_nic.ip).run().strip()
# Implemented new check for correct IP/subnet input
try:
ipaddress.ip_interface(ip)
@@ -98,7 +97,7 @@ class ManualNetworkConfig(ListManager):
while 1:
gateway = TextInput(
_('Enter your gateway (router) IP address or leave blank for none: '),
- edit_iface.gateway
+ edit_nic.gateway
).run().strip()
try:
if len(gateway) > 0:
@@ -107,8 +106,8 @@ class ManualNetworkConfig(ListManager):
except ValueError:
warn("You need to enter a valid gateway (router) IP address")
- if edit_iface.dns:
- display_dns = ' '.join(edit_iface.dns)
+ if edit_nic.dns:
+ display_dns = ' '.join(edit_nic.dns)
else:
display_dns = None
dns_input = TextInput(_('Enter your DNS servers (space separated, blank for none): '), display_dns).run().strip()
@@ -117,39 +116,24 @@ class ManualNetworkConfig(ListManager):
if len(dns_input):
dns = dns_input.split(' ')
- return NetworkConfiguration(NicType.MANUAL, iface=iface_name, ip=ip, gateway=gateway, dns=dns, dhcp=False)
+ return Nic(iface=iface_name, ip=ip, gateway=gateway, dns=dns, dhcp=False)
else:
# this will contain network iface names
- return NetworkConfiguration(NicType.MANUAL, iface=iface_name)
+ return Nic(iface=iface_name)
-def ask_to_configure_network(
- preset: Union[NetworkConfiguration, List[NetworkConfiguration]]
-) -> Optional[NetworkConfiguration | List[NetworkConfiguration]]:
+def ask_to_configure_network(preset: Optional[NetworkConfiguration]) -> Optional[NetworkConfiguration]:
"""
Configure the network on the newly installed system
"""
- network_options = {
- 'none': str(_('No network configuration')),
- 'iso_config': str(_('Copy ISO network configuration to installation')),
- 'network_manager': str(_('Use NetworkManager (necessary to configure internet graphically in GNOME and KDE)')),
- 'manual': str(_('Manual configuration'))
- }
- # for this routine it's easier to set the cursor position rather than a preset value
- cursor_idx = None
-
- if preset and not isinstance(preset, list):
- if preset.type == 'iso_config':
- cursor_idx = 0
- elif preset.type == 'network_manager':
- cursor_idx = 1
-
+ options = {n.display_msg(): n for n in NicType}
+ preset_val = preset.type.display_msg() if preset else None
warning = str(_('Are you sure you want to reset this setting?'))
choice = Menu(
_('Select one network interface to configure'),
- list(network_options.values()),
- cursor_index=cursor_idx,
+ list(options.keys()),
+ preset_values=preset_val,
sort=False,
allow_reset=True,
allow_reset_warning_msg=warning
@@ -158,15 +142,18 @@ def ask_to_configure_network(
match choice.type_:
case MenuSelectionType.Skip: return preset
case MenuSelectionType.Reset: return None
-
- if choice.value == network_options['none']:
- return None
- elif choice.value == network_options['iso_config']:
- return NetworkConfiguration(NicType.ISO)
- elif choice.value == network_options['network_manager']:
- return NetworkConfiguration(NicType.NM)
- elif choice.value == network_options['manual']:
- preset_ifaces = preset if isinstance(preset, list) else []
- return ManualNetworkConfig('Configure interfaces', preset_ifaces).run()
+ case MenuSelectionType.Selection:
+ nic_type = options[choice.single_value]
+
+ match nic_type:
+ case NicType.ISO:
+ return NetworkConfiguration(NicType.ISO)
+ case NicType.NM:
+ return NetworkConfiguration(NicType.NM)
+ case NicType.MANUAL:
+ preset_nics = preset.nics if preset else []
+ nics = ManualNetworkConfig('Configure interfaces', preset_nics).run()
+ if nics:
+ return NetworkConfiguration(NicType.MANUAL, nics)
return preset