Using Hooks 3.2
The Hook Manager present in OpenNebula enables the triggering of custom scripts tied to a change in state in a particular resource, being that a Host or a Virtual Machine. This opens a wide area of automation for system administrators to tailor their cloud infrastructures.
Hook Manager configuration is set in /etc/one/oned.conf. Hooks can be tied to changes in host or virtual machine states, and they can be executed locally to the OpenNebula front-end and remotely in the relevant worker node.
In general, hook definition in /etc/one/oned.conf has two paremeters:
/usr/lib/one/mads/etc/one/In the case of VirtualMachine hooks, the following can be defined:
/var/lib/one/remotes/hooksThe following is an example of a hook tied to the DONE state of a VM:
#-------------------------------- Image Hook -----------------------------------
# This hook is used to handle image saving and overwriting when virtual machines
# reach the DONE state after being shutdown.
VM_HOOK = [
name = "image",
on = "DONE",
command = "image.rb",
arguments = "$VMID" ]
#-------------------------------------------------------------------------------
In the case of Host hooks, the following can be defined:
/var/lib/one/remotes/hooksThe following is an example of a hook tied to the ERROR state of a Host:
#-------------------------------- Host Hook -----------------------------------
# This hook is used to perform recovery actions when a host fails. The VMs
# running in the host can be deleted (use -d option) or resubmitted (-r) in
# other host
# Last argument (force) can be "y", so suspended VMs in the host will be
# resubmitted/deleted, or "n", so suspended VMs in the host will be ignored
HOST_HOOK = [
name = "error",
on = "ERROR",
command = "host_error.rb",
arguments = "$HID -r n",
remote = no ]
#-------------------------------------------------------------------------------