22
33from dataclasses import dataclass , field
44from enum import Enum
5- from typing import TYPE_CHECKING , Any
5+ from typing import TYPE_CHECKING , NotRequired , TypedDict
66
77from ..models .profile_model import ProfileConfiguration
88
99if TYPE_CHECKING :
1010 from collections .abc import Callable
1111
12+ from archinstall .lib .installer import Installer
1213 from archinstall .lib .translationhandler import DeferredTranslation
1314
1415 _ : Callable [[str ], DeferredTranslation ]
@@ -29,6 +30,14 @@ def display_msg(self) -> str:
2930 return str (_ ('Manual configuration' ))
3031
3132
33+ class _NicSerialization (TypedDict ):
34+ iface : str | None
35+ ip : str | None
36+ dhcp : bool
37+ gateway : str | None
38+ dns : list [str ]
39+
40+
3241@dataclass
3342class Nic :
3443 iface : str | None = None
@@ -37,7 +46,7 @@ class Nic:
3746 gateway : str | None = None
3847 dns : list [str ] = field (default_factory = list )
3948
40- def table_data (self ) -> dict [str , Any ]:
49+ def table_data (self ) -> dict [str , str | bool | list [ str ] ]:
4150 return {
4251 'iface' : self .iface if self .iface else '' ,
4352 'ip' : self .ip if self .ip else '' ,
@@ -46,7 +55,7 @@ def table_data(self) -> dict[str, Any]:
4655 'dns' : self .dns
4756 }
4857
49- def json (self ) -> dict [ str , Any ] :
58+ def json (self ) -> _NicSerialization :
5059 return {
5160 'iface' : self .iface ,
5261 'ip' : self .ip ,
@@ -56,7 +65,7 @@ def json(self) -> dict[str, Any]:
5665 }
5766
5867 @staticmethod
59- def parse_arg (arg : dict [ str , Any ] ) -> Nic :
68+ def parse_arg (arg : _NicSerialization ) -> Nic :
6069 return Nic (
6170 iface = arg .get ('iface' , None ),
6271 ip = arg .get ('ip' , None ),
@@ -93,20 +102,25 @@ def as_systemd_config(self) -> str:
93102 return config_str
94103
95104
105+ class _NetworkConfigurationSerialization (TypedDict ):
106+ type : str
107+ nics : NotRequired [list [_NicSerialization ]]
108+
109+
96110@dataclass
97111class NetworkConfiguration :
98112 type : NicType
99113 nics : list [Nic ] = field (default_factory = list )
100114
101- def json (self ) -> dict [ str , Any ] :
102- config : dict [ str , Any ] = {'type' : self .type .value }
115+ def json (self ) -> _NetworkConfigurationSerialization :
116+ config : _NetworkConfigurationSerialization = {'type' : self .type .value }
103117 if self .nics :
104118 config ['nics' ] = [n .json () for n in self .nics ]
105119
106120 return config
107121
108122 @staticmethod
109- def parse_arg (config : dict [ str , Any ] ) -> NetworkConfiguration | None :
123+ def parse_arg (config : _NetworkConfigurationSerialization ) -> NetworkConfiguration | None :
110124 nic_type = config .get ('type' , None )
111125 if not nic_type :
112126 return None
@@ -126,7 +140,7 @@ def parse_arg(config: dict[str, Any]) -> NetworkConfiguration | None:
126140
127141 def install_network_config (
128142 self ,
129- installation : Any ,
143+ installation : Installer ,
130144 profile_config : ProfileConfiguration | None = None
131145 ) -> None :
132146 match self .type :
0 commit comments