Documents Ganeti version 2.15
Contents
In order to allow customisation of operations, Ganeti runs scripts in sub-directories of @SYSCONFDIR@/ganeti/hooks. These sub-directories are named $hook-$phase.d, where $phase is either pre or post and $hook matches the directory name given for a hook (e.g. cluster-verify-post.d or node-add-pre.d).
This is similar to the /etc/network/ structure present in Debian for network interface handling.
For every operation, two sets of scripts are run:
Also, for each operation, the scripts are run on one or more nodes, depending on the operation type.
Note that, even though we call them scripts, we are actually talking about any executable.
The pre scripts have a definite target: to check that the operation is allowed given the site-specific constraints. You could have, for example, a rule that says every new instance is required to exists in a database; to implement this, you could write a script that checks the new instance parameters against your database.
The objective of these scripts should be their return code (zero or non-zero for success and failure). However, if they modify the environment in any way, they should be idempotent, as failed executions could be restarted and thus the script(s) run again with exactly the same parameters.
Note that if a node is unreachable at the time a hooks is run, this will not be interpreted as a deny for the execution. In other words, only an actual error returned from a script will cause abort, and not an unreachable node.
Therefore, if you want to guarantee that a hook script is run and denies an action, it’s best to put it on the master node.
These scripts should do whatever you need as a reaction to the completion of an operation. Their return code is not checked (but logged), and they should not depend on the fact that the pre scripts have been run.
The allowed names for the scripts consist of (similar to run-parts) upper and lower case, digits, underscores and hyphens. In other words, the regexp ^[a-zA-Z0-9_-]+$. Also, non-executable scripts will be ignored.
On a single node, the scripts in a directory are run in lexicographic order (more exactly, the python string comparison order). It is advisable to implement the usual NN-name convention where NN is a two digit number.
For an operation whose hooks are run on multiple nodes, there is no specific ordering of nodes with regard to hooks execution; you should assume that the scripts are run in parallel on the target nodes (keeping on each node the above specified ordering). If you need any kind of inter-node synchronisation, you have to implement it yourself in the scripts.
The scripts will be run as follows:
All information about the cluster is passed using environment variables. Different operations will have sligthly different environments, but most of the variables are common.
Adds a node to the cluster.
directory: | node-add |
---|---|
env. vars: | NODE_NAME, NODE_PIP, NODE_SIP, MASTER_CAPABLE, VM_CAPABLE |
pre-execution: | all existing nodes |
post-execution: | all nodes plus the new node |
Removes a node from the cluster. On the removed node the hooks are called during the execution of the operation and not after its completion.
directory: | node-remove |
---|---|
env. vars: | NODE_NAME |
pre-execution: | all existing nodes except the removed node |
post-execution: | all existing nodes |
Changes a node’s parameters.
directory: | node-modify |
---|---|
env. vars: | MASTER_CANDIDATE, OFFLINE, DRAINED, MASTER_CAPABLE, VM_CAPABLE |
pre-execution: | master node, the target node |
post-execution: | master node, the target node |
Relocate secondary instances from a node.
directory: | node-migrate |
---|---|
env. vars: | NODE_NAME |
pre-execution: | master node |
post-execution: | master node |
Adds a node group to the cluster.
directory: | group-add |
---|---|
env. vars: | GROUP_NAME |
pre-execution: | master node |
post-execution: | master node |
Changes a node group’s parameters.
directory: | group-modify |
---|---|
env. vars: | GROUP_NAME, NEW_ALLOC_POLICY |
pre-execution: | master node |
post-execution: | master node |
Removes a node group from the cluster. Since the node group must be empty for removal to succeed, the concept of “nodes in the group” does not exist, and the hook is only executed in the master node.
directory: | group-remove |
---|---|
env. vars: | GROUP_NAME |
pre-execution: | master node |
post-execution: | master node |
Renames a node group.
directory: | group-rename |
---|---|
env. vars: | OLD_NAME, NEW_NAME |
pre-execution: | master node and all nodes in the group |
post-execution: | master node and all nodes in the group |
Evacuates a node group.
directory: | group-evacuate |
---|---|
env. vars: | GROUP_NAME, TARGET_GROUPS |
pre-execution: | master node and all nodes in the group |
post-execution: | master node and all nodes in the group |
Adds a network to the cluster.
directory: | network-add |
---|---|
env. vars: | NETWORK_NAME, NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6, NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS |
pre-execution: | master node |
post-execution: | master node |
Removes a network from the cluster.
directory: | network-remove |
---|---|
env. vars: | NETWORK_NAME |
pre-execution: | master node |
post-execution: | master node |
Connects a network to a nodegroup.
directory: | network-connect |
---|---|
env. vars: | GROUP_NAME, NETWORK_NAME, GROUP_NETWORK_MODE, GROUP_NETWORK_LINK, GROUP_NETWORK_VLAN, NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6, NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS |
pre-execution: | nodegroup nodes |
post-execution: | nodegroup nodes |
Disconnects a network from a nodegroup.
directory: | network-disconnect |
---|---|
env. vars: | GROUP_NAME, NETWORK_NAME, GROUP_NETWORK_MODE, GROUP_NETWORK_LINK, GROUP_NETWORK_VLAN, NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6, NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS |
pre-execution: | nodegroup nodes |
post-execution: | nodegroup nodes |
Modifies a network.
directory: | network-modify |
---|---|
env. vars: | NETWORK_NAME, NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6, NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS |
pre-execution: | master node |
post-execution: | master node |
All instance operations take at least the following variables: INSTANCE_NAME, INSTANCE_PRIMARY, INSTANCE_SECONDARY, INSTANCE_OS_TYPE, INSTANCE_DISK_TEMPLATE, INSTANCE_MEMORY, INSTANCE_DISK_SIZES, INSTANCE_VCPUS, INSTANCE_NIC_COUNT, INSTANCE_NICn_IP, INSTANCE_NICn_BRIDGE, INSTANCE_NICn_MAC, INSTANCE_NICn_NETWORK, INSTANCE_NICn_NETWORK_UUID, INSTANCE_NICn_NETWORK_SUBNET, INSTANCE_NICn_NETWORK_GATEWAY, INSTANCE_NICn_NETWORK_SUBNET6, INSTANCE_NICn_NETWORK_GATEWAY6, INSTANCE_NICn_NETWORK_MAC_PREFIX, INSTANCE_DISK_COUNT, INSTANCE_DISKn_SIZE, INSTANCE_DISKn_MODE, INSTANCE_DISKn_NAME, INSTANCE_DISKn_UUID, INSTANCE_DISKn_DEV_TYPE.
The INSTANCE_NICn_* and INSTANCE_DISKn_* variables represent the properties of the n -th NIC and disk, and are zero-indexed. Depending on the disk template, Ganeti exports some info related to the logical id of the disk, that is basically its driver and id.
The INSTANCE_NICn_NETWORK_* variables are only passed if a NIC’s network parameter is set (that is if the NIC is associated to a network defined via gnt-network)
Creates a new instance.
directory: | instance-add |
---|---|
env. vars: | ADD_MODE, SRC_NODE, SRC_PATH, SRC_IMAGES |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Reinstalls an instance.
directory: | instance-reinstall |
---|---|
env. vars: | only the standard instance vars |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Exports the instance.
directory: | instance-export |
---|---|
env. vars: | EXPORT_MODE, EXPORT_NODE, EXPORT_DO_SHUTDOWN, REMOVE_INSTANCE |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Starts an instance.
directory: | instance-start |
---|---|
env. vars: | FORCE |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Stops an instance.
directory: | instance-stop |
---|---|
env. vars: | TIMEOUT |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Reboots an instance.
directory: | instance-reboot |
---|---|
env. vars: | IGNORE_SECONDARIES, REBOOT_TYPE, SHUTDOWN_TIMEOUT |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Modifies the instance parameters.
directory: | instance-modify |
---|---|
env. vars: | NEW_DISK_TEMPLATE, RUNTIME_MEMORY |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Failovers an instance. In the post phase INSTANCE_PRIMARY and INSTANCE_SECONDARY refer to the nodes that were repectively primary and secondary before failover.
directory: | instance-failover |
---|---|
env. vars: | IGNORE_CONSISTENCY, SHUTDOWN_TIMEOUT, OLD_PRIMARY, OLD_SECONDARY, NEW_PRIMARY, NEW_SECONDARY |
pre-execution: | master node, secondary (target) node |
post-execution: | master node, primary (source) and secondary (target) nodes |
Migrates an instance. In the post phase INSTANCE_PRIMARY and INSTANCE_SECONDARY refer to the nodes that were repectively primary and secondary before migration.
directory: | instance-migrate |
---|---|
env. vars: | MIGRATE_LIVE, MIGRATE_CLEANUP, OLD_PRIMARY, OLD_SECONDARY, NEW_PRIMARY, NEW_SECONDARY |
pre-execution: | master node, primary (source) and secondary (target) nodes |
post-execution: | master node, primary (source) and secondary (target) nodes |
Remove an instance.
directory: | instance-remove |
---|---|
env. vars: | SHUTDOWN_TIMEOUT |
pre-execution: | master node |
post-execution: | master node, primary and secondary nodes |
Grows the disk of an instance.
directory: | disk-grow |
---|---|
env. vars: | DISK, AMOUNT |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Renames an instance.
directory: | instance-rename |
---|---|
env. vars: | INSTANCE_NEW_NAME |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Move an instance by data-copying.
directory: | instance-move |
---|---|
env. vars: | TARGET_NODE, SHUTDOWN_TIMEOUT |
pre-execution: | master node, primary and target nodes |
post-execution: | master node, primary and target nodes |
Recreate an instance’s missing disks.
directory: | instance-recreate-disks |
---|---|
env. vars: | only the standard instance vars |
pre-execution: | master node, primary and secondary nodes |
post-execution: | master node, primary and secondary nodes |
Replace the disks of an instance.
directory: | mirrors-replace |
---|---|
env. vars: | MODE, NEW_SECONDARY, OLD_SECONDARY |
pre-execution: | master node, primary and new secondary nodes |
post-execution: | master node, primary and new secondary nodes |
Moves an instance to another group.
directory: | instance-change-group |
---|---|
env. vars: | TARGET_GROUPS |
pre-execution: | master node |
post-execution: | master node |
This hook is called via a special “empty” LU right after cluster initialization.
directory: | cluster-init |
---|---|
env. vars: | none |
pre-execution: | none |
post-execution: | master node |
The post phase of this hook is called during the execution of destroy operation and not after its completion.
directory: | cluster-destroy |
---|---|
env. vars: | none |
pre-execution: | none |
post-execution: | master node |
Verifies all nodes in a group. This is a special LU with regard to hooks, as the result of the opcode will be combined with the result of post-execution hooks, in order to allow administrators to enhance the cluster verification procedure.
directory: | cluster-verify |
---|---|
env. vars: | CLUSTER, MASTER, CLUSTER_TAGS, NODE_TAGS_<name> |
pre-execution: | none |
post-execution: | all nodes in a group |
Renames the cluster.
directory: | cluster-rename |
---|---|
env. vars: | NEW_NAME |
pre-execution: | master-node |
post-execution: | master-node |
Modifies the cluster parameters.
directory: | cluster-modify |
---|---|
env. vars: | NEW_VG_NAME |
pre-execution: | master node |
post-execution: | master node |
This doesn’t correspond to an actual op-code, but it is called when the master IP is activated.
directory: | master-ip-turnup |
---|---|
env. vars: | MASTER_NETDEV, MASTER_IP, MASTER_NETMASK, CLUSTER_IP_VERSION |
pre-execution: | master node |
post-execution: | master node |
This doesn’t correspond to an actual op-code, but it is called when the master IP is deactivated.
directory: | master-ip-turndown |
---|---|
env. vars: | MASTER_NETDEV, MASTER_IP, MASTER_NETMASK, CLUSTER_IP_VERSION |
pre-execution: | master node |
post-execution: | master node |
The following operations are no longer present or don’t execute hooks anymore in Ganeti 2.0:
Note that all variables listed here are actually prefixed with GANETI_ in order to provide a clear namespace. In addition, post-execution scripts receive another set of variables, prefixed with GANETI_POST_, representing the status after the opcode executed.
This is the list of environment variables supported by all operations:
This is the list of variables which are specific to one or more operations.
The startup of an instance will pass this environment to the hook script:
GANETI_CLUSTER=cluster1.example.com
GANETI_DATA_DIR=/var/lib/ganeti
GANETI_FORCE=False
GANETI_HOOKS_PATH=instance-start
GANETI_HOOKS_PHASE=post
GANETI_HOOKS_VERSION=2
GANETI_INSTANCE_DISK0_MODE=rw
GANETI_INSTANCE_DISK0_SIZE=128
GANETI_INSTANCE_DISK_COUNT=1
GANETI_INSTANCE_DISK_TEMPLATE=drbd
GANETI_INSTANCE_MEMORY=128
GANETI_INSTANCE_NAME=instance2.example.com
GANETI_INSTANCE_NIC0_BRIDGE=xen-br0
GANETI_INSTANCE_NIC0_IP=
GANETI_INSTANCE_NIC0_MAC=aa:00:00:a5:91:58
GANETI_INSTANCE_NIC_COUNT=1
GANETI_INSTANCE_OS_TYPE=debootstrap
GANETI_INSTANCE_PRIMARY=node3.example.com
GANETI_INSTANCE_SECONDARY=node5.example.com
GANETI_INSTANCE_STATUS=down
GANETI_INSTANCE_VCPUS=1
GANETI_MASTER=node1.example.com
GANETI_OBJECT_TYPE=INSTANCE
GANETI_OP_CODE=OP_INSTANCE_STARTUP
GANETI_OP_TARGET=instance2.example.com