From df0ffeef7e66a1308c910723e800e037c6f40d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Mon, 11 Nov 2024 09:48:14 -0300 Subject: [PATCH 1/2] core: libs: commonwealth: Change DHCP range api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- .../commonwealth/utils/DHCPServerManager.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/libs/commonwealth/commonwealth/utils/DHCPServerManager.py b/core/libs/commonwealth/commonwealth/utils/DHCPServerManager.py index 1fa2cf4f9a..79aebb54b0 100644 --- a/core/libs/commonwealth/commonwealth/utils/DHCPServerManager.py +++ b/core/libs/commonwealth/commonwealth/utils/DHCPServerManager.py @@ -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 @@ -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 @@ -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 From 452a6094e214e02c19f897f3831ef60a504a428c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Mon, 11 Nov 2024 09:54:59 -0300 Subject: [PATCH 2/2] core: services: cable_guy: Move to DHCP server by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- core/services/cable_guy/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/services/cable_guy/main.py b/core/services/cable_guy/main.py index 6ae6db3670..f85486b3e2 100755 --- a/core/services/cable_guy/main.py +++ b/core/services/cable_guy/main.py @@ -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)]), ]