mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-09 04:06:42 +00:00
Relocates `cli/meta/{ports,networks/suggest}` to
`cli/contributing/network/{ports,address/suggest}` so port and subnet
allocators live alongside the rest of the contributor-side tooling
(mirror, update, changelog) instead of `meta`. Mirrors the tests
into `tests/unit/cli/contributing/network/` and renames the contract
docs to `docs/contributing/tools/network/{port,address}.md`. Prog
names update from `cli meta ports suggest` / `cli meta networks
suggest` to `cli contributing network ports suggest` / `cli
contributing network address suggest`; the corresponding lint
references and `utils.meta.scan` docstring follow.
Adds a third subcommand: `cli contributing network diagnose`
(stdlib-only DNS / TCP / TLS / PMTU probe against the standard
infrastructure hosts plus interface MTU, `/etc/resolv.conf`,
`/etc/hosts`, proxy env, CA-bundle summaries). Split across `cli.py`
(orchestration), `config.py` (SPOT for hosts / per-distro install
commands), `format.py` (output + subprocess helpers), `tools.py`
(distro-aware auto-install of `iputils-ping` + `iproute2`),
`report.py` (system-info dumps + IPv6-default-route detection), and
`probes.py` (per-host probes). Exposed as `make debug-network`.
Companion `docs/contributing/actions/debugging/network.md` absorbs
the diagnose-tool walkthrough (incl. how to read MTU-induced TLS
handshake timeouts) so the merged page covers DNS / MTU / IPv6 /
connectivity end-to-end.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
115 lines
3.5 KiB
Python
115 lines
3.5 KiB
Python
"""Per-system info dumps: identity, interfaces+MTU, /etc/resolv.conf, /etc/hosts, proxies, CA bundles."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import socket
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
from cli.contributing.network.diagnose.config import (
|
|
CA_BUNDLE_CANDIDATES,
|
|
PROXY_ENV_KEYS,
|
|
)
|
|
from cli.contributing.network.diagnose.format import cmd_capture, line, section
|
|
|
|
|
|
def show_identity() -> None:
|
|
section("identity")
|
|
line("timestamp", time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()))
|
|
line("hostname", socket.gethostname())
|
|
line("fqdn", socket.getfqdn())
|
|
line("python", sys.version.split()[0])
|
|
|
|
|
|
def show_resolv() -> None:
|
|
section("/etc/resolv.conf")
|
|
try:
|
|
content = Path("/etc/resolv.conf").read_text() # nocheck: cache-read
|
|
except OSError as e:
|
|
print(f" unreadable: {e}")
|
|
return
|
|
print(content.rstrip())
|
|
|
|
|
|
def show_hosts() -> None:
|
|
section("/etc/hosts")
|
|
try:
|
|
content = Path("/etc/hosts").read_text() # nocheck: cache-read
|
|
except OSError as e:
|
|
print(f" unreadable: {e}")
|
|
return
|
|
print(content.rstrip())
|
|
|
|
|
|
def show_iface_routes() -> None:
|
|
section("interfaces + MTU")
|
|
sys_net = Path("/sys/class/net")
|
|
if sys_net.is_dir():
|
|
for iface in sorted(p.name for p in sys_net.iterdir()):
|
|
mtu_path = sys_net / iface / "mtu"
|
|
try:
|
|
mtu = mtu_path.read_text().strip() # nocheck: cache-read
|
|
except OSError:
|
|
mtu = "?"
|
|
line(iface, f"mtu={mtu}")
|
|
rc, out = cmd_capture(["ip", "route"])
|
|
if rc == 0 and out.strip():
|
|
print("\n>>> ip route")
|
|
print(out.rstrip())
|
|
return
|
|
|
|
proc_route = Path("/proc/net/route")
|
|
if not proc_route.is_file():
|
|
return
|
|
print("\n>>> /proc/net/route (default route only)")
|
|
route_text = proc_route.read_text() # nocheck: cache-read
|
|
for raw in route_text.splitlines()[1:]:
|
|
parts = raw.split()
|
|
if len(parts) >= 8 and parts[1] == "00000000":
|
|
gw_hex = parts[2]
|
|
gw_ip = ".".join(str(int(gw_hex[i : i + 2], 16)) for i in (6, 4, 2, 0))
|
|
print(f" default via {gw_ip} dev {parts[0]}")
|
|
return
|
|
|
|
|
|
def show_proxies() -> None:
|
|
section("proxy env vars")
|
|
for key in PROXY_ENV_KEYS:
|
|
line(key, os.environ.get(key, "<unset>"))
|
|
|
|
|
|
def show_ca_bundle() -> None:
|
|
section("CA bundle summary")
|
|
for candidate in CA_BUNDLE_CANDIDATES:
|
|
p = Path(candidate)
|
|
if not p.is_file():
|
|
line(candidate, "<missing>")
|
|
continue
|
|
try:
|
|
size = p.stat().st_size
|
|
content = p.read_text(errors="ignore") # nocheck: cache-read
|
|
count = content.count("BEGIN CERTIFICATE")
|
|
line(candidate, f"{size}B, {count} certs")
|
|
except OSError as e:
|
|
line(candidate, f"unreadable: {e}")
|
|
|
|
|
|
def has_ipv6_default_route() -> bool:
|
|
"""True when an IPv6 default route exists on a non-loopback interface."""
|
|
rc, out = cmd_capture(["ip", "-6", "route", "show", "default"])
|
|
if rc == 0:
|
|
for raw in out.splitlines():
|
|
if "default" in raw and " dev lo" not in raw:
|
|
return True
|
|
try:
|
|
v6_text = Path("/proc/net/ipv6_route").read_text() # nocheck: cache-read
|
|
for raw in v6_text.splitlines():
|
|
parts = raw.split()
|
|
if len(parts) >= 10 and parts[0] == "0" * 32 and parts[-1] != "lo":
|
|
return True
|
|
except OSError:
|
|
pass
|
|
return False
|