driver / lint (pull_request) Successful in 15s
driver / standard (pull_request) Successful in 19s
driver / types (pull_request) Failing after 28s
driver / test (3.13) (pull_request) Failing after 15s
driver / test (3.12) (pull_request) Failing after 17s
driver / lowest (pull_request) Failing after 19s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Failing after 37s
CI / driver (pull_request) Failing after 1m12s
driver / publish (pull_request) Skipped
Both drivers mix in napalm-device-types' PosixScheduledJobsMixin over the node's root SSH session: get_scheduled_jobs reads cron, run-parts, anacron and every systemd timer in one round trip; manage_scheduled_job enables, disables or runs one now; put_ and delete_scheduled_job write and remove an application's own job. What Proxmox ships is platform, so it is only switched and run: pve-* units, pvesr.timer and /etc/cron.d/vzdump on Proxmox VE, proxmox-backup* units on a backup server. A vzdump cron line is only run, because the file is a link into /etc/pve and rewriting it would replace the link with a plain file. Backup jobs (/cluster/backup), replication and a backup server's verify, prune, sync and GC jobs run in Proxmox's own daemons and stay with the backup features. Requires napalm-device-types 4.26.0. Closes #56
52 lines
2.1 KiB
Python
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``, 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
|