feat: add get_system_config() — cluster name, timezone, node list
Implements get_system_config() in ProxmoxSystemMixin:
- cluster_name from /cluster/status (type=cluster entry)
- cluster_nodes list of online node hostnames
- timezone from /nodes/{node}/time
- hostname, ssh_port, ssh_password_auth with safe defaults
Used by NetOrk's sync task to name the NetBox Cluster after the
actual Proxmox cluster rather than falling back to the site name.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
f6e694f028
commit
f288c01629
@@ -820,3 +820,47 @@ class ProxmoxSystemMixin:
|
|||||||
result[dev] = entry
|
result[dev] = entry
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def get_system_config(self) -> dict[str, Any]:
|
||||||
|
"""Return system-level configuration for this Proxmox node.
|
||||||
|
|
||||||
|
Collected from ``/cluster/status`` and the node config API:
|
||||||
|
|
||||||
|
* ``cluster_name`` (str | None) — Proxmox cluster name; ``None`` when
|
||||||
|
the node is standalone (not part of a cluster).
|
||||||
|
* ``cluster_nodes`` (list[str]) — hostnames of all online cluster nodes.
|
||||||
|
* ``hostname`` (str) — this node's name as reported by the cluster.
|
||||||
|
* ``timezone`` (str | None) — e.g. ``"Europe/Berlin"``.
|
||||||
|
* ``ntp_servers`` (list[str]).
|
||||||
|
* ``ssh_port`` (int) — always 22 for Proxmox nodes.
|
||||||
|
* ``ssh_password_auth`` (bool) — ``False`` as a safe default.
|
||||||
|
"""
|
||||||
|
cfg: dict[str, Any] = {
|
||||||
|
"cluster_name": None,
|
||||||
|
"cluster_nodes": [],
|
||||||
|
"hostname": self._node_name,
|
||||||
|
"timezone": None,
|
||||||
|
"ntp_servers": [],
|
||||||
|
"ssh_port": 22,
|
||||||
|
"ssh_password_auth": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cluster name and node list from /cluster/status
|
||||||
|
try:
|
||||||
|
status = self._api.cluster.status.get() or []
|
||||||
|
for entry in status:
|
||||||
|
if entry.get("type") == "cluster":
|
||||||
|
cfg["cluster_name"] = entry.get("name")
|
||||||
|
elif entry.get("type") == "node" and entry.get("online"):
|
||||||
|
cfg["cluster_nodes"].append(entry.get("name", ""))
|
||||||
|
except Exception as exc:
|
||||||
|
logger.debug("Failed to fetch cluster status for system config: %s", exc)
|
||||||
|
|
||||||
|
# Timezone from node time API
|
||||||
|
try:
|
||||||
|
time_cfg = self._node_api().time.get() or {}
|
||||||
|
cfg["timezone"] = time_cfg.get("timezone") or None
|
||||||
|
except Exception as exc:
|
||||||
|
logger.debug("Failed to fetch node time config: %s", exc)
|
||||||
|
|
||||||
|
return cfg
|
||||||
|
|||||||
Reference in New Issue
Block a user