Skip to content

Commit

Permalink
core: libs: commonwealth: Change DHCP range api
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Nov 11, 2024
1 parent 7af6764 commit 8ea5873
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/libs/commonwealth/commonwealth/utils/DHCPServerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(
interface: str,
ipv4_gateway: IPv4Address,
subnet_mask: Optional[IPv4Address] = None,
ipv4_lease_range: Optional[tuple[IPv4Address, IPv4Address]] = None,
lease_range: Union[int, int] = (101, 200),
lease_time: str = "24h",
) -> None:
self._subprocess: Optional[Any] = None
Expand All @@ -32,9 +32,15 @@ def __init__(
subnet_mask = IPv4Address("255.255.255.0")
self._subnet_mask = subnet_mask

if ipv4_lease_range is None:
# If no lease-range is defined we offer all available IPs for lease
ipv4_lease_range = (list(self.ipv4_network.hosts())[100], list(self.ipv4_network.hosts())[199])
if 0 < lease_range[0] < 256 and 0 < lease_range[1] < 256 and lease_range[0] < lease_range[1]:
ipv4_lease_range = (
list(self.ipv4_network.hosts())[lease_range[0] - 1],
list(self.ipv4_network.hosts())[lease_range[1] - 1],
)
else:
logger.error(f"Outside valid lease range: {lease_range}")
ipv4_lease_range = (list(self.ipv4_network.hosts())[0], list(self.ipv4_network.hosts())[-1])

self._ipv4_lease_range = ipv4_lease_range

self._lease_time = lease_time
Expand Down

0 comments on commit 8ea5873

Please sign in to comment.