|
3 | 3 | from archinstall.lib.models.profile import ProfileConfiguration |
4 | 4 |
|
5 | 5 |
|
6 | | -class NetworkHandler: |
7 | | - def install_network_config( |
8 | | - self, |
9 | | - network_config: NetworkConfiguration, |
10 | | - installation: Installer, |
11 | | - profile_config: ProfileConfiguration | None = None, |
12 | | - ) -> None: |
13 | | - match network_config.type: |
14 | | - case NicType.ISO: |
15 | | - _ = installation.copy_iso_network_config( |
16 | | - enable_services=True, # Sources the ISO network configuration to the install medium. |
17 | | - ) |
18 | | - case NicType.NM | NicType.NM_IWD: |
19 | | - # Install NetworkManager package for both cases |
20 | | - packages = ['networkmanager'] |
21 | | - # Default back-end only for non-iwd |
22 | | - if network_config.type == NicType.NM: |
23 | | - packages.append('wpa_supplicant') |
24 | | - |
25 | | - installation.add_additional_packages(packages) |
26 | | - |
27 | | - # Desktop profile -> Always add applet |
28 | | - if profile_config and profile_config.profile: |
29 | | - if profile_config.profile.is_desktop_profile(): |
30 | | - installation.add_additional_packages('network-manager-applet') |
31 | | - |
32 | | - installation.enable_service('NetworkManager.service') |
33 | | - if network_config.type == NicType.NM_IWD: |
34 | | - # NM_IWD special handling |
35 | | - installation.configure_nm_iwd() |
36 | | - installation.disable_service('iwd.service') |
37 | | - |
38 | | - case NicType.MANUAL: |
39 | | - for nic in network_config.nics: |
40 | | - installation.configure_nic(nic) |
41 | | - installation.enable_service('systemd-networkd') |
42 | | - installation.enable_service('systemd-resolved') |
| 6 | +def install_network_config( |
| 7 | + network_config: NetworkConfiguration, |
| 8 | + installation: Installer, |
| 9 | + profile_config: ProfileConfiguration | None = None, |
| 10 | +) -> None: |
| 11 | + match network_config.type: |
| 12 | + case NicType.ISO: |
| 13 | + _ = installation.copy_iso_network_config( |
| 14 | + enable_services=True, # Sources the ISO network configuration to the install medium. |
| 15 | + ) |
| 16 | + case NicType.NM | NicType.NM_IWD: |
| 17 | + packages = ['networkmanager'] |
| 18 | + |
| 19 | + if network_config.type == NicType.NM: |
| 20 | + packages.append('wpa_supplicant') |
| 21 | + else: |
| 22 | + packages.append('iwd') |
| 23 | + |
| 24 | + if profile_config and profile_config.profile: |
| 25 | + if profile_config.profile.is_desktop_profile(): |
| 26 | + packages.append('network-manager-applet') |
| 27 | + |
| 28 | + installation.add_additional_packages(packages) |
| 29 | + installation.enable_service('NetworkManager.service') |
| 30 | + |
| 31 | + if network_config.type == NicType.NM_IWD: |
| 32 | + _configure_nm_iwd(installation) |
| 33 | + installation.disable_service('iwd.service') |
| 34 | + |
| 35 | + case NicType.MANUAL: |
| 36 | + for nic in network_config.nics: |
| 37 | + installation.configure_nic(nic) |
| 38 | + installation.enable_service('systemd-networkd') |
| 39 | + installation.enable_service('systemd-resolved') |
| 40 | + |
| 41 | + |
| 42 | +def _configure_nm_iwd(installation: Installer) -> None: |
| 43 | + nm_conf_dir = installation.target / 'etc/NetworkManager/conf.d' |
| 44 | + nm_conf_dir.mkdir(parents=True, exist_ok=True) |
| 45 | + |
| 46 | + iwd_backend_conf = nm_conf_dir / 'wifi_backend.conf' |
| 47 | + _ = iwd_backend_conf.write_text('[device]\nwifi.backend=iwd\n') |
0 commit comments