Hooks, APIs, and idempotent automation
Automate through libvirt's API or declarative definitions. Treat hooks as a narrow integration boundary, not a hidden orchestration engine. Desired state loop 1. Read capabilities and current definitions. 2. Compute a re
Automate through libvirt's API or declarative definitions. Treat hooks as a narrow integration boundary, not a hidden orchestration engine.
Desired-state loop
- Read capabilities and current definitions.
- Compute a reviewed desired state.
- Validate XML before mutation.
- Apply only the required delta.
- Verify live and persistent state.
- Emit an auditable result without secrets.
Hooks
Hook scripts execute on lifecycle boundaries and can block operations. Keep them deterministic, fast, timeout-aware, and safe when invoked more than once. Log correlation identifiers and outcomes, not credentials or full secret payloads.
find /etc/libvirt/hooks -maxdepth 2 -type f -ls
journalctl -u virtqemud -u libvirtd --since -30mAvoid shell parsing when APIs exist
For applications, use maintained libvirt bindings and structured return values. Shelling out to virsh is reasonable for operator scripts but creates fragile parsing and error-handling boundaries at scale.