Cualquier desarrollador y cualquier empresa puede escribir, compartir y distribuir plugins propios para Hyperflow, igual que ocurre con las aplicaciones de Nextcloud. Un plugin solo necesita un manifiesto plugin.json válido y, opcionalmente, un backend en Python (backend.py) y una interfaz web (index.html). Como referencia completa sirve el plugin incluido Hello World Demo (plugins_bundled/hello-world).
Generar una plantilla inicial#
En el área Erweiterungen (Extensiones), en + Erweiterung erstellen (Crear extensión), o mediante POST /api/v1/plugins/scaffold, Hyperflow genera un paquete inicial .zip inmediatamente ejecutable con manifiesto, backend, un ejemplo del SDK de frontend y README.md.
Estructura de directorios de un plugin#
mein-plugin/
├── plugin.json # Pflicht: Metadaten, Backend, Frontend & Einstellungen
├── backend.py # Optional: FastAPI APIRouter & Hooks
├── index.html # Optional: UI im Sandboxed Iframe + Plugin SDK
└── README.md
El nombre de la carpeta debe coincidir con el id del plugin.
1. El manifiesto (plugin.json)#
{
"id": "mein-plugin",
"name": "Mein Plugin",
"version": "1.0.0",
"description": "Reagiert auf VM-Events und bietet eine eigene UI.",
"author": "Floweon Community",
"license": "MIT",
"icon": "🔔",
"category": "Automatisierung",
"backend": { "entrypoint": "backend.py" },
"frontend": {
"entry": "index.html",
"nav_label": "Mein Plugin",
"nav_icon": "🔔"
},
"settings": [
{ "key": "webhook_url", "label": "Webhook URL", "type": "string", "default": "" },
{ "key": "api_secret", "label": "API Secret", "type": "password" },
{ "key": "enabled_events", "label": "Events", "type": "select", "options": ["alle", "nur Power"], "default": "alle" }
]
}
| Campo | Obligatorio | Descripción |
|---|---|---|
id, name, version |
sí | ID única, nombre visible, versión |
description, author, license, homepage, category |
no | Metadatos para el catálogo y la tarjeta del plugin |
icon |
no | Emoji para la tarjeta del plugin |
backend.entrypoint |
no | Archivo Python con el enrutador y los hooks |
frontend.entry, nav_label, nav_icon |
no | Punto de entrada HTML y entrada en la barra lateral |
settings[] |
no | Campos de ajustes: key, label, type, default, options |
min_hyperflow_version, permissions |
no | Informativos; no se aplican en la v1.8.0 |
Los tipos de ajuste permitidos son string, number, boolean, password y select. Los campos de tipo password se enmascaran en las respuestas de la API.
Reglas para id#
El ID del plugin debe cumplir el patrón ^[a-z0-9][a-z0-9-]{0,48}[a-z0-9]$: de 2 a 50 caracteres, solo minúsculas, dígitos y guion, sin guion al principio ni al final. No se permiten guiones bajos.
2. Backend en Python y hooks (backend.py)#
Hyperflow carga el módulo en su propio proceso y utiliza estos objetos opcionales:
| Objeto | Llamada |
|---|---|
router |
APIRouter de FastAPI, montado en /api/v1/plugins/{id}/api |
setup(ctx) |
Al activar |
teardown(ctx) |
Al desactivar |
on_event(event_name, payload, ctx) |
En cada evento del sistema |
A través de ctx se obtienen plugin_id, settings (diccionario), data_dir (directorio de datos persistente en data/plugins_data/<id>), logger y emit().
from fastapi import APIRouter
router = APIRouter()
_state = {"ctx": None}
def setup(ctx):
_state["ctx"] = ctx
ctx.logger.info(f"Plugin {ctx.plugin_id} activado")
def teardown(ctx):
_state["ctx"] = None
ctx.logger.info(f"Plugin {ctx.plugin_id} desactivado")
def on_event(event_name, payload, ctx):
if event_name == "vm.power":
ctx.logger.info(f"VM {payload.get('name')} -> {payload.get('action')}")
@router.get("/status")
async def get_status():
ctx = _state["ctx"]
return {"ok": True, "webhook_url": ctx.settings.get("webhook_url") if ctx else None}
Eventos del sistema disponibles#
| Evento | Desencadenante | Carga útil |
|---|---|---|
vm.created |
Se ha creado una VM nueva | vm_id, name, node_id, vcpus, ram_mb, autostart |
vm.updated |
Se ha modificado el hardware o el inicio automático | vm_id, name, vcpus, ram_mb, autostart |
vm.deleted |
Se ha eliminado una VM | vm_id, name, disk_deleted |
vm.power |
Inicio, parada, reinicio | vm_id, name, action, status |
node.created |
Se ha añadido un hipervisor | node_id, hostname, ip_address |
node.deleted |
Se ha eliminado un hipervisor | node_id, hostname |
plugin.enabled / plugin.disabled |
Plugin activado/desactivado | Datos del plugin |
3. Frontend con el SDK de plugins (index.html)#
La interfaz se muestra en un iframe en /plugins/{id}/static/<entry> (sandbox: allow-scripts allow-same-origin allow-forms allow-popups). Incluya /static/js/hyperflow-plugin-sdk.js. La comunicación con el portal se realiza mediante postMessage; su token de autenticación se transmite automáticamente.
| Función del SDK | Descripción |
|---|---|
Hyperflow.ready(callback) |
Llama a callback(ctx) en cuanto se establece la conexión con el portal |
Hyperflow.api(path, method, body) |
Llamar a cualquier API de Hyperflow (Promise) |
Hyperflow.pluginApi(subpath, method, body) |
Llamar a las rutas propias del plugin; el ID del plugin se determina automáticamente |
Hyperflow.toast(message, type) |
Mostrar una notificación en el portal |
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<script src="/static/js/hyperflow-plugin-sdk.js"></script>
</head>
<body style="font-family: sans-serif; color: #eef1f3; background: transparent;">
<h2>Mi plugin</h2>
<button id="btn">Cargar estado</button>
<pre id="out"></pre>
<script>
Hyperflow.ready(function () {
document.getElementById("btn").onclick = async function () {
const res = await Hyperflow.pluginApi("/status");
document.getElementById("out").textContent = JSON.stringify(res, null, 2);
Hyperflow.toast("Estado cargado", "success");
};
});
</script>
</body>
</html>
4. Empaquetado y publicación#
- Empaquete todos los archivos directamente (o dentro de una única carpeta raíz) en un archivo
.zip(máx. 50 MB). - Cargue el archivo en ZIP / Git installieren (Instalar ZIP / Git) o publique un repositorio Git con
plugin.jsonen la raíz, que los administradores incorporan mediante Aus Git installieren (Instalar desde Git).