"""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``, which a rewrite #: (``install`` over the path) would replace with a file of its own. 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