feat: release v1.1.2 - hardened IP sorting with ipaddress and config sort defaults
Build and Publish Release / Build Packages and Publish (push) Successful in 10s

This commit is contained in:
soda64 committed 2026-10-03 22:18:10 +02:00
1 parent 62710d8bb7
commit 1dbbb1ce56
12 files changed
+88 -21

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
"""Universal homelab and fleet inventory collector and deduplicator."""
__version__ = "1.1.1"
__version__ = "1.1.2"
_yaml_warning_emitted = False
+6 -3
View File
@@ -120,12 +120,13 @@ def build_parser() -> argparse.ArgumentParser:
"--sort", "--sort-by",
dest="sort_by",
choices=["name", "ip"],
default="name",
help="Sort hosts by 'name' or 'ip' (default: name)."
default=None,
help="Sort hosts by 'name' or 'ip' (default: name, or config default)."
)
parser.add_argument(
"-r", "--reverse",
action="store_true",
default=None,
help="Reverse the sort order."
)
parser.add_argument(
@@ -228,7 +229,9 @@ def main(argv: Optional[List[str]] = None) -> int:
)
# 4c. Sort inventory by name or IP
inv = inv.sort(sort_by=args.sort_by, reverse=args.reverse)
sort_by = args.sort_by or app_config.sort_by or "name"
sort_reverse = args.reverse if args.reverse is not None else app_config.sort_reverse
inv = inv.sort(sort_by=sort_by, reverse=sort_reverse)
# 5. Inspection / Dry-run Mode
if args.dry_run:
+6
View File
@@ -31,6 +31,8 @@ class AppConfig:
output_linux_connector: Optional[Path] = None
output_yaml: Optional[Path] = None
output_xml: Optional[Path] = None
sort_by: str = "name"
sort_reverse: bool = False
class ConfigLoader:
"""Loads configuration with environment variable interpolation."""
@@ -197,6 +199,10 @@ class ConfigLoader:
config.default_ssh_user = defaults.get("ssh_user", config.default_ssh_user)
config.default_ssh_port = int(defaults.get("ssh_port", config.default_ssh_port))
config.conflict_policy = defaults.get("conflict_policy", config.conflict_policy)
if "sort_by" in defaults:
config.sort_by = str(defaults["sort_by"])
if "sort_reverse" in defaults:
config.sort_reverse = bool(defaults["sort_reverse"])
# Parse destinations
destinations = data.get("destinations", {})
+12 -6
View File
@@ -1,3 +1,4 @@
import ipaddress
from dataclasses import dataclass, field
from typing import Dict, List, Optional, Any
@@ -63,14 +64,19 @@ class InventoryData:
def ip_sort_key(ip: str):
clean_ip = (ip or "").strip()
if not clean_ip:
return (1, ())
return (2, 0, "")
# Strip single port if present e.g. 192.168.1.1:22
if ":" in clean_ip and not clean_ip.startswith("[") and clean_ip.count(":") == 1:
clean_ip = clean_ip.split(":")[0]
# Strip CIDR prefix if present e.g. 192.168.1.1/24
if "/" in clean_ip:
clean_ip = clean_ip.split("/")[0]
try:
parts = tuple(int(p) for p in clean_ip.split("."))
if len(parts) == 4:
return (0, parts)
addr = ipaddress.ip_address(clean_ip)
return (0, addr.version, int(addr))
except Exception:
pass
return (2, clean_ip)
return (1, 0, clean_ip.lower())
def record_key(host: HostRecord):
if sort_by.lower() == "ip":