From 43f13d717adcfc7158f45573f98f74b0a17fd21f Mon Sep 17 00:00:00 2001 From: Fredrick Amnehagen Date: Thu, 5 Feb 2026 19:27:34 +0100 Subject: [PATCH] feat: expand free IP discovery to 10.32.70.x - 10.32.80.x range --- README.md | 2 +- infra_cli/dns.py | 61 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index d978e18..0792b1e 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ infra proxmox create-lxc 12150 local:vztmpl/debian-13-standard "new-app" "10.32. ``` ### 3. Networking (IP, DNS & DHCP) -Assign a static identity to your new machine. The CLI helps you find free addresses in the dedicated agent pool (`10.32.70.0/24`). +Assign a static identity to your new machine. The CLI helps you find free addresses in the dedicated agent pool (`10.32.70.0/24` through `10.32.80.0/24`). ```bash # Find the next available IP for your project diff --git a/infra_cli/dns.py b/infra_cli/dns.py index 079ee9f..5461964 100644 --- a/infra_cli/dns.py +++ b/infra_cli/dns.py @@ -57,23 +57,46 @@ class DNSManager: dns = self.exec_lxc(f"cat {self.dns_file}").stdout return {"hosts": hosts, "dns": dns} - def get_free_ips(self, range_start=1, range_end=254, subnet="10.32.70"): - """Finds free IPs in the specified range by checking both static and dynamic leases""" - # 1. Get all static IPs from dhcp-hosts.conf and dynamic-hosts.conf - static_configs = self.exec_lxc(f"cat /etc/dnsmasq.d/dhcp-hosts.conf {self.hosts_file} 2>/dev/null").stdout - import re - used_ips = set(re.findall(r'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}', static_configs)) - - # 2. Get all active dynamic leases - leases = self.exec_lxc("cat /var/lib/misc/dnsmasq.leases 2>/dev/null").stdout - used_ips.update(set(re.findall(r'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}', leases))) + def get_free_ips(self, start_subnet=70, end_subnet=80): - # 3. Find first available in the agent range - free_ips = [] - for i in range(range_start, range_end + 1): - candidate = f"{subnet}.{i}" - if candidate not in used_ips: - free_ips.append(candidate) - if len(free_ips) >= 10: # Just return the top 10 - break - return free_ips \ No newline at end of file + """Finds free IPs in the range 10.32.[70-80].1-254 by checking both static and dynamic leases""" + + # 1. Get all static IPs from dhcp-hosts.conf and dynamic-hosts.conf + + static_configs = self.exec_lxc(f"cat /etc/dnsmasq.d/dhcp-hosts.conf {self.hosts_file} 2>/dev/null").stdout + + import re + + used_ips = set(re.findall(r'10\.32\.[0-9]{1,3}\.[0-9]{1,3}', static_configs)) + + + + # 2. Get all active dynamic leases + + leases = self.exec_lxc("cat /var/lib/misc/dnsmasq.leases 2>/dev/null").stdout + + used_ips.update(set(re.findall(r'10\.32\.[0-9]{1,3}\.[0-9]{1,3}', leases))) + + + + # 3. Find first available in the expanded agent range + + free_ips = [] + + for subnet_idx in range(start_subnet, end_subnet + 1): + + for host_idx in range(1, 255): + + candidate = f"10.32.{subnet_idx}.{host_idx}" + + if candidate not in used_ips: + + free_ips.append(candidate) + + if len(free_ips) >= 10: # Return top 10 + + return free_ips + + return free_ips + + \ No newline at end of file