feat: set_hostname renames the host (#45) #46

Merged
christianmanivong merged 1 commits from feat/set-hostname-45 into main 2026-10-29 21:05:29 +00:00
Owner

Closes #45

set_hostname() for Linux hosts, so netOrk's apply-hostname works for them (netOrk side: NetOrk/netork#1671).

  • Short name via hostnamectl, or /etc/hostname + hostname(1) without systemd
  • /etc/hosts: lines naming the old name rewritten, else the 127.0.1.1 line; otherwise untouched (nothing appended)
  • cloud-init hosts: /etc/cloud/cloud.cfg.d/99-preserve-hostname.cfg with preserve_hostname: true
  • RFC 1123 validation before anything runs; files staged unprivileged and installed by root

In its own module (_hostname.py, HostnameMixin) because linux.py may not grow under the quality ratchet; baseline 2288 → 2286.

Not in scope: /etc/mailname/Postfix, and sharing code with napalm-proxmox's own set_hostname (that belongs to the napalm-unix split, NetOrk/netork#1105).

Tests: 253 passed (32 new), ruff, mypy, napalm-standard ratchet and check green locally.

Closes #45 `set_hostname()` for Linux hosts, so netOrk's apply-hostname works for them (netOrk side: NetOrk/netork#1671). - Short name via `hostnamectl`, or `/etc/hostname` + `hostname(1)` without systemd - `/etc/hosts`: lines naming the old name rewritten, else the `127.0.1.1` line; otherwise untouched (nothing appended) - cloud-init hosts: `/etc/cloud/cloud.cfg.d/99-preserve-hostname.cfg` with `preserve_hostname: true` - RFC 1123 validation before anything runs; files staged unprivileged and installed by root In its own module (`_hostname.py`, `HostnameMixin`) because `linux.py` may not grow under the quality ratchet; baseline 2288 → 2286. Not in scope: `/etc/mailname`/Postfix, and sharing code with napalm-proxmox's own `set_hostname` (that belongs to the napalm-unix split, NetOrk/netork#1105). Tests: 253 passed (32 new), ruff, mypy, `napalm-standard ratchet` and `check` green locally.
christianmanivong added 1 commit 2026-10-29 20:57:50 +00:00
feat: set_hostname renames the host (#45)
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m12s
driver / test (3.12) (pull_request) Successful in 1m11s
driver / test (3.13) (pull_request) Successful in 1m6s
driver / lowest (pull_request) Successful in 29s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m14s
CI / driver (pull_request) Successful in 1m15s
driver / publish (pull_request) Skipped
4108eb83dd
netOrk could save a Linux host's new name but not apply it: the driver had
no set_hostname(), so apply-hostname answered "The driver linux does not
support set_hostname()".

HostnameMixin.set_hostname() takes a bare name or an FQDN. The short name
goes to hostnamectl, or to /etc/hostname and hostname(1) without systemd.
/etc/hosts follows: every line naming the old name, else the 127.0.1.1
line; a file with neither is left alone. A cloud-init host gets
preserve_hostname: true, or its next boot restores the image's name.
Names that are not RFC 1123 hostnames are refused before anything runs.
Files are staged unprivileged and installed by root
(_install_file_as_root), never written from privileged stdin.

It lives in its own module because linux.py may not grow (quality
ratchet); the two lines it adds there are offset by a stale comment and
an import that fits on one line, so the baseline drops to 2286.
christianmanivong merged commit 2ffad23bf0 into main 2026-10-29 21:05:29 +00:00
christianmanivong deleted branch feat/set-hostname-45 2026-10-29 21:05:29 +00:00
Sign in to join this conversation.