Files
napalm-proxmox/napalm_proxmox/scheduled_jobs.py
T
Christian Manivong 4e7e29b598
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 15s
driver / test (3.12) (pull_request) Failing after 17s
driver / types (pull_request) Failing after 30s
driver / test (3.13) (pull_request) Failing after 15s
driver / lowest (pull_request) Failing after 19s
driver / security (pull_request) Failing after 43s
driver / build (pull_request) Successful in 35s
CI / driver (pull_request) Failing after 1m35s
driver / publish (pull_request) Skipped
docs(scheduled-jobs): a vzdump line only runs because of pmxcfs (#56)
The guard is not about the link: napalm-device-types now writes the file a
link names. /etc/cron.d/vzdump points into /etc/pve, the cluster file
system, where installing a file with a mode and owner is not safe.

Refs #56
2026-11-03 05:40:27 +01:00

52 lines
2.1 KiB
Python

"""Scheduled jobs of a Proxmox VE node or a Proxmox Backup Server (#56).
Both are Debian hosts: napalm-device-types' ``PosixScheduledJobsMixin`` reads
cron, run-parts, anacron and systemd timers over ``run_command`` as root, and
switches, runs and writes them. What this module adds is which of them Proxmox
itself ships -- ``platform`` -- and that a line in a file the cluster file
system holds is only run.
Not here: Proxmox VE's backup jobs (``/cluster/backup``) and replication, and a
backup server's verify, prune, sync and garbage collection jobs. Proxmox runs
those in its own daemons, not from cron or a timer, and the backup features
(``get_clusters``, ``get_backup_jobs``) keep them.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, ClassVar
from napalm_device_types import PosixScheduledJobsMixin
if TYPE_CHECKING:
from napalm_device_types._scheduled_reading import Reading
_UNITS = ("/usr/lib/systemd/system", "/lib/systemd/system")
#: What Proxmox VE ships: ``pve-daily-update.timer`` (pve-manager), ``pvesr.timer``
#: (replication before Proxmox VE 7) and ``/etc/cron.d/vzdump``, the backup schedule of
#: releases before ``pvescheduler``, a link to ``/etc/pve/vzdump.cron``.
PVE_PLATFORM_SOURCES = (
*(f"{d}/pve-*" for d in _UNITS),
*(f"{d}/pvesr.timer" for d in _UNITS),
"/etc/cron.d/vzdump",
)
#: What a Proxmox Backup Server ships: ``proxmox-backup-daily-update.timer``.
PBS_PLATFORM_SOURCES = tuple(f"{d}/proxmox-backup*" for d in _UNITS)
class ProxmoxScheduledJobsMixin(PosixScheduledJobsMixin):
"""Scheduled jobs of a Proxmox host; a driver sets ``PLATFORM_SOURCES``."""
#: Sources a job is only run from: links into ``/etc/pve``, the cluster file system
#: (pmxcfs), where a switch's ``install`` with a mode and owner is not safe.
RUN_ONLY_SOURCES: ClassVar[tuple[str, ...]] = ()
def _sj_read(self) -> Reading:
reading = super()._sj_read()
for job in reading.jobs:
if job["source"] in self.RUN_ONLY_SOURCES:
job["actions"] = [a for a in job["actions"] if a == "run"] # type: ignore[attr-defined]
return reading