We would like to introduce a way to configure system wide a script
which would be called when some event happens. The script is a single
executable set as a libvirtd option by the system administrator
(assuming one runs the system libvirtd) or the user (assuming a
user run libvirtd).
The script could be invoked on daemon events, for example starting
stopping, or reloading (SIGHUP), on domain events for example before
a domain starts, or after its stops, and possibly on other kind of
events detected by the daemon (storage or interface ...)
My current thinking is to add the following two variables to
libvirtd.conf:
# Event scripts
# An optional path to a script handling various kind of events like
# domain start, domain end, pre and post migration, etc...
# The events_script must be a path to the script or binary handling
# the
# events.
# The events_set is a list of space separated name for the event type
# the script should receive
#
# events_script="/etc/libvirt/events"
# events_set="daemon domain"
The script aruguments would be
- the object kind: e.g. "domain"
- the object name: e.g. the domain name
- the event itself: e.g. "start"
- sub event qualifier: e.g. "before"
- an optional extra information for example in case of migration
the destination or source
So for example if the two variables as set as sugegsted,
/etc/libvirt/events domain foo start before
would be run by the daemon before the lunch of a domain which could
have been initiated by the user when running "virsh foo start".
The script exec return value is expected to be 0 unless indicating an
error, in that case the libvirtd command would fail, for example
if the command launched for "virsh foo start" failed with an error value
the domain won't be started.
This is a new kind of API in libvirt(d) so I'm submitting this for
review. There could be some challenging issues, for example naming
i.e. is the object "external" name like 'foo' the right thing to pass
or should we also provide the uuid, making sure the arguments for the
scripts and the behaviour is generic enough, and also how to handle
potential recursion and avoid deadlock if the events script happen to
use libvirt.
I hope to have some initial patches by tomorrow, but I'm probably
forgetting things, so feedback welcome !
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit
http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine
http://rpmfind.net/
http://veillard.com/ | virtualization library
http://libvirt.org/