Statistics
| Branch: | Tag: | Revision:

root / doc / hooks.rst @ b1ee5610

History | View | Annotate | Download (16.2 kB)

1
Ganeti customisation using hooks
2
================================
3

    
4
Documents ganeti version 2.0
5

    
6
.. contents::
7

    
8
Introduction
9
------------
10

    
11

    
12
In order to allow customisation of operations, ganeti runs scripts
13
under ``/etc/ganeti/hooks`` based on certain rules.
14

    
15

    
16
This is similar to the ``/etc/network/`` structure present in Debian
17
for network interface handling.
18

    
19
Organisation
20
------------
21

    
22
For every operation, two sets of scripts are run:
23

    
24
- pre phase (for authorization/checking)
25
- post phase (for logging)
26

    
27
Also, for each operation, the scripts are run on one or more nodes,
28
depending on the operation type.
29

    
30
Note that, even though we call them scripts, we are actually talking
31
about any executable.
32

    
33
*pre* scripts
34
~~~~~~~~~~~~~
35

    
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.
41

    
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.
47

    
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
51
an unreachable node.
52

    
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.
55

    
56
*post* scripts
57
~~~~~~~~~~~~~~
58

    
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
62
have been run.
63

    
64
Naming
65
~~~~~~
66

    
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
70
ignored.
71

    
72

    
73
Order of execution
74
~~~~~~~~~~~~~~~~~~
75

    
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
79
two digit number.
80

    
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
86
in the scripts.
87

    
88
Execution environment
89
~~~~~~~~~~~~~~~~~~~~~
90

    
91
The scripts will be run as follows:
92

    
93
- no command line arguments
94

    
95
- no controlling *tty*
96

    
97
- stdin is actually */dev/null*
98

    
99
- stdout and stderr are directed to files
100

    
101
- PATH is reset to ``/sbin:/bin:/usr/sbin:/usr/bin``
102

    
103
- the environment is cleared, and only ganeti-specific variables will
104
  be left
105

    
106

    
107
All information about the cluster is passed using environment
108
variables. Different operations will have sligthly different
109
environments, but most of the variables are common.
110

    
111
Operation list
112
--------------
113

    
114
Node operations
115
~~~~~~~~~~~~~~~
116

    
117
OP_ADD_NODE
118
+++++++++++
119

    
120
Adds a node to the cluster.
121

    
122
:directory: node-add
123
:env. vars: NODE_NAME, NODE_PIP, NODE_SIP
124
:pre-execution: all existing nodes
125
:post-execution: all nodes plus the new node
126

    
127

    
128
OP_REMOVE_NODE
129
++++++++++++++
130

    
131
Removes a node from the cluster. On the removed node the hooks are
132
called during the execution of the operation and not after its
133
completion.
134

    
135
:directory: node-remove
136
:env. vars: NODE_NAME
137
:pre-execution: all existing nodes except the removed node
138
:post-execution: all existing nodes
139

    
140
OP_NODE_SET_PARAMS
141
++++++++++++++++++
142

    
143
Changes a node's parameters.
144

    
145
:directory: node-modify
146
:env. vars: MASTER_CANDIDATE, OFFLINE, DRAINED
147
:pre-execution: master node, the target node
148
:post-execution: master node, the target node
149

    
150
OP_NODE_EVACUATE
151
++++++++++++++++
152

    
153
Relocate secondary instances from a node.
154

    
155
:directory: node-evacuate
156
:env. vars: NEW_SECONDARY, NODE_NAME
157
:pre-execution: master node, target node
158
:post-execution: master node, target node
159

    
160
OP_NODE_MIGRATE
161
++++++++++++++++
162

    
163
Relocate secondary instances from a node.
164

    
165
:directory: node-migrate
166
:env. vars: NODE_NAME
167
:pre-execution: master node
168
:post-execution: master node
169

    
170

    
171
Node group operations
172
~~~~~~~~~~~~~~~~~~~~~
173

    
174
OP_ADD_GROUP
175
++++++++++++
176

    
177
Adds a node group to the cluster.
178

    
179
:directory: group-add
180
:env. vars: GROUP_NAME
181
:pre-execution: master node
182
:post-execution: master node
183

    
184

    
185
Instance operations
186
~~~~~~~~~~~~~~~~~~~
187

    
188
All instance operations take at least the following variables:
189
INSTANCE_NAME, INSTANCE_PRIMARY, INSTANCE_SECONDARIES,
190
INSTANCE_OS_TYPE, INSTANCE_DISK_TEMPLATE, INSTANCE_MEMORY,
191
INSTANCE_DISK_SIZES, INSTANCE_VCPUS, INSTANCE_NIC_COUNT,
192
INSTANCE_NICn_IP, INSTANCE_NICn_BRIDGE, INSTANCE_NICn_MAC,
193
INSTANCE_DISK_COUNT, INSTANCE_DISKn_SIZE, INSTANCE_DISKn_MODE.
194

    
195
The INSTANCE_NICn_* and INSTANCE_DISKn_* variables represent the
196
properties of the *n* -th NIC and disk, and are zero-indexed.
197

    
198

    
199
OP_INSTANCE_ADD
200
+++++++++++++++
201

    
202
Creates a new instance.
203

    
204
:directory: instance-add
205
:env. vars: ADD_MODE, SRC_NODE, SRC_PATH, SRC_IMAGES
206
:pre-execution: master node, primary and secondary nodes
207
:post-execution: master node, primary and secondary nodes
208

    
209
OP_INSTANCE_REINSTALL
210
+++++++++++++++++++++
211

    
212
Reinstalls an instance.
213

    
214
:directory: instance-reinstall
215
:env. vars: only the standard instance vars
216
:pre-execution: master node, primary and secondary nodes
217
:post-execution: master node, primary and secondary nodes
218

    
219
OP_BACKUP_EXPORT
220
++++++++++++++++
221

    
222
Exports the instance.
223

    
224
:directory: instance-export
225
:env. vars: EXPORT_NODE, EXPORT_DO_SHUTDOWN
226
:pre-execution: master node, primary and secondary nodes
227
:post-execution: master node, primary and secondary nodes
228

    
229
OP_INSTANCE_START
230
+++++++++++++++++
231

    
232
Starts an instance.
233

    
234
:directory: instance-start
235
:env. vars: FORCE
236
:pre-execution: master node, primary and secondary nodes
237
:post-execution: master node, primary and secondary nodes
238

    
239
OP_INSTANCE_SHUTDOWN
240
++++++++++++++++++++
241

    
242
Stops an instance.
243

    
244
:directory: instance-stop
245
:env. vars: only the standard instance vars
246
:pre-execution: master node, primary and secondary nodes
247
:post-execution: master node, primary and secondary nodes
248

    
249
OP_INSTANCE_REBOOT
250
++++++++++++++++++
251

    
252
Reboots an instance.
253

    
254
:directory: instance-reboot
255
:env. vars: IGNORE_SECONDARIES, REBOOT_TYPE
256
:pre-execution: master node, primary and secondary nodes
257
:post-execution: master node, primary and secondary nodes
258

    
259
OP_INSTANCE_MODIFY
260
++++++++++++++++++
261

    
262
Modifies the instance parameters.
263

    
264
:directory: instance-modify
265
:env. vars: only the standard instance vars
266
:pre-execution: master node, primary and secondary nodes
267
:post-execution: master node, primary and secondary nodes
268

    
269
OP_INSTANCE_FAILOVER
270
++++++++++++++++++++
271

    
272
Failovers an instance. In the post phase INSTANCE_PRIMARY and
273
INSTANCE_SECONDARIES refer to the nodes that were repectively primary
274
and secondary before failover.
275

    
276
:directory: instance-failover
277
:env. vars: IGNORE_CONSISTENCY, OLD_SECONDARY, OLD_PRIMARY, NEW_SECONDARY, NEW_PRIMARY
278
:pre-execution: master node, secondary node
279
:post-execution: master node, primary and secondary nodes
280

    
281
OP_INSTANCE_MIGRATE
282
++++++++++++++++++++
283

    
284
Migrates an instance. In the post phase INSTANCE_PRIMARY and
285
INSTANCE_SECONDARIES refer to the nodes that were repectively primary
286
and secondary before migration.
287

    
288
:directory: instance-migrate
289
:env. vars: MIGRATE_LIVE, MIGRATE_CLEANUP, OLD_SECONDARY, OLD_PRIMARY, NEW_SECONDARY, NEW_PRIMARY
290
:pre-execution: master node, secondary node
291
:post-execution: master node, primary and secondary nodes
292

    
293

    
294
OP_INSTANCE_REMOVE
295
++++++++++++++++++
296

    
297
Remove an instance.
298

    
299
:directory: instance-remove
300
:env. vars: only the standard instance vars
301
:pre-execution: master node
302
:post-execution: master node, primary and secondary nodes
303

    
304
OP_INSTANCE_REPLACE_DISKS
305
+++++++++++++++++++++++++
306

    
307
Replace an instance's disks.
308

    
309
:directory: mirror-replace
310
:env. vars: MODE, NEW_SECONDARY, OLD_SECONDARY
311
:pre-execution: master node, primary and secondary nodes
312
:post-execution: master node, primary and secondary nodes
313

    
314
OP_INSTANCE_GROW_DISK
315
+++++++++++++++++++++
316

    
317
Grows the disk of an instance.
318

    
319
:directory: disk-grow
320
:env. vars: DISK, AMOUNT
321
:pre-execution: master node, primary and secondary nodes
322
:post-execution: master node, primary and secondary nodes
323

    
324
OP_INSTANCE_RENAME
325
++++++++++++++++++
326

    
327
Renames an instance.
328

    
329
:directory: instance-rename
330
:env. vars: INSTANCE_NEW_NAME
331
:pre-execution: master node, primary and secondary nodes
332
:post-execution: master node, primary and secondary nodes
333

    
334
OP_INSTANCE_MOVE
335
++++++++++++++++
336

    
337
Move an instance by data-copying.
338

    
339
:directory: instance-move
340
:env. vars: TARGET_NODE
341
:pre-execution: master node, primary and target nodes
342
:post-execution: master node, primary and target nodes
343

    
344
OP_INSTANCE_RECREATE_DISKS
345
++++++++++++++++++++++++++
346

    
347
Recreate an instance's missing disks.
348

    
349
:directory: instance-recreate-disks
350
:env. vars: only the standard instance vars
351
:pre-execution: master node, primary and secondary nodes
352
:post-execution: master node, primary and secondary nodes
353

    
354
OP_INSTANCE_REPLACE_DISKS
355
+++++++++++++++++++++++++
356

    
357
Replace the disks of an instance.
358

    
359
:directory: mirrors-replace
360
:env. vars: MODE, NEW_SECONDARY, OLD_SECONDARY
361
:pre-execution: master node, primary and new secondary nodes
362
:post-execution: master node, primary and new secondary nodes
363

    
364

    
365
Cluster operations
366
~~~~~~~~~~~~~~~~~~
367

    
368
OP_POST_INIT_CLUSTER
369
++++++++++++++++++++
370

    
371
This hook is called via a special "empty" LU right after cluster
372
initialization.
373

    
374
:directory: cluster-init
375
:env. vars: none
376
:pre-execution: none
377
:post-execution: master node
378

    
379
OP_DESTROY_CLUSTER
380
++++++++++++++++++
381

    
382
The post phase of this hook is called during the execution of destroy
383
operation and not after its completion.
384

    
385
:directory: cluster-destroy
386
:env. vars: none
387
:pre-execution: none
388
:post-execution: master node
389

    
390
OP_CLUSTER_VERIFY
391
+++++++++++++++++
392

    
393
Verifies the cluster status. This is a special LU with regard to
394
hooks, as the result of the opcode will be combined with the result of
395
post-execution hooks, in order to allow administrators to enhance the
396
cluster verification procedure.
397

    
398
:directory: cluster-verify
399
:env. vars: CLUSTER, MASTER, CLUSTER_TAGS, NODE_TAGS_<name>
400
:pre-execution: none
401
:post-execution: all nodes
402

    
403
OP_CLUSTER_RENAME
404
+++++++++++++++++
405

    
406
Renames the cluster.
407

    
408
:directory: cluster-rename
409
:env. vars: NEW_NAME
410
:pre-execution: master-node
411
:post-execution: master-node
412

    
413
OP_CLUSTER_SET_PARAMS
414
+++++++++++++++++++++
415

    
416
Modifies the cluster parameters.
417

    
418
:directory: cluster-modify
419
:env. vars: NEW_VG_NAME
420
:pre-execution: master node
421
:post-execution: master node
422

    
423

    
424
Obsolete operations
425
~~~~~~~~~~~~~~~~~~~
426

    
427
The following operations are no longer present or don't execute hooks
428
anymore in Ganeti 2.0:
429

    
430
- OP_INIT_CLUSTER
431
- OP_MASTER_FAILOVER
432
- OP_INSTANCE_ADD_MDDRBD
433
- OP_INSTANCE_REMOVE_MDDRBD
434

    
435

    
436
Environment variables
437
---------------------
438

    
439
Note that all variables listed here are actually prefixed with
440
*GANETI_* in order to provide a clear namespace.
441

    
442
Common variables
443
~~~~~~~~~~~~~~~~
444

    
445
This is the list of environment variables supported by all operations:
446

    
447
HOOKS_VERSION
448
  Documents the hooks interface version. In case this doesnt match
449
  what the script expects, it should not run. The documents conforms
450
  to the version 2.
451

    
452
HOOKS_PHASE
453
  One of *PRE* or *POST* denoting which phase are we in.
454

    
455
CLUSTER
456
  The cluster name.
457

    
458
MASTER
459
  The master node.
460

    
461
OP_CODE
462
  One of the *OP_* values from the list of operations.
463

    
464
OBJECT_TYPE
465
  One of ``INSTANCE``, ``NODE``, ``CLUSTER``.
466

    
467
DATA_DIR
468
  The path to the Ganeti configuration directory (to read, for
469
  example, the *ssconf* files).
470

    
471

    
472
Specialised variables
473
~~~~~~~~~~~~~~~~~~~~~
474

    
475
This is the list of variables which are specific to one or more
476
operations.
477

    
478
INSTANCE_NAME
479
  The name of the instance which is the target of the operation.
480

    
481
INSTANCE_DISK_TEMPLATE
482
  The disk type for the instance.
483

    
484
INSTANCE_DISK_COUNT
485
  The number of disks for the instance.
486

    
487
INSTANCE_DISKn_SIZE
488
  The size of disk *n* for the instance.
489

    
490
INSTANCE_DISKn_MODE
491
  Either *rw* for a read-write disk or *ro* for a read-only one.
492

    
493
INSTANCE_NIC_COUNT
494
  The number of NICs for the instance.
495

    
496
INSTANCE_NICn_BRIDGE
497
  The bridge to which the *n* -th NIC of the instance is attached.
498

    
499
INSTANCE_NICn_IP
500
  The IP (if any) of the *n* -th NIC of the instance.
501

    
502
INSTANCE_NICn_MAC
503
  The MAC address of the *n* -th NIC of the instance.
504

    
505
INSTANCE_OS_TYPE
506
  The name of the instance OS.
507

    
508
INSTANCE_PRIMARY
509
  The name of the node which is the primary for the instance. Note that
510
  for migrations/failovers, you shouldn't rely on this variable since
511
  the nodes change during the exectution, but on the
512
  OLD_PRIMARY/NEW_PRIMARY values.
513

    
514
INSTANCE_SECONDARIES
515
  Space-separated list of secondary nodes for the instance. Note that
516
  for migrations/failovers, you shouldn't rely on this variable since
517
  the nodes change during the exectution, but on the
518
  OLD_SECONDARY/NEW_SECONDARY values.
519

    
520
INSTANCE_MEMORY
521
  The memory size (in MiBs) of the instance.
522

    
523
INSTANCE_VCPUS
524
  The number of virtual CPUs for the instance.
525

    
526
INSTANCE_STATUS
527
  The run status of the instance.
528

    
529
NODE_NAME
530
  The target node of this operation (not the node on which the hook
531
  runs).
532

    
533
NODE_PIP
534
  The primary IP of the target node (the one over which inter-node
535
  communication is done).
536

    
537
NODE_SIP
538
  The secondary IP of the target node (the one over which drbd
539
  replication is done). This can be equal to the primary ip, in case
540
  the cluster is not dual-homed.
541

    
542
FORCE
543
  This is provided by some operations when the user gave this flag.
544

    
545
IGNORE_CONSISTENCY
546
  The user has specified this flag. It is used when failing over
547
  instances in case the primary node is down.
548

    
549
ADD_MODE
550
  The mode of the instance create: either *create* for create from
551
  scratch or *import* for restoring from an exported image.
552

    
553
SRC_NODE, SRC_PATH, SRC_IMAGE
554
  In case the instance has been added by import, these variables are
555
  defined and point to the source node, source path (the directory
556
  containing the image and the config file) and the source disk image
557
  file.
558

    
559
NEW_SECONDARY
560
  The name of the node on which the new mirror component is being
561
  added (for replace disk). This can be the name of the current
562
  secondary, if the new mirror is on the same secondary. For
563
  migrations/failovers, this is the old primary node.
564

    
565
OLD_SECONDARY
566
  The name of the old secondary in the replace-disks command. Note that
567
  this can be equal to the new secondary if the secondary node hasn't
568
  actually changed. For migrations/failovers, this is the new primary
569
  node.
570

    
571
OLD_PRIMARY, NEW_PRIMARY
572
  For migrations/failovers, the old and respectively new primary
573
  nodes. These two mirror the NEW_SECONDARY/OLD_SECONDARY variables
574

    
575
EXPORT_NODE
576
  The node on which the exported image of the instance was done.
577

    
578
EXPORT_DO_SHUTDOWN
579
  This variable tells if the instance has been shutdown or not while
580
  doing the export. In the "was shutdown" case, it's likely that the
581
  filesystem is consistent, whereas in the "did not shutdown" case,
582
  the filesystem would need a check (journal replay or full fsck) in
583
  order to guarantee consistency.
584

    
585
CLUSTER_TAGS
586
  The list of cluster tags, space separated.
587

    
588
NODE_TAGS_<name>
589
  The list of tags for node *<name>*, space separated.
590

    
591
Examples
592
--------
593

    
594
The startup of an instance will pass this environment to the hook
595
script::
596

    
597
  GANETI_CLUSTER=cluster1.example.com
598
  GANETI_DATA_DIR=/var/lib/ganeti
599
  GANETI_FORCE=False
600
  GANETI_HOOKS_PATH=instance-start
601
  GANETI_HOOKS_PHASE=post
602
  GANETI_HOOKS_VERSION=2
603
  GANETI_INSTANCE_DISK0_MODE=rw
604
  GANETI_INSTANCE_DISK0_SIZE=128
605
  GANETI_INSTANCE_DISK_COUNT=1
606
  GANETI_INSTANCE_DISK_TEMPLATE=drbd
607
  GANETI_INSTANCE_MEMORY=128
608
  GANETI_INSTANCE_NAME=instance2.example.com
609
  GANETI_INSTANCE_NIC0_BRIDGE=xen-br0
610
  GANETI_INSTANCE_NIC0_IP=
611
  GANETI_INSTANCE_NIC0_MAC=aa:00:00:a5:91:58
612
  GANETI_INSTANCE_NIC_COUNT=1
613
  GANETI_INSTANCE_OS_TYPE=debootstrap
614
  GANETI_INSTANCE_PRIMARY=node3.example.com
615
  GANETI_INSTANCE_SECONDARIES=node5.example.com
616
  GANETI_INSTANCE_STATUS=down
617
  GANETI_INSTANCE_VCPUS=1
618
  GANETI_MASTER=node1.example.com
619
  GANETI_OBJECT_TYPE=INSTANCE
620
  GANETI_OP_CODE=OP_INSTANCE_STARTUP
621
  GANETI_OP_TARGET=instance2.example.com
622

    
623
.. vim: set textwidth=72 :
624
.. Local Variables:
625
.. mode: rst
626
.. fill-column: 72
627
.. End: