refactor: update lib modules (common, dnsmasq, logging, network, state, nginx)
This commit is contained in:
+54
-4
@@ -20,7 +20,48 @@ DATA_DIR = PROJECT_DIR / "data" / "networkd"
|
||||
|
||||
DEFAULT_CONFIG: dict[str, Any] = {"interfaces": {}}
|
||||
|
||||
KNOWN_INTERFACE_KEYS: set[str] = {
|
||||
"addresses",
|
||||
"ipv6_addresses",
|
||||
"gateway",
|
||||
"ipv6_gateway",
|
||||
"dns",
|
||||
"ipv6_dns",
|
||||
"domains",
|
||||
"ipv6_domains",
|
||||
"dns_default_route",
|
||||
"dhcp",
|
||||
"routes",
|
||||
"bind_carrier",
|
||||
"ignore_carrier_loss",
|
||||
"keep_configuration",
|
||||
"configure_without_carrier",
|
||||
"link_local_addressing",
|
||||
"ipv6_link_local_address_generation_mode",
|
||||
"ipv6_stable_secret_address",
|
||||
"ipv4_ll_start_address",
|
||||
"ipv4_ll_route",
|
||||
"default_route_on_device",
|
||||
"ipv6_hop_limit",
|
||||
"ipv6_retransmission_time_sec",
|
||||
"ipv4_duplicate_address_detection_timeout_sec",
|
||||
"ipv4_reverse_path_filter",
|
||||
"ipv4_accept_local",
|
||||
"ipv4_route_localnet",
|
||||
"ipv4_proxy_arp",
|
||||
"ipv4_proxy_arp_private_vlan",
|
||||
"ipv6_proxy_ndp",
|
||||
"ipv6_proxy_ndp_address",
|
||||
"ipv6_send_ra",
|
||||
"m_pls_routing",
|
||||
"keep_master",
|
||||
"ip_family",
|
||||
"link",
|
||||
"dhcp_client",
|
||||
}
|
||||
|
||||
__all__ = [
|
||||
"KNOWN_INTERFACE_KEYS",
|
||||
"collect_upstream_dns",
|
||||
"generate_network_files",
|
||||
"get_config",
|
||||
@@ -421,6 +462,7 @@ def parse_networkctl_status(output: str) -> dict[str, Any]:
|
||||
"addresses": [],
|
||||
"gateway": None,
|
||||
"dns": [],
|
||||
"mac": None,
|
||||
"state": "unknown",
|
||||
"link": parts[1] if len(parts) > 1 else "unknown",
|
||||
}
|
||||
@@ -440,6 +482,8 @@ def parse_networkctl_status(output: str) -> dict[str, Any]:
|
||||
dns_str = stripped.split(":", 1)[1].strip()
|
||||
if dns_str and dns_str.lower() != "n/a":
|
||||
current_iface["dns"] = [d.strip() for d in dns_str.split() if d.strip()]
|
||||
elif stripped.startswith("Hardware Address:"):
|
||||
current_iface["mac"] = stripped.split(":", 2)[2].strip()
|
||||
elif stripped.startswith("Addresses:"):
|
||||
addr_str = stripped.split(":", 1)[1].strip()
|
||||
if addr_str and addr_str.lower() != "n/a":
|
||||
@@ -452,7 +496,7 @@ def parse_networkctl_status(output: str) -> dict[str, Any]:
|
||||
|
||||
|
||||
def generate_network_files(cfg: dict[str, Any]) -> dict[str, list[Path]]:
|
||||
"""Walk config and write all 50-<name>.network files to data/networkd/.
|
||||
"""Walk config and write all 99-<name>.network files to data/networkd/.
|
||||
|
||||
Also removes stale .network files that no longer match config.
|
||||
|
||||
@@ -473,7 +517,7 @@ def generate_network_files(cfg: dict[str, Any]) -> dict[str, list[Path]]:
|
||||
for iface_name, entry in interfaces_cfg.items():
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
fname = f"50-{iface_name}.network"
|
||||
fname = f"99-{iface_name}.network"
|
||||
expected_names.add(fname)
|
||||
content = render_network_file(iface_name, entry)
|
||||
out_path = DATA_DIR / fname
|
||||
@@ -584,11 +628,17 @@ def infer_dhcp_ranges(cfg: dict[str, Any]) -> dict[str, dict[str, Any]]:
|
||||
continue
|
||||
net_addr = net.network_address
|
||||
broadcast = net.broadcast_address
|
||||
_start = net_addr + 100
|
||||
_end = net_addr + 200
|
||||
_start = min(_start, broadcast - 1)
|
||||
_end = min(_end, broadcast - 1)
|
||||
if _start > _end:
|
||||
continue
|
||||
result[name] = {
|
||||
"subnet": str(net_addr),
|
||||
"prefix": net.prefixlen,
|
||||
"start": str(net_addr + 1),
|
||||
"end": str(broadcast - 1),
|
||||
"start": str(_start),
|
||||
"end": str(_end),
|
||||
}
|
||||
break
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user