Ogni sviluppatore e ogni azienda può scrivere, condividere e distribuire plugin propri per Hyperflow, esattamente come per le app di Nextcloud. Un plugin richiede soltanto un manifest plugin.json valido e, facoltativamente, un backend Python (backend.py) e un'interfaccia web (index.html). Come riferimento completo serve il plugin fornito Hello World Demo (plugins_bundled/hello-world).
Generare il template di partenza#
Nell'area Erweiterungen (Estensioni), sotto + Erweiterung erstellen (Crea estensione), oppure tramite POST /api/v1/plugins/scaffold, Hyperflow genera un pacchetto starter .zip immediatamente eseguibile con manifest, backend, esempio di SDK frontend e README.md.
Struttura delle directory di 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
Il nome della cartella deve corrispondere all'id del plugin.
1. Il manifest (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 | Obbligatorio | Descrizione |
|---|---|---|
id, name, version |
sì | ID univoco, nome visualizzato, versione |
description, author, license, homepage, category |
no | Metadati per il catalogo e la scheda del plugin |
icon |
no | Emoji per la scheda del plugin |
backend.entrypoint |
no | File Python con router e hook |
frontend.entry, nav_label, nav_icon |
no | Punto di ingresso HTML e voce nella barra laterale |
settings[] |
no | Campi di impostazione: key, label, type, default, options |
min_hyperflow_version, permissions |
no | Informativi; nella v1.8.0 non vengono applicati |
I tipi di impostazione consentiti sono string, number, boolean, password e select. I campi di tipo password vengono mascherati nelle risposte API.
Regole per id#
L'ID del plugin deve corrispondere al pattern ^[a-z0-9][a-z0-9-]{0,48}[a-z0-9]$: da 2 a 50 caratteri, solo lettere minuscole, cifre e trattino, nessun trattino all'inizio o alla fine. I caratteri di sottolineatura non sono consentiti.
2. Backend Python e hook (backend.py)#
Hyperflow carica il modulo in un processo proprio e utilizza questi oggetti facoltativi:
| Oggetto | Chiamata |
|---|---|
router |
FastAPI APIRouter, montato sotto /api/v1/plugins/{id}/api |
setup(ctx) |
All'attivazione |
teardown(ctx) |
Alla disattivazione |
on_event(event_name, payload, ctx) |
A ogni evento di sistema |
Tramite ctx ottenete plugin_id, settings (dizionario), data_dir (directory dati persistente in data/plugins_data/<id>), logger e emit().
from fastapi import APIRouter
router = APIRouter()
_state = {"ctx": None}
def setup(ctx):
_state["ctx"] = ctx
ctx.logger.info(f"Plugin {ctx.plugin_id} attivato")
def teardown(ctx):
_state["ctx"] = None
ctx.logger.info(f"Plugin {ctx.plugin_id} disattivato")
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}
Eventi di sistema disponibili#
| Evento | Causa | Payload |
|---|---|---|
vm.created |
Nuova VM creata | vm_id, name, node_id, vcpus, ram_mb, autostart |
vm.updated |
Hardware/avvio automatico modificato | vm_id, name, vcpus, ram_mb, autostart |
vm.deleted |
VM eliminata | vm_id, name, disk_deleted |
vm.power |
Avvio, arresto, riavvio | vm_id, name, action, status |
node.created |
Hypervisor aggiunto | node_id, hostname, ip_address |
node.deleted |
Hypervisor rimosso | node_id, hostname |
plugin.enabled / plugin.disabled |
Plugin attivato/disattivato | Dati del plugin |
3. Frontend con il Plugin SDK (index.html)#
L'interfaccia viene visualizzata in un iframe sotto /plugins/{id}/static/<entry> (sandbox: allow-scripts allow-same-origin allow-forms allow-popups). Includete /static/js/hyperflow-plugin-sdk.js. La comunicazione con il portale avviene tramite postMessage; il vostro token di autenticazione viene inoltrato automaticamente.
| Funzione SDK | Descrizione |
|---|---|
Hyperflow.ready(callback) |
Chiama callback(ctx) non appena la connessione al portale è stabilita |
Hyperflow.api(path, method, body) |
Richiamare una qualsiasi API di Hyperflow (Promise) |
Hyperflow.pluginApi(subpath, method, body) |
Richiamare le route proprie del plugin; l'ID del plugin viene determinato automaticamente |
Hyperflow.toast(message, type) |
Mostrare una notifica nel portale |
<!DOCTYPE html>
<html lang="it">
<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>Mein Plugin</h2>
<button id="btn">Carica stato</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("Stato caricato", "success");
};
});
</script>
</body>
</html>
4. Creare il pacchetto e pubblicare#
- Comprimete tutti i file direttamente (oppure all'interno di un'unica cartella radice) in un file
.zip(max. 50 MB). - Caricate l'archivio sotto ZIP / Git installieren (Installa da ZIP / Git) oppure pubblicate un repository Git con
plugin.jsonnella radice, che gli amministratori integrano con Aus Git installieren (Installa da Git).