| 108 | |
| 109 | @dataclass |
| 110 | class NetworkConfiguration(SubConfig): |
| 111 | type: NicType |
| 112 | nics: list[Nic] = field(default_factory=list) |
| 113 | |
| 114 | @override |
| 115 | def json(self) -> _NetworkConfigurationSerialization: |
| 116 | config: _NetworkConfigurationSerialization = {'type': self.type.value} |
| 117 | if self.nics: |
| 118 | config['nics'] = [n.json() for n in self.nics] |
| 119 | |
| 120 | return config |
| 121 | |
| 122 | @override |
| 123 | def summary(self) -> str: |
| 124 | return self.type.display_msg() |
| 125 | |
| 126 | @classmethod |
| 127 | def parse_arg(cls, config: _NetworkConfigurationSerialization) -> Self | None: |
| 128 | nic_type = config.get('type', None) |
| 129 | if not nic_type: |
| 130 | return None |
| 131 | |
| 132 | match NicType(nic_type): |
| 133 | case NicType.ISO: |
| 134 | return cls(NicType.ISO) |
| 135 | case NicType.NM: |
| 136 | return cls(NicType.NM) |
| 137 | case NicType.NM_IWD: |
| 138 | return cls(NicType.NM_IWD) |
| 139 | case NicType.IWD: |
| 140 | return cls(NicType.IWD) |
| 141 | case NicType.MANUAL: |
| 142 | nics_arg = config.get('nics', []) |
| 143 | if nics_arg: |
| 144 | nics = [Nic.parse_arg(n) for n in nics_arg] |
| 145 | return cls(NicType.MANUAL, nics) |
| 146 | |
| 147 | return None |
| 148 | |
| 149 | |
| 150 | @dataclass |
no outgoing calls