You've already forked netbox-proxmox-power-button
53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
# Copyright (C) 2026 Bryan Joshua Pedini
|
|
from netbox.plugins import PluginConfig
|
|
|
|
|
|
class ProxmoxPowerButtonConfig(PluginConfig):
|
|
name = "proxmox_power_button"
|
|
verbose_name = "Proxmox Power Button"
|
|
description = "Start/stop/reboot Proxmox VMs from the NetBox VM detail page"
|
|
version = "0.1.1"
|
|
author = "Bryan Pedini"
|
|
base_url = "proxmox-power-button"
|
|
# The data migration pins extras.0134_owner / virtualization.0052_gfk_indexes,
|
|
# which first exist in NetBox 4.5.0 — on anything older `migrate` would die
|
|
# with NodeNotFoundError, so don't claim compatibility we can't honour.
|
|
min_version = "4.5.0"
|
|
|
|
# Optional behaviour, overridable via PLUGINS_CONFIG["proxmox_power_button"]:
|
|
# verify_ssl : verify the Proxmox TLS cert (default True — set False
|
|
# only for self-signed lab certs; the API token crosses
|
|
# this connection, so disabling verification invites MitM)
|
|
# stop_mode : "shutdown" (graceful ACPI, default) or "stop" (hard kill)
|
|
# reboot_mode : "reboot" (graceful, default) or "reset" (hard)
|
|
default_settings = {
|
|
"verify_ssl": True,
|
|
"stop_mode": "shutdown",
|
|
"reboot_mode": "reboot",
|
|
}
|
|
|
|
def ready(self):
|
|
super().ready()
|
|
# Register the per-cluster VMID uniqueness validator (post_clean).
|
|
from . import signals # noqa: F401
|
|
|
|
# Ensure power-operation audit lines reach stdout (container logs) even
|
|
# when the deployment ships the default, mostly-silent logging config.
|
|
import logging
|
|
import sys
|
|
|
|
log = logging.getLogger("proxmox_power_button")
|
|
if not any(getattr(h, "_ppb_handler", False) for h in log.handlers):
|
|
handler = logging.StreamHandler(sys.stdout)
|
|
handler.setFormatter(
|
|
logging.Formatter("%(levelname)s %(asctime)s proxmox_power_button %(message)s")
|
|
)
|
|
handler._ppb_handler = True
|
|
log.addHandler(handler)
|
|
log.setLevel(logging.INFO)
|
|
log.propagate = False
|
|
|
|
|
|
config = ProxmoxPowerButtonConfig
|