1 Ganeti customisation using hooks
2 ================================
4 Documents ganeti version 2.0
12 In order to allow customisation of operations, ganeti runs scripts
13 under ``/etc/ganeti/hooks`` based on certain rules.
16 This is similar to the ``/etc/network/`` structure present in Debian
17 for network interface handling.
22 For every operation, two sets of scripts are run:
24 - pre phase (for authorization/checking)
25 - post phase (for logging)
27 Also, for each operation, the scripts are run on one or more nodes,
28 depending on the operation type.
30 Note that, even though we call them scripts, we are actually talking
36 The *pre* scripts have a definite target: to check that the operation
37 is allowed given the site-specific constraints. You could have, for
38 example, a rule that says every new instance is required to exists in
39 a database; to implement this, you could write a script that checks
40 the new instance parameters against your database.
42 The objective of these scripts should be their return code (zero or
43 non-zero for success and failure). However, if they modify the
44 environment in any way, they should be idempotent, as failed
45 executions could be restarted and thus the script(s) run again with
46 exactly the same parameters.
48 Note that if a node is unreachable at the time a hooks is run, this
49 will not be interpreted as a deny for the execution. In other words,
50 only an actual error returned from a script will cause abort, and not
53 Therefore, if you want to guarantee that a hook script is run and
54 denies an action, it's best to put it on the master node.
59 These scripts should do whatever you need as a reaction to the
60 completion of an operation. Their return code is not checked (but
61 logged), and they should not depend on the fact that the *pre* scripts
67 The allowed names for the scripts consist of (similar to *run-parts* )
68 upper and lower case, digits, underscores and hyphens. In other words,
69 the regexp ``^[a-zA-Z0-9_-]+$``. Also, non-executable scripts will be
76 On a single node, the scripts in a directory are run in lexicographic
77 order (more exactly, the python string comparison order). It is
78 advisable to implement the usual *NN-name* convention where *NN* is a
81 For an operation whose hooks are run on multiple nodes, there is no
82 specific ordering of nodes with regard to hooks execution; you should
83 assume that the scripts are run in parallel on the target nodes
84 (keeping on each node the above specified ordering). If you need any
85 kind of inter-node synchronisation, you have to implement it yourself
91 The scripts will be run as follows:
93 - no command line arguments
95 - no controlling *tty*
97 - stdin is actually */dev/null*
99 - stdout and stderr are directed to files
101 - PATH is reset to ``/sbin:/bin:/usr/sbin:/usr/bin``
103 - the environment is cleared, and only ganeti-specific variables will
107 All informations about the cluster is passed using environment
108 variables. Different operations will have sligthly different
109 environments, but most of the variables are common.
120 Adds a node to the cluster.
123 :env. vars: NODE_NAME, NODE_PIP, NODE_SIP
124 :pre-execution: all existing nodes
125 :post-execution: all nodes plus the new node
131 Removes a node from the cluster.
133 :directory: node-remove
134 :env. vars: NODE_NAME
135 :pre-execution: all existing nodes except the removed node
136 :post-execution: all existing nodes except the removed node
141 Changes a node's parameters.
143 :directory: node-modify
144 :env. vars: MASTER_CANDIDATE, OFFLINE, DRAINED
145 :pre-execution: master node, the target node
146 :post-execution: master node, the target node
152 All instance operations take at least the following variables:
153 INSTANCE_NAME, INSTANCE_PRIMARY, INSTANCE_SECONDARIES,
154 INSTANCE_OS_TYPE, INSTANCE_DISK_TEMPLATE, INSTANCE_MEMORY,
155 INSTANCE_DISK_SIZES, INSTANCE_VCPUS, INSTANCE_NIC_COUNT,
156 INSTANCE_NICn_IP, INSTANCE_NICn_BRIDGE, INSTANCE_NICn_MAC,
157 INSTANCE_DISK_COUNT, INSTANCE_DISKn_SIZE, INSTANCE_DISKn_MODE.
159 The INSTANCE_NICn_* and INSTANCE_DISKn_* variables represent the
160 properties of the *n* -th NIC and disk, and are zero-indexed.
166 Creates a new instance.
168 :directory: instance-add
169 :env. vars: ADD_MODE, SRC_NODE, SRC_PATH, SRC_IMAGES
170 :pre-execution: master node, primary and secondary nodes
171 :post-execution: master node, primary and secondary nodes
173 OP_INSTANCE_REINSTALL
174 +++++++++++++++++++++
176 Reinstalls an instance.
178 :directory: instance-reinstall
179 :env. vars: only the standard instance vars
180 :pre-execution: master node, primary and secondary nodes
181 :post-execution: master node, primary and secondary nodes
186 Exports the instance.
189 :directory: instance-export
190 :env. vars: EXPORT_NODE, EXPORT_DO_SHUTDOWN
191 :pre-execution: master node, primary and secondary nodes
192 :post-execution: master node, primary and secondary nodes
199 :directory: instance-start
200 :env. vars: INSTANCE_NAME, INSTANCE_PRIMARY, INSTANCE_SECONDARIES, FORCE
201 :pre-execution: master node, primary and secondary nodes
202 :post-execution: master node, primary and secondary nodes
209 :directory: instance-shutdown
210 :env. vars: INSTANCE_NAME, INSTANCE_PRIMARY, INSTANCE_SECONDARIES
211 :pre-execution: master node, primary and secondary nodes
212 :post-execution: master node, primary and secondary nodes
219 :directory: instance-reboot
220 :env. vars: IGNORE_SECONDARIES, REBOOT_TYPE
221 :pre-execution: master node, primary and secondary nodes
222 :post-execution: master node, primary and secondary nodes
227 Modifies the instance parameters.
229 :directory: instance-modify
230 :env. vars: INSTANCE_NAME, MEM_SIZE, VCPUS, INSTANCE_IP
231 :pre-execution: master node, primary and secondary nodes
232 :post-execution: master node, primary and secondary nodes
237 Failovers an instance.
239 :directory: instance-failover
240 :env. vars: IGNORE_CONSISTENCY
241 :pre-execution: master node, secondary node
242 :post-execution: master node, secondary node
247 Migrates an instance.
249 :directory: instance-failover
250 :env. vars: INSTANCE_MIGRATE_LIVE, INSTANCE_MIGRATE_CLEANUP
251 :pre-execution: master node, secondary node
252 :post-execution: master node, secondary node
260 :directory: instance-remove
261 :env. vars: INSTANCE_NAME, INSTANCE_PRIMARY, INSTANCE_SECONDARIES
262 :pre-execution: master node
263 :post-execution: master node
265 OP_INSTANCE_REPLACE_DISKS
266 +++++++++++++++++++++++++
268 Replace an instance's disks.
270 :directory: mirror-replace
271 :env. vars: MODE, NEW_SECONDARY, OLD_SECONDARY
272 :pre-execution: master node, primary and secondary nodes
273 :post-execution: master node, primary and secondary nodes
275 OP_INSTANCE_GROW_DISK
276 +++++++++++++++++++++
278 Grows the disk of an instance.
280 :directory: disk-grow
281 :env. vars: DISK, AMOUNT
282 :pre-execution: master node, primary node
283 :post-execution: master node, primary node
290 :directory: instance-rename
291 :env. vars: INSTANCE_NEW_NAME
292 :pre-execution: master node, primary and secondary nodes
293 :post-execution: master node, primary and secondary nodes
301 Verifies the cluster status. This is a special LU with regard to
302 hooks, as the result of the opcode will be combined with the result of
303 post-execution hooks, in order to allow administrators to enhance the
304 cluster verification procedure.
306 :directory: cluster-verify
307 :env. vars: CLUSTER, MASTER, CLUSTER_TAGS, NODE_TAGS_<name>
309 :post-execution: all nodes
316 :directory: cluster-rename
318 :pre-execution: master-node
319 :post-execution: master-node
321 OP_CLUSTER_SET_PARAMS
322 +++++++++++++++++++++
324 Modifies the cluster parameters.
326 :directory: cluster-modify
327 :env. vars: NEW_VG_NAME
328 :pre-execution: master node
329 :post-execution: master node
335 The following operations are no longer present or don't execute hooks
336 anymore in Ganeti 2.0:
340 - OP_INSTANCE_ADD_MDDRBD
341 - OP_INSTANCE_REMOVE_MDDRBD
344 Environment variables
345 ---------------------
347 Note that all variables listed here are actually prefixed with
348 *GANETI_* in order to provide a clear namespace.
353 This is the list of environment variables supported by all operations:
356 Documents the hooks interface version. In case this doesnt match
357 what the script expects, it should not run. The documents conforms
361 One of *PRE* or *POST* denoting which phase are we in.
370 One of the *OP_* values from the list of operations.
373 One of ``INSTANCE``, ``NODE``, ``CLUSTER``.
376 The path to the Ganeti configuration directory (to read, for
377 example, the *ssconf* files).
380 Specialised variables
381 ~~~~~~~~~~~~~~~~~~~~~
383 This is the list of variables which are specific to one or more
387 The name of the instance which is the target of the operation.
389 INSTANCE_DISK_TEMPLATE
390 The disk type for the instance.
393 The number of disks for the instance.
396 The size of disk *n* for the instance.
399 Either *rw* for a read-write disk or *ro* for a read-only one.
402 The number of NICs for the instance.
405 The bridge to which the *n* -th NIC of the instance is attached.
408 The IP (if any) of the *n* -th NIC of the instance.
411 The MAC address of the *n* -th NIC of the instance.
414 The name of the instance OS.
417 The name of the node which is the primary for the instance.
420 Space-separated list of secondary nodes for the instance.
423 The memory size (in MiBs) of the instance.
426 The number of virtual CPUs for the instance.
429 The run status of the instance.
432 The target node of this operation (not the node on which the hook
436 The primary IP of the target node (the one over which inter-node
437 communication is done).
440 The secondary IP of the target node (the one over which drbd
441 replication is done). This can be equal to the primary ip, in case
442 the cluster is not dual-homed.
445 This is provided by some operations when the user gave this flag.
448 The user has specified this flag. It is used when failing over
449 instances in case the primary node is down.
452 The mode of the instance create: either *create* for create from
453 scratch or *import* for restoring from an exported image.
455 SRC_NODE, SRC_PATH, SRC_IMAGE
456 In case the instance has been added by import, these variables are
457 defined and point to the source node, source path (the directory
458 containing the image and the config file) and the source disk image
462 The name of the node on which the new mirror component is being
463 added. This can be the name of the current secondary, if the new
464 mirror is on the same secondary.
467 The name of the old secondary in the replace-disks command Note that
468 this can be equal to the new secondary if the secondary node hasn't
472 The node on which the exported image of the instance was done.
475 This variable tells if the instance has been shutdown or not while
476 doing the export. In the "was shutdown" case, it's likely that the
477 filesystem is consistent, whereas in the "did not shutdown" case,
478 the filesystem would need a check (journal replay or full fsck) in
479 order to guarantee consistency.
482 The list of cluster tags, space separated.
485 The list of tags for node *<name>*, space separated.
490 The startup of an instance will pass this environment to the hook
493 GANETI_CLUSTER=cluster1.example.com
494 GANETI_DATA_DIR=/var/lib/ganeti
496 GANETI_HOOKS_PATH=instance-start
497 GANETI_HOOKS_PHASE=post
498 GANETI_HOOKS_VERSION=2
499 GANETI_INSTANCE_DISK0_MODE=rw
500 GANETI_INSTANCE_DISK0_SIZE=128
501 GANETI_INSTANCE_DISK_COUNT=1
502 GANETI_INSTANCE_DISK_TEMPLATE=drbd
503 GANETI_INSTANCE_MEMORY=128
504 GANETI_INSTANCE_NAME=instance2.example.com
505 GANETI_INSTANCE_NIC0_BRIDGE=xen-br0
506 GANETI_INSTANCE_NIC0_IP=
507 GANETI_INSTANCE_NIC0_MAC=aa:00:00:a5:91:58
508 GANETI_INSTANCE_NIC_COUNT=1
509 GANETI_INSTANCE_OS_TYPE=debootstrap
510 GANETI_INSTANCE_PRIMARY=node3.example.com
511 GANETI_INSTANCE_SECONDARIES=node5.example.com
512 GANETI_INSTANCE_STATUS=down
513 GANETI_INSTANCE_VCPUS=1
514 GANETI_MASTER=node1.example.com
515 GANETI_OBJECT_TYPE=INSTANCE
516 GANETI_OP_CODE=OP_INSTANCE_STARTUP
517 GANETI_OP_TARGET=instance2.example.com