Skip to content

Commit 8332fac

Browse files
Add support for Ipv6 configuration
1 parent 3263461 commit 8332fac

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
- Add support for clustering:
1212
- Add `ClusterMember` class
1313
- Add `add_cluster_member`, `list_cluster_members`, `set_cluster_peer_urls`, `remove_cluster_member`, `get_cluster_ca_certificate`, `set_cluster_ca_certificate` functions to `NetHSM`
14+
- Add support for IPv6 configuration:
15+
- Add `Ipv6Config` class
16+
- `NetworkConfig`: Add optional `ipv6` field
1417

1518
[All Changes](https://github.com/Nitrokey/nethsm-sdk-py/compare/v2.0.1...HEAD)
1619

nethsm/__init__.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
from .client import ApiException
4141
from .client.apis.tags.default_api import DefaultApi
4242
from .client.components.schema.cluster_member import ClusterMemberDict
43+
from .client.components.schema.ipv6_config import Ipv6ConfigDict
44+
from .client.components.schema.network_config import NetworkConfigDict
4345
from .client.schemas import Unset
4446

4547

@@ -356,11 +358,35 @@ class LoggingConfig:
356358
port: int
357359

358360

361+
@dataclass
362+
class Ipv6Config:
363+
cidr: Optional[str]
364+
gateway: Optional[str]
365+
366+
@staticmethod
367+
def _from_api(item: "Ipv6ConfigDict") -> "Ipv6Config":
368+
return Ipv6Config(
369+
cidr=_unset_to_optional(item.cidr),
370+
gateway=_unset_to_optional(item.gateway),
371+
)
372+
373+
359374
@dataclass
360375
class NetworkConfig:
361376
gateway: Optional[str]
362377
ip_address: str
363378
netmask: str
379+
ipv6: Optional[Ipv6Config]
380+
381+
@staticmethod
382+
def _from_api(item: "NetworkConfigDict") -> "NetworkConfig":
383+
ipv6 = _unset_to_optional(item.ipv6)
384+
return NetworkConfig(
385+
gateway=_unset_to_optional(item.gateway),
386+
ip_address=item.ipAddress,
387+
netmask=item.netmask,
388+
ipv6=Ipv6Config._from_api(ipv6) if ipv6 is not None else None,
389+
)
364390

365391

366392
@dataclass
@@ -1324,11 +1350,7 @@ def get_config_network(self) -> NetworkConfig:
13241350
response = self._get_api().config_network_get()
13251351
except Exception as e:
13261352
_handle_exception(e, state=State.OPERATIONAL, roles=[Role.ADMINISTRATOR])
1327-
return NetworkConfig(
1328-
gateway=_unset_to_optional(response.body.gateway),
1329-
ip_address=response.body.ipAddress,
1330-
netmask=response.body.netmask,
1331-
)
1353+
return NetworkConfig._from_api(response.body)
13321354

13331355
def get_config_time(self) -> datetime:
13341356
try:

0 commit comments

Comments
 (0)