From f6e694f0283e3414619a1ddeb24ac9fe20bfa5b1 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Fri, 19 Jun 2026 21:15:30 +0200 Subject: [PATCH] fix: migrate /etc/pve/nodes// before reboot in set_hostname MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After renaming /etc/hostname, Proxmox boots under the new node name and looks for VM/CT configs in /etc/pve/nodes//qemu-server/. Without migrating the directory first, all VMs appear missing after the reboot. Now renames /etc/pve/nodes// to /etc/pve/nodes// while pve-cluster is running (pmxcfs supports live rename). Also replaces pvecm updatecerts -f with pvenode cert create --overwrite — pvecm updatecerts restarts pve-cluster, unmounts /etc/pve and can crash VMs. Co-Authored-By: Claude Sonnet 4.6 --- napalm_proxmox/system_mixin.py | 41 ++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/napalm_proxmox/system_mixin.py b/napalm_proxmox/system_mixin.py index c6b52a6..7b70efb 100644 --- a/napalm_proxmox/system_mixin.py +++ b/napalm_proxmox/system_mixin.py @@ -622,8 +622,10 @@ class ProxmoxSystemMixin: installed. 5. Runtime hostname — applied immediately via ``hostname(1)`` so SSH and the Proxmox API see the new name without a reboot. - 6. Proxmox node TLS certificate — regenerated via - ``pvecm updatecerts -f``. + 6. ``/etc/pve/nodes/`` → ``/etc/pve/nodes/`` rename so + VM/CT configs are found after the reboot under the new node name. + 7. Proxmox node TLS certificate — regenerated via + ``pvenode cert create --overwrite``. **Important**: the Proxmox *node name* (shown in the web UI and stored in ``/etc/pve/nodes//``) only changes after a full reboot. @@ -692,14 +694,35 @@ class ProxmoxSystemMixin: # ── 5. Apply hostname at runtime ───────────────────────────────── self._exec_ssh_command(f"hostname '{short_hostname}'") - # ── 6. Regenerate Proxmox node TLS certificate ─────────────────── - # pvecm updatecerts -f is the canonical command for both standalone - # and clustered nodes (PVE 6+). Fall back to restarting pveproxy, - # which regenerates the certificate automatically when it detects a - # hostname change. + # ── 6. Migrate /etc/pve/nodes/ → /etc/pve/nodes/ ────── + # Proxmox stores VM and CT configs under /etc/pve/nodes//. + # This rename MUST happen before the reboot while pve-cluster is + # running and pmxcfs is mounted — pmxcfs supports the rename live. + # Without this step the node boots under the new hostname, finds an + # empty /etc/pve/nodes// and all VMs appear missing. + if old_short and old_short != short_hostname: + pve_old = f"/etc/pve/nodes/{old_short}" + pve_new = f"/etc/pve/nodes/{short_hostname}" + migrate_out = self._exec_ssh_command( + f"if [ -d '{pve_old}' ] && [ ! -e '{pve_new}' ]; then" + f" mv '{pve_old}' '{pve_new}'" + f" && echo 'migrated {pve_old} -> {pve_new}';" + f"elif [ -d '{pve_new}' ]; then" + f" echo 'target already exists, skipping migration';" + f"else" + f" echo 'source {pve_old} not found, skipping migration';" + f"fi" + ) + logger.info("Proxmox node dir migration: %s", migrate_out) + + # ── 7. Regenerate Proxmox node TLS certificate ─────────────────── + # Use pvenode cert create --overwrite rather than pvecm updatecerts -f. + # pvecm updatecerts -f restarts pve-cluster which briefly unmounts the + # cluster filesystem (/etc/pve) and can crash running VMs. + # pvenode cert create --overwrite only touches the node's own cert and + # restarts pveproxy (safe while VMs are running). cert_out = self._exec_ssh_command( - "pvecm updatecerts -f 2>&1" - " || pvenode cert create --overwrite 1 2>&1" + "pvenode cert create --overwrite 1 2>&1" " || { systemctl restart pveproxy 2>&1; echo 'restarted pveproxy'; }" " || true" )