Xen Orchestra / XCP-ng Smart-Home-Integration, kostenlos und Open Source

Xen Orchestra and XCP-ng: hosts, VMs (state, CPU, memory), storage, backups; start a VM.
Die Dokumentation dieser Integration wird von ihrem Autor geschrieben und ist bisher nur auf Englisch verfügbar.
Follow your XCP-ng hosts, VMs, storage repositories and backups from Gladys, and start a VM, through the REST API of Xen Orchestra (XO), over HTTPS on your network. Unofficial integration, not affiliated with Vates, Xen Orchestra nor XCP-ng. Never tested with a real device: written from the official REST API documentation (https://docs.xen-orchestra.com/restapi) and the Swagger shipped with XO, tested against a simulated Xen Orchestra and, for the reads and the token, against a real Xen Orchestra in a container without a hypervisor (no real VM started nor stopped).
What you get
Devices to add from the Discovery (once the Scan is run):
| Device | Features |
|---|---|
| Host | running (binary), memory used (%, only while it runs) |
| VM | running (binary), power state (text), CPU (%), memory used (%), memory size (MB); Start, Shut down, Force shutdown, Restart buttons |
| Storage | used (%), free and total space (GB); ISO libraries and removable devices are left out |
| Backup | last run successful (binary), last run (text), hours since the last success |
- CPU (the percent per vCPU given by the API, mean of the vCPUs) and memory used come from the statistics: up to 10 running VMs per read, in turn (with 30 running VMs, each is read every 3 reads). A sample older than 5 minutes (by the time of XO) is not published. Without the guest tools, the memory used stays unknown (never 0).
- Backups: the runs started within the last 8 days (by the time of XO). A job without a success in that window has an unknown time since the last success.
- At most 32 hosts, 200 VMs, 64 storage repositories, 64 backup jobs: beyond, the status says so.
- The device ids are the UUIDs given by XO (a renamed VM stays the same device).
Setup
- In Xen Orchestra, create an authentication token (your user, Authentication tokens, or
xo-cli create-token). Prefer a non-admin user that only sees the VMs you want in Gladys (XO rights). - In Gladys, open the integration, type the address of Xen Orchestra (as in your browser, e.g.
192.168.1.30; HTTPS only;:portif not 443) and the token, then save. - Click Trust the certificate twice. The first click shows the SHA-256 fingerprint of the certificate
shown and sends nothing else. Compare it with the one your browser shows for
https://<address>/(certificate details), then click again within 2 minutes. You can also type the fingerprint in the configuration. From then on, another certificate stops everything (the token is not sent to it) until you trust it the same way. - Run a Scan in the Discovery and create the devices you want.
The token
- It is kept by Gladys in its database, never shown again, sent only to Xen Orchestra (in the
authenticationTokencookie) and only once its certificate is checked. It is in no log, nor in/data, nor in the status. - Renewal: the integration reads the expiry of the token from the token list of its user (
GET /rest/v0/users/<id>/authentication_tokens), by the time of XO, never the container's, at most every 12 h and at least 5 min apart: the next read comes at a quarter of the time left before the renewal (a 12-hour token is read again within an hour and a half). When less than half its life, or less than 7 days, is left, it asks XO for a new token with the current one, through the route documented by XO (POST /rest/v0/users/<id>/authentication_tokens, no password; themealias, which answers with a redirection, is never followed), and gives it to Gladys, which keeps it instead of the old one. If that list is refused twice (a user without that right), the status says so: the token cannot be renewed in time. If Gladys cannot keep the new one, it is used in memory and tried again every 10 minutes; after a restart, the token you typed is used while it is valid. Without a readable time of XO, the token is never taken for expiring. - Tokens left in XO: the old token stays valid in XO until its own expiry. A new token can also be left orphan when Gladys could not keep it before a restart, or when the renewal left without an answer. They carry the description "Gladys Assistant (renewed)": revoke them in XO (your user, Authentication tokens).
- If you save another token while the renewed one is being written, Gladys keeps yours (it is written back).
- A new token saved lifts a refusal at once.
- Refusal: if XO answers 401 in its own envelope to the read of the VMs, the token is refused: nothing
is tried again (a 16-bit mark, never the token, is kept in
/data) until you save another token or click Test the connection. A 401 or 403 on another route (hosts, backups, statistics, token list) or a 401 without the envelope of XO (a proxy) is not a refusal.
The VM buttons
- Start is allowed without an option. A paused or suspended VM is not started (resume it in XO).
- Shut down (clean, needs the guest tools), Force shutdown (like pulling the plug) and Restart (clean) are off by default, one option each.
- They are buttons, not switches: a "turn everything off" of a voice assistant or a scene does not reach them.
- Each command reads the VM again after the click and decides on that read (already running: nothing sent; already halted: nothing sent; XO operation running: refused). The option, the pause, a newer stop of the same VM and the guard are checked again right before the first byte. One command at a time per VM, one per VM per 15 s; another VM is not held.
- After Shut down or Force shutdown, Start of that VM is refused for 1 minute. This guard is written to
/databefore sending; if/datacannot write it, the stop is refused (nothing sent). A stop that did not leave withdraws its guard. - A stop of a VM cancels a Start of the same VM not sent yet (even when that stop is itself refused because its option is off or a command is running).
- A command is sent within 3.5 s of the click or not at all (Gladys waits 5 s). It is shown as done only once a later read shows it (power state, or a new start time for a restart); reads follow (5 s, 20 s, then further apart). A read equal to the state before is "not applied yet". Sent without a clear answer (time out, or 502, 503, 504 of a proxy): "sent, without confirmation", guard kept, never sent again by itself. Not sent: "nothing sent". The result shows in the status of the integration for 10 minutes.
- Start is refused when: the integration is not configured, the certificate is not pinned, the token is refused, XO asked to wait, a newer stop of the same VM came, within the one-minute guard after a stop, a command of the VM is running, less than 15 s since the last command of the VM, the VM cannot be read or is unknown to XO, an XO operation is running, the VM is paused or suspended, the configuration changed during the command (another address or token), the answer is too slow.
- Shut down, Force shutdown and Restart are refused for the same reasons (the guard aside), plus their
option off,
/datanot keeping the guard (Shut down, Force shutdown) and a VM not running (Shut down, Restart).
Pauses and reads
- The read of the VMs is the main read; hosts, storage, backups, statistics and the token are secondary reads: their failure does not stop the others (except a pause or a changed certificate, below) and they are spaced (up to 1 h) while they fail.
- A 429, or a 5xx that is not an error of XO itself (a proxy, 502, 503, 504), pauses reads and commands
(1 min to 6 h,
Retry-Afterhonoured, kept in/data). A 500 of XAPI about a VM pauses nothing. - Never faster than the interval after a restart, a reconnection to Gladys, a Scan or a click on Test (which only tries a refused token again at once); only another address or token saved, or a certificate trusted, reads at once. The reads that follow a command do not count.
Not done
- No creation, deletion, migration, snapshot nor restore; no command on hosts.
- No real-time events (SSE): reads at the interval.
- No user name nor password: a token only.
Konfigurationseinstellungen
Diese Einstellungen fragt Xen Orchestra / XCP-ng in seinem Konfigurationsbildschirm in Gladys ab.
| Einstellung | Typ | Pflichtfeld | Beschreibung |
|---|---|---|---|
| How it works | section | Nein | Gladys reads your Xen Orchestra (XO) through its REST API, over HTTPS on your network, with an authentication token of XO: the hosts, the VMs (state, CPU, memory), the storage repositories and the last runs of the backup jobs, as devices to add from the Discovery. A VM can be started; shutting down, forcing the shutdown and restarting are each off until you allow them below. The token is renewed by the integration before it expires. Never tested with a real device. Unofficial integration, not affiliated with Vates, Xen Orchestra nor XCP-ng. |
| Address of Xen Orchestra | string | Ja | Its IP address on your local network (or a host name), as you open its web interface. HTTPS only; add :port if it is not 443. |
| Certificate fingerprint (SHA-256, optional) | string | Nein | Xen Orchestra often shows a self-signed certificate. Empty: click Trust the certificate twice after saving (the first click shows the fingerprint seen, nothing else is sent). Filled: only this certificate is accepted (the SHA-256 fingerprint shown by your browser). Nothing, the token neither, is sent to another certificate. |
| Authentication token of XO | secret | Ja | Created in XO (your user, Authentication tokens) or with xo-cli create-token. Prefer a user that only sees the VMs you want in Gladys. Kept by Gladys in its database, never shown again, sent only to Xen Orchestra, and only once its certificate is checked. Renewed before it expires: the new token replaces this one here (the old one stays valid in XO until its own expiry). If XO refuses it, Gladys stops until you save another one or click Test. |
| Refresh (seconds) | number | Nein | How often Gladys reads Xen Orchestra (a few requests, plus the CPU and memory of up to 10 running VMs in turn). 30 to 3600 seconds. |
| VM buttons | section | Nein | Start needs no option. The three buttons below can stop a service of your home: each one is off by default, decided on a fresh read of the VM, checked again right before sending, one command per VM per 15 s, and Start is refused for 1 min after a shutdown. A command is shown as done only once a later read shows it. |
| Allow shutting VMs down | boolean | Nein | Off by default. On: the Shut down button asks the operating system of a running VM to shut down cleanly (needs its guest tools). |
| Allow forcing the shutdown | boolean | Nein | Off by default. On: the Force shutdown button cuts the VM off at once, like pulling the plug (data not saved is lost). |
| Allow restarting VMs | boolean | Nein | Off by default. On: the Restart button asks the operating system of a running VM to restart cleanly. |
| Language of names and messages | select | Nein | The names of the devices and features at their creation, the power states and the messages of the buttons. |
So installierst du Xen Orchestra / XCP-ng in Gladys
- Öffne in Gladys Integrationen: Xen Orchestra / XCP-ng erscheint im Katalog neben den nativen Integrationen, mit einem Community-Badge.
- Klicke auf Installieren. Gladys lädt das Docker-Image (
ghcr.io/lm1lc3n7/gladys-xen-orchestra:0.1.1) herunter, startet es in einer vom Kern isolierten Sandbox und erzeugt die Oberfläche der Integration (Geräte, Erkennung und Konfiguration). - Öffne den Bildschirm Konfiguration der Integration, fülle die Einstellungen aus und speichere.
- Du kannst sie auch direkt über die URL ihres Repositorys installieren: https://github.com/LM1LC3N7/gladys-xen-orchestra.
Xen Orchestra / XCP-ng benötigt Gladys >=5.1.0. Der Katalog in Gladys wird stündlich aktualisiert, eine neue Version ist also spätestens eine Stunde nach ihrer Veröffentlichung verfügbar.
Du nutzt Gladys noch nicht? Es ist kostenlos und Open Source: folge der Installationsanleitung, um loszulegen.
Über externe Integrationen
Xen Orchestra / XCP-ng ist eine externe Integration: eine Community-Integration, die als Docker-Container verpackt und auf GitHub veröffentlicht wird. Gladys installiert sie mit einem Klick und führt sie in einer vom Kern isolierten Sandbox aus. Sie wird von LM1LC3N7 veröffentlicht und gepflegt, nicht vom Gladys-Kernteam.
- Alle Integrationen durchsuchen, native und aus der Community
- Deine eigene externe Integration bauen und veröffentlichen
- Quellcode auf GitHub — Quelle dieser Dokumentation