|
1 | 1 | from enum import Enum |
2 | | -from ipaddress import ip_network |
3 | | -from typing import List, Optional |
4 | | - |
5 | | -from pydantic import BaseModel, IPvAnyAddress, IPvAnyNetwork |
| 2 | +from ipaddress import ip_network, ip_address, IPv4Network, IPv6Network, IPv4Address, IPv6Address |
| 3 | +from typing import List, Optional, Union |
| 4 | +from pydantic import BaseModel |
6 | 5 |
|
7 | 6 |
|
8 | 7 | class AddressMode(str, Enum): |
@@ -53,24 +52,24 @@ def __hash__(self) -> int: |
53 | 52 |
|
54 | 53 | # TODO: Remove this once we update self.destination type |
55 | 54 | @property |
56 | | - def destination_parsed(self) -> IPvAnyNetwork: |
57 | | - return IPvAnyNetwork(self.destination) |
| 55 | + def destination_parsed(self) -> Union[IPv4Network, IPv6Network]: |
| 56 | + return ip_network(self.destination) |
58 | 57 |
|
59 | 58 | # TODO: Remove this once we update self.destination type |
60 | 59 | @destination_parsed.setter |
61 | | - def destination_parsed(self, ip: IPvAnyNetwork) -> None: |
| 60 | + def destination_parsed(self, ip: Union[IPv4Network, IPv6Network]) -> None: |
62 | 61 | self.destination = str(ip) |
63 | 62 |
|
64 | 63 | # TODO: Remove this once we update self.next_hop type |
65 | 64 | @property |
66 | | - def next_hop_parsed(self) -> Optional[IPvAnyAddress]: |
| 65 | + def next_hop_parsed(self) -> Optional[Union[IPv4Address, IPv6Address]]: |
67 | 66 | if self.gateway is None: |
68 | 67 | return None |
69 | | - return IPvAnyAddress(self.gateway) |
| 68 | + return ip_address(self.gateway) |
70 | 69 |
|
71 | 70 | # TODO: Remove this once we update self.next_hop type |
72 | 71 | @next_hop_parsed.setter |
73 | | - def next_hop_parsed(self, ip: Optional[IPvAnyAddress]) -> None: |
| 72 | + def next_hop_parsed(self, ip: Optional[Union[IPv4Address, IPv6Address]]) -> None: |
74 | 73 | self.gateway = str(ip) if ip else None |
75 | 74 |
|
76 | 75 | @property |
|
0 commit comments