Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change DHCP range api and set server as default mode #2988

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions core/libs/commonwealth/commonwealth/utils/DHCPServerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import time
from ipaddress import IPv4Address, IPv4Interface, IPv4Network
from typing import Any, List, Optional, Union
from typing import Any, List, Optional, Tuple, Union

import psutil
from loguru import logger
Expand All @@ -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: Tuple[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
2 changes: 1 addition & 1 deletion core/services/cable_guy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

if args.default_config == "bluerov2":
default_configs = [
NetworkInterface(name="eth0", addresses=[InterfaceAddress(ip="192.168.2.2", mode=AddressMode.Unmanaged)]),
NetworkInterface(name="eth0", addresses=[InterfaceAddress(ip="192.168.2.2", mode=AddressMode.Server)]),
NetworkInterface(name="usb0", addresses=[InterfaceAddress(ip="192.168.3.1", mode=AddressMode.Server)]),
]

Expand Down
Loading