Using Hooks 4.4
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. inlinetoc
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/hooks
The following is an example of a hook tied to the DONE state of a VM:
<xterm> VM_HOOK = [
name = "notify_done", on = "DONE", command = "notify.rb", arguments = "$ID $TEMPLATE" ]
</xterm>
Or an more advanced example:
<xterm> VM_HOOK = [
name = "advanced_hook", on = "CUSTOM", state = "ACTIVE", lcm_state = "BOOT_UNKNOWN", command = "log.rb", arguments = "$ID $PREV_STATE $PREV_LCM_STATE" ]
</xterm>
In the case of Host hooks, the following can be defined:
/var/lib/one/remotes/hooks
The following is an example of a hook tied to the ERROR state of a Host:
<xterm> #——————————– Host Hook ———————————– # This hook is used to perform recovery actions when a host fails. # Script to implement host failure tolerance # It can be set to # -r recreate VMs running in the host # -d delete VMs running in the host # Additional flags # -f force resubmission of suspended VMs # -p <n> avoid resubmission if host comes # back after n monitoring cycles #—————————————————————————— # #HOST_HOOK = [ # name = “error”, # on = “ERROR”, # command = “ft/host_error.rb”, # arguments = “$ID -r”, # remote = “no” ] #——————————————————————————- </xterm>
Other OpenNebula entities like Virtual Networks, Users, Groups and Images can be hooked on creation and removal. These hooks are specified with the following variables in oned.conf:
These hooks are always executed on the front-end and are defined by the following attributes
/var/lib/one/remotes/hooks
The following is an example of a hook that sends and email to a new register user:
<xterm>
USER_HOOK = [
name = "mail", on = "CREATE", command = "email2user.rb", arguments = "$ID $TEMPLATE"]
</xterm>
The execution of each hook is tied to the object that trigger the event. The data of the object can be passed to the hook through the $ID and the $TEMPLATE variables:
#!/bin/bash # Argument hook for virtual network add to oned.conf # VNET_HOOK = [ # name="bash_arguments", # on="CREATE", # command=<path_to_this_file>, # arguments="$TEMPLATE" ] XPATH=/var/lib/one/remotes/datastore/xpath.rb T64=$1 USER_NAME=`$XPATH -b $T64 UNAME` OWNER_USE_PERMISSION=`$XPATH -b $T64 PERMISSIONS/OWNER_U` #UNAME and PERMISSIONS/OWNER_U are the XPATH for the attributes without the root element
Note that within the hook you can further interact with OpenNebula to retrieve more information, or perform any other action