DNS + ingress: the confirmed names, split-horizon alias, providers on https

Rick confirmed forgeway.<site>.falkvinge.net and the local-first alias
forgeway.services.falkvinge.net. README documents the alias as the front
door, the per-site names as explicit handles, and exactly how the Serenity
override keeps the alias LOCAL (host-record + local= on both Serenity
Pi-holes; the local= line closes the dual-stack AAAA bypass).

OpenClaw providers now point at the https alias with a placeholder apiKey:
OpenClaw exempts plain-IP http base URLs from needing a key but not https
hostnames. scripts/technitium.py ships the Technitium API helper used for
the records (zones / records / add / resync / logtail).

REPORT.md addendum carries the verification table from real clients at both
sites and the findings made on the way.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Dolon (Agent)
2026-09-18 14:56:12 +00:00
co-authored by Claude Fable 5.1
parent b81d39fdd4
commit 1bec7c784c
4 changed files with 320 additions and 28 deletions
+60 -15
View File
@@ -3,11 +3,12 @@
An OpenAI-compatible LLM router in front of forge's Ollama `gpt-oss:120b`. An OpenAI-compatible LLM router in front of forge's Ollama `gpt-oss:120b`.
One instance runs **per cluster**, not one central service. One instance runs **per cluster**, not one central service.
> **The name is not final.** `forgeway` is a working name (alternatives: `llm-router`, > **Names (confirmed by Rick, 2026-09-18).** Explicit per-site names
> `askforge`; per-site `forgeway.lounge` / `forgeway.serenity`). Until Rick confirms it, > `forgeway.lounge.falkvinge.net` and `forgeway.serenity.falkvinge.net` (Chalet later:
> **no DNS record and no ingress exist** — both instances are reachable by IP only. The > `forgeway.chalet.falkvinge.net`), plus the split-horizon local-first alias
> name lives in exactly one place per deployment: the `FORGEWAY_NAME` key in each > **`forgeway.services.falkvinge.net`**, which resolves to whichever instance is local to
> cluster's ConfigMap. > the querying client's site. `.services.` names are internal-only by convention: no
> entrance SAN, no external exposure, ever.
## The two endpoints ## The two endpoints
@@ -20,11 +21,20 @@ Both expose `/v1/chat/completions` (including `stream: true`) and `/v1/models`.
Where they live: Where they live:
| Site | Cluster | Base address | | Site | Cluster | Use this | Raw LB IP (DNS-independent) |
|---|---|---| |---|---|---|---|
| Lounge | Rocinante | `http://172.19.10.90` | | any | — | `https://forgeway.services.falkvinge.net` → the instance local to you | — |
| Serenity | Niðavellir | `http://172.24.10.21` | | Lounge | Rocinante | `http://forgeway.lounge.falkvinge.net` | `http://172.19.10.90` |
| Chalet | — | when the cluster exists | | Serenity | Niðavellir | `http://forgeway.serenity.falkvinge.net` | `http://172.24.10.21` |
| Chalet | — | when the cluster exists | — |
The alias is the front door. Use the per-site names only when you deliberately want a
*specific* site's instance (for example, asking the Lounge one from Serenity). HTTPS with
a valid certificate is available on the alias at both sites; the per-site names are
`http://` only — the internal ingress certificates carry `*.services.falkvinge.net` but
not `*.lounge.` / `*.serenity.` (adding those SANs to the two *internal* ingress
certificates is a one-line cert-manager change if ever wanted; the entrance bundle is
not the place).
### Calling them ### Calling them
@@ -35,7 +45,7 @@ to something already struggling. Handle the error, or degrade to your own fallba
```bash ```bash
# strict: one attempt, handle the 503 yourself # strict: one attempt, handle the 503 yourself
curl -sS -X POST http://172.19.10.90/local-strict/v1/chat/completions \ curl -sS -X POST https://forgeway.services.falkvinge.net/local-strict/v1/chat/completions \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
-d '{"model":"gpt-oss:120b","messages":[{"role":"user","content":"hello"}]}' \ -d '{"model":"gpt-oss:120b","messages":[{"role":"user","content":"hello"}]}' \
-w '\n%{http_code}\n' -w '\n%{http_code}\n'
@@ -45,7 +55,7 @@ curl -sS -X POST http://172.19.10.90/local-strict/v1/chat/completions \
import httpx import httpx
# strict — no retries on 503; that status is an answer, not a hiccup # strict — no retries on 503; that status is an answer, not a hiccup
with httpx.Client(base_url="http://172.19.10.90/local-strict/v1", timeout=600) as c: with httpx.Client(base_url="https://forgeway.services.falkvinge.net/local-strict/v1", timeout=600) as c:
r = c.post("/chat/completions", json={ r = c.post("/chat/completions", json={
"model": "gpt-oss:120b", "model": "gpt-oss:120b",
"messages": [{"role": "user", "content": "hello"}], "messages": [{"role": "user", "content": "hello"}],
@@ -58,7 +68,7 @@ with httpx.Client(base_url="http://172.19.10.90/local-strict/v1", timeout=600) a
# optimistic — fallback is already handled inside the router. # optimistic — fallback is already handled inside the router.
# Do NOT add your own retry loop: a failure here means forge AND the cloud both failed. # Do NOT add your own retry loop: a failure here means forge AND the cloud both failed.
with httpx.Client(base_url="http://172.19.10.90/local-optimistic/v1", timeout=600) as c: with httpx.Client(base_url="https://forgeway.services.falkvinge.net/local-optimistic/v1", timeout=600) as c:
r = c.post("/chat/completions", json={ r = c.post("/chat/completions", json={
"model": "gpt-oss:120b", "model": "gpt-oss:120b",
"messages": [{"role": "user", "content": "hello"}], "messages": [{"role": "user", "content": "hello"}],
@@ -72,7 +82,7 @@ non-empty api key (the router does not authenticate callers):
```python ```python
from openai import OpenAI from openai import OpenAI
client = OpenAI(base_url="http://172.19.10.90/local-optimistic/v1", api_key="unused") client = OpenAI(base_url="https://forgeway.services.falkvinge.net/local-optimistic/v1", api_key="unused")
``` ```
Every response carries `x-forgeway-backend: forge|cloud`, `x-forgeway-upstream`, Every response carries `x-forgeway-backend: forge|cloud`, `x-forgeway-upstream`,
@@ -85,7 +95,8 @@ because Ollama only accepts the first and `gpt-5.4-mini` rejects it outright.
### From OpenClaw agents ### From OpenClaw agents
The same endpoints are registered as model providers, so agents and scripts use one The same endpoints are registered as model providers (base URL = the `.services.`
alias over HTTPS, so agents get the local instance too), so agents and scripts use one
backend: backend:
``` ```
@@ -93,6 +104,40 @@ forgeway-strict/gpt-oss-120b # forge or an error
forgeway-optimistic/gpt-oss-120b # forge, else gpt-5.4-mini forgeway-optimistic/gpt-oss-120b # forge, else gpt-5.4-mini
``` ```
## DNS: how the alias finds the local instance
Every `.services.` name in the estate is a CNAME chain ending at a site's ingress-nginx,
and the authoritative `services.falkvinge.net` zone lives on the Lounge Technitium. So
at the Lounge nothing special is needed:
```
forgeway.services.falkvinge.net → forgeway.dmz.lounge.falkvinge.net → ingress.dmz.lounge.falkvinge.net → 172.19.10.11
forgeway.lounge.falkvinge.net → forgeway.dmz.lounge.falkvinge.net → … → 172.19.10.11
forgeway.serenity.falkvinge.net → forgeway.dmz.serenity.falkvinge.net → ingress.dmz.serenity.falkvinge.net → 172.24.10.11
```
Serenity's Pi-holes forward everything under `falkvinge.net` (except `serenity.`) to the
Lounge — so without an override, a Serenity client would silently get the **Lounge**
ingress and the remote instance, defeating the whole multi-site design. Both Serenity
Pi-holes therefore pin the alias to the Serenity ingress:
| Resolver | Where the override lives |
|---|---|
| `172.24.10.201` (k8s, two pods) | `serenity-cluster-config/apps/pihole/pihole.yaml` → `03-serenity-forwards.conf` |
| `172.24.1.201` (LXC) | Pi-hole v6 API: `dns.hosts` entry + `misc.dnsmasq_lines` |
Both carry `host-record=forgeway.services.falkvinge.net,172.24.10.11` **and**
`local=/forgeway.services.falkvinge.net/`. The `local=` line matters: without it an AAAA
query is still forwarded to the Lounge, and the day the Lounge ingress gains an IPv6
address every dual-stack Serenity client would prefer it and quietly reach the remote
instance — the same dual-stack bypass that defeated the Lounge overrides on 2026-08-24.
Each site's ingress serves `forgeway.services.falkvinge.net` for its own instance, so the
DNS answer alone decides which site you land on. Verified 2026-09-18 from real clients:
Lounge (OpenClaw VM, Lounge Kuma host) → `172.19.10.11`, `x-forgeway-site: lounge`;
Serenity (Niðavellir pod, both Serenity Pi-holes) → `172.24.10.11`,
`x-forgeway-site: serenity`. Never the reverse.
## Why one instance per cluster ## Why one instance per cluster
A single central router would sit on one site. The cross-site link to forge is exactly A single central router would sit on one site. The cross-site link to forge is exactly
+116 -4
View File
@@ -2,8 +2,9 @@
Two OpenAI-compatible query endpoints over forge's Ollama `gpt-oss:120b`, deployed as Two OpenAI-compatible query endpoints over forge's Ollama `gpt-oss:120b`, deployed as
one instance per cluster on Lounge (Rocinante) and Serenity (Niðavellir). Working, in one instance per cluster on Lounge (Rocinante) and Serenity (Niðavellir). Working, in
GitOps, monitored, and reachable by IP. **No DNS record and no ingress** — the name is GitOps, monitored, and reachable by IP. **Update, later the same day:** Rick confirmed the
still Rick's call. name; DNS, ingress and the split-horizon alias are live and verified — see the addendum at
the end of this file.
| | Lounge | Serenity | | | Lounge | Serenity |
|---|---|---| |---|---|---|
@@ -127,8 +128,7 @@ forgeway-optimistic/gpt-oss-120b -> PROVIDER-PROOF-OK (21.1 s)
## Open for Rick ## Open for Rick
1. **The DNS name.** Still `forgeway` as a working name. Nothing is exposed until you 1. ~~The DNS name.~~ **Resolved** — confirmed and built; see the addendum.
confirm; the name is a single ConfigMap value plus the record to be created.
2. **The pfSense SNAT exemption** described above, which would let me tighten forge's 2. **The pfSense SNAT exemption** described above, which would let me tighten forge's
firewall rule from "the mesh" to "Serenity's nodes". firewall rule from "the mesh" to "Serenity's nodes".
3. **Monitoring vs. LoRA training.** A 60 s health probe keeps `gpt-oss:120b` resident on 3. **Monitoring vs. LoRA training.** A 60 s health probe keeps `gpt-oss:120b` resident on
@@ -147,3 +147,115 @@ forgeway-optimistic/gpt-oss-120b -> PROVIDER-PROOF-OK (21.1 s)
| Kuma ops files | `deploy/kuma/ops-{lounge,serenity}.json` | | Kuma ops files | `deploy/kuma/ops-{lounge,serenity}.json` |
| OpenClaw provider config | `deploy/openclaw/providers.batch.json` | | OpenClaw provider config | `deploy/openclaw/providers.batch.json` |
| Image | `git.falkvinge.net/rick/forgeway:0.1.1` | | Image | `git.falkvinge.net/rick/forgeway:0.1.1` |
---
# Addendum, 2026-09-18 later — DNS and ingress (name confirmed by Rick)
The open item is closed. Rick confirmed `forgeway.lounge.falkvinge.net`,
`forgeway.serenity.falkvinge.net` (Chalet later) and the split-horizon local-first alias
`forgeway.services.falkvinge.net`. All three are live at both sites and verified from real
clients, and the OpenClaw providers now use the alias over HTTPS.
## What was built
**Ingress at each site** (`apps/forgeway/.../ingress.yaml`, ingress-nginx, class `nginx`),
serving `forgeway.services.falkvinge.net`, the per-site name, and the `.dmz.<site>.` CNAME
hop. No SSL redirect — this is an API for scripts, and neither httpx nor the OpenAI SDK
follow a 308 on POST by default. Buffering off and 600 s timeouts for SSE streams. HTTPS on
the alias presents a valid certificate at both sites (`*.services.falkvinge.net` is on both
internal wildcard certs); the per-site names are `http://` only, because neither internal
cert carries `*.lounge.` / `*.serenity.`. Adding those SANs to the two *internal*
cert-manager Certificates is a one-line change if ever wanted. The entrance bundle was not
touched and must not be — `.services.` stays internal-only by convention.
**DNS.** I followed the estate's existing `.services.` pattern exactly: every record in
the `services.falkvinge.net` zone is a CNAME chain that ends at a site ingress, so:
| Record | Zone (primary) | Points at |
|---|---|---|
| `forgeway.services` | `services.falkvinge.net` (Lounge Technitium) | `forgeway.dmz.lounge.falkvinge.net` |
| `forgeway.dmz.lounge` | `dmz.lounge.falkvinge.net` (Lounge) | `ingress.dmz.lounge.falkvinge.net` → 172.19.10.11 |
| `forgeway.lounge` | `lounge.falkvinge.net` (Lounge) | `forgeway.dmz.lounge.falkvinge.net` |
| `forgeway.dmz.serenity` | `dmz.serenity.falkvinge.net` (Serenity Technitium) | `ingress.dmz.serenity.falkvinge.net` → 172.24.10.11 |
| `forgeway.serenity` | `serenity.falkvinge.net` (Serenity) | `forgeway.dmz.serenity.falkvinge.net` |
**The split-horizon override — the whole point.** Serenity's Pi-holes forward everything
under `falkvinge.net` except `serenity.` to the Lounge Pi-holes, so without an override a
Serenity client would silently receive the Lounge ingress and the remote instance. Both
Serenity resolvers therefore pin the alias to the Serenity ingress `172.24.10.11`:
- `172.24.10.201` (k8s, pods `pihole` + `pihole-b` behind one Service): in GitOps,
`serenity-cluster-config/apps/pihole/pihole.yaml`. The ConfigMap is a subPath mount, so
the two pods were restarted one at a time (no outage — they share the LB).
- `172.24.1.201` (LXC): via the Pi-hole v6 API — a `dns.hosts` entry and one
`misc.dnsmasq_lines` entry (that list was empty; nothing was overwritten).
Both carry `host-record=forgeway.services.falkvinge.net,172.24.10.11` **and**
`local=/forgeway.services.falkvinge.net/`. The second line closes a real hole: with only
the host-record, AAAA queries were still forwarded to the Lounge. Today that returns no
address, but the day the Lounge ingress gains an IPv6 record every dual-stack Serenity
client would prefer it and quietly reach the *remote* instance — the same dual-stack
bypass that defeated the Lounge overrides on 2026-08-24. AAAA is now NODATA on both.
## Interpretation I made, stated plainly
The brief said each site's resolver should answer with "its own instance's MetalLB IP".
I pointed the alias at each site's **ingress-nginx** (also a MetalLB IP) rather than at the
forgeway Service IP directly, because that is how every other `.services.` name in the
estate works and it is the only way the alias gets a valid certificate. Local-first is
preserved: each site's ingress fronts only its own instance. The raw Service IPs
(`172.19.10.90`, `172.24.10.21`) remain reachable as DNS-independent doors.
## Verification — the alias returns the LOCAL instance, never the remote one
| Client | Site | `forgeway.services` → | `https://…/healthz` | `x-forgeway-site` |
|---|---|---|---|---|
| OpenClaw VM (resolvers `.1.201`/`.10.201`) | Lounge | `172.19.10.11` | 200, cert OK | `lounge` |
| Lounge Kuma LXC | Lounge | `172.19.10.11` | 200, cert OK | `lounge` |
| Niðavellir pod (CoreDNS → both Serenity Pi-holes) | Serenity | `172.24.10.11` | 200, cert OK | `serenity` |
| Serenity Kuma LXC, `@172.24.10.201` and `@172.24.1.201` | Serenity | `172.24.10.11` | 200, cert OK | `serenity` |
Per-site names, from both sites: `forgeway.lounge` → `172.19.10.11` / `site=lounge`;
`forgeway.serenity` → `172.24.10.11` / `site=serenity`. A real `local-strict` completion
through `https://forgeway.services.falkvinge.net` from the Lounge answered from forge.
OpenClaw providers `forgeway-strict/gpt-oss-120b` and `forgeway-optimistic/gpt-oss-120b`
now use the alias over HTTPS; both returned `PROVIDER-PROOF-OK` (22 s each, real
completions). One wrinkle: OpenClaw exempts a plain-IP `http://` base URL from needing a
key but demands one for an `https://` hostname (`missing-provider-auth`), so both carry
the placeholder `apiKey: forgeway-no-auth`. It is not a credential; the router ignores
the header. Side effect: `openclaw doctor --lint` now lists those two `apiKey` paths
among its "plaintext secret-bearing config fields" — a false positive for these two,
alongside the pre-existing entries it already flagged.
## Findings on the way (none caused by this work)
1. **Both LXC Pi-hole v6 APIs have no password set** — `172.19.1.201` and `172.24.1.201`
both answer `/api/auth` with `"no password set"`. Any host that can reach them can
rewrite their DNS config without credentials. It made today's LXC edit trivial; it is
worth a password. The k8s Pi-holes require auth.
2. **The Serenity Kuma LXC's default resolver is dead for internal names.** It resolves via
the UDM (`192.168.24.1`), which times out on every `falkvinge.net` name, while both
Serenity Pi-holes answer it directly and instantly. Its monitors work because they use
IPs. Same class as the Lounge Kuma resolv.conf note.
3. **Lounge `.1.202` lags Serenity zone changes by up to 15 minutes.** It is a tier-two
secondary (Serenity primary → `.10.202` → `.1.202`) and `.10.202` sends no NOTIFY, so
`.1.202` only refreshes on its 900 s SOA timer, and the Lounge Pi-holes round-robin
both Technitiums. For a quarter of an hour after any Serenity record is created, Lounge
clients get it about half the time — then negative-cache the miss for another 900 s.
I resynced `.1.202` by API for today; the log confirms it. Optional hygiene, your call:
`notify: SpecifiedNameServers → 172.19.1.202` on `.10.202`'s two Serenity secondaries.
I initially misread this last one as a month-old broken replica; the serials were simply
the primary's last-change dates. Corrected here and in memory.
## Where everything lives (additions)
| | |
|---|---|
| Lounge ingress | `lounge-cluster-config/apps/forgeway/manifests/ingress.yaml` — commits `674d09e`, `15b226e` |
| Serenity ingress + Pi-hole override | `serenity-cluster-config/apps/forgeway/ingress.yaml`, `apps/pihole/pihole.yaml` — `82fef33`, `f44dbb8`, `532ba68` |
| Technitium records | live on `172.19.1.202` and `172.24.1.202` (zone data is not in git by design) |
| LXC Pi-hole override | live on `172.24.1.201` via API (`dns.hosts` + `misc.dnsmasq_lines`) |
| Technitium helper | `scripts/technitium.py` (zones / records / add / resync / logtail) |
+21 -9
View File
@@ -2,7 +2,7 @@
{ {
"path": "models.providers.forgeway-optimistic", "path": "models.providers.forgeway-optimistic",
"value": { "value": {
"baseUrl": "http://172.19.10.90/local-optimistic/v1", "baseUrl": "https://forgeway.services.falkvinge.net/local-optimistic/v1",
"api": "openai-completions", "api": "openai-completions",
"timeoutSeconds": 600, "timeoutSeconds": 600,
"injectNumCtxForOpenAICompat": false, "injectNumCtxForOpenAICompat": false,
@@ -12,18 +12,24 @@
"name": "forgeway optimistic (forge gpt-oss:120b, cloud fallback)", "name": "forgeway optimistic (forge gpt-oss:120b, cloud fallback)",
"api": "openai-completions", "api": "openai-completions",
"reasoning": true, "reasoning": true,
"input": ["text"], "input": [
"text"
],
"contextTokens": 131072, "contextTokens": 131072,
"maxTokens": 32768, "maxTokens": 32768,
"cost": { "input": 0, "output": 0 } "cost": {
"input": 0,
"output": 0
}
} }
] ],
"apiKey": "forgeway-no-auth"
} }
}, },
{ {
"path": "models.providers.forgeway-strict", "path": "models.providers.forgeway-strict",
"value": { "value": {
"baseUrl": "http://172.19.10.90/local-strict/v1", "baseUrl": "https://forgeway.services.falkvinge.net/local-strict/v1",
"api": "openai-completions", "api": "openai-completions",
"timeoutSeconds": 600, "timeoutSeconds": 600,
"injectNumCtxForOpenAICompat": false, "injectNumCtxForOpenAICompat": false,
@@ -33,12 +39,18 @@
"name": "forgeway strict (forge gpt-oss:120b, 503 when unavailable)", "name": "forgeway strict (forge gpt-oss:120b, 503 when unavailable)",
"api": "openai-completions", "api": "openai-completions",
"reasoning": true, "reasoning": true,
"input": ["text"], "input": [
"text"
],
"contextTokens": 131072, "contextTokens": 131072,
"maxTokens": 32768, "maxTokens": 32768,
"cost": { "input": 0, "output": 0 } "cost": {
"input": 0,
"output": 0
}
} }
] ],
"apiKey": "forgeway-no-auth"
} }
} }
] ]
+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/env python3
"""Technitium DNS admin helper for the forgeway DNS work.
Credentials come from `pass` inside this process; the session token is kept in
memory and sent as a form field. Nothing secret is ever printed or put on a
command line.
tech.py <site> zones
tech.py <site> records <zone>
tech.py <site> add-cname <zone> <name> <target>
tech.py <site> add-a <zone> <name> <ip>
tech.py <site> add-zone <zone> # primary zone
tech.py <site> delete <zone> <name> <type> <value>
<site> = lounge | serenity (primary Technitium at each site)
"""
from __future__ import annotations
import json
import subprocess
import sys
import urllib.parse
import urllib.request
PRIMARY = {
"lounge": ("http://172.19.1.202:5380", "technitium/lounge/ns1-admin-password"),
"serenity": ("http://172.24.1.202:5380", "technitium/serenity/ns1-admin-password"),
# secondaries, for resync / inspection only — never add records here
"lounge-ns2": ("http://172.19.10.202:5380", "technitium/lounge/ns2-admin-password"),
"serenity-ns2": ("http://172.24.10.202:5380", "technitium/serenity/ns2-admin-password"),
}
def _pass(entry: str) -> str:
return subprocess.run(["pass", entry], capture_output=True, text=True, check=True).stdout.strip()
class Tech:
def __init__(self, site: str):
self.base, entry = PRIMARY[site]
self.token = self._call("/api/user/login", {"user": "admin", "pass": _pass(entry)}, auth=False)["token"]
def _call(self, path: str, params: dict, auth: bool = True) -> dict:
if auth:
params = {**params, "token": self.token}
data = urllib.parse.urlencode(params).encode()
req = urllib.request.Request(f"{self.base}{path}", data=data, method="POST")
with urllib.request.urlopen(req, timeout=20) as r:
body = json.loads(r.read().decode())
if body.get("status") != "ok":
raise SystemExit(f"{path}: {body.get('status')} {body.get('errorMessage', '')}")
# login puts its fields (incl. token) at the top level; everything else nests under "response"
return body.get("response", body)
def zones(self) -> list[dict]:
return self._call("/api/zones/list", {})["zones"]
def records(self, zone: str) -> list[dict]:
return self._call("/api/zones/records/get", {"domain": zone, "zone": zone, "listZone": "true"})["records"]
def add(self, zone: str, name: str, rtype: str, **kw) -> dict:
fqdn = zone if name in ("@", "") else f"{name}.{zone}"
return self._call("/api/zones/records/add", {"domain": fqdn, "zone": zone, "type": rtype, "ttl": "300", **kw})
def delete(self, zone: str, name: str, rtype: str, **kw) -> dict:
fqdn = zone if name in ("@", "") else f"{name}.{zone}"
return self._call("/api/zones/records/delete", {"domain": fqdn, "zone": zone, "type": rtype, **kw})
def add_zone(self, zone: str) -> dict:
return self._call("/api/zones/create", {"zone": zone, "type": "Primary"})
def main(argv: list[str]) -> int:
if len(argv) < 3:
print(__doc__)
return 2
site, cmd, args = argv[1], argv[2], argv[3:]
t = Tech(site)
if cmd == "zones":
for z in sorted(t.zones(), key=lambda z: z["name"]):
print(f"{z['name']:45s} {z['type']:10s} {'DISABLED' if z.get('disabled') else ''}")
elif cmd == "records":
for r in t.records(args[0]):
rd = r.get("rData", {})
val = rd.get("ipAddress") or rd.get("cname") or rd.get("nameServer") or json.dumps(rd)[:80]
print(f"{r['name']:50s} {r['type']:6s} ttl={r['ttl']:<6} {val}")
elif cmd == "add-cname":
print(json.dumps(t.add(args[0], args[1], "CNAME", cname=args[2]).get("addedRecord", {}))[:200])
elif cmd == "add-a":
print(json.dumps(t.add(args[0], args[1], "A", ipAddress=args[2]).get("addedRecord", {}))[:200])
elif cmd == "add-zone":
print(json.dumps(t.add_zone(args[0]))[:200])
elif cmd == "api":
# generic read: tech.py <host> api /api/zones/options/get zone=x [key ...]
path, params, keys = args[0], {}, []
for a in args[1:]:
(params.__setitem__(*a.split("=", 1)) if "=" in a else keys.append(a))
out = t._call(path, params)
print(json.dumps({k: out.get(k) for k in keys} if keys else out, indent=1)[:3000])
elif cmd == "logtail":
# /api/logs/download returns plain text, not JSON: tech.py <host> logtail <YYYY-MM-DD> [n]
params = urllib.parse.urlencode({"fileName": args[0], "limit": 5000, "token": t.token}).encode()
req = urllib.request.Request(f"{t.base}/api/logs/download", data=params, method="POST")
with urllib.request.urlopen(req, timeout=30) as r:
lines = r.read().decode(errors="replace").splitlines()
n = int(args[1]) if len(args) > 1 else 40
print("\n".join(l[:230] for l in lines[-n:]))
elif cmd == "resync":
# secondary zone: pull a fresh copy from its primary now instead of
# waiting for the SOA refresh timer
print(json.dumps(t._call("/api/zones/resync", {"zone": args[0]}))[:200])
elif cmd == "delete":
zone, name, rtype, value = args
key = "cname" if rtype == "CNAME" else "ipAddress"
print(json.dumps(t.delete(zone, name, rtype, **{key: value}))[:200])
else:
print(__doc__)
return 2
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv))