hooks: Provide variables with post-opcode values
authorMichael Hanselmann <hansmi@google.com>
Wed, 16 Mar 2011 17:35:18 +0000 (18:35 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 16 Mar 2011 17:58:35 +0000 (18:58 +0100)
commitdd7f6776235601c60ce4257c710a2bc0be80a206
tree5dce9008271695ab46abfda7c1e6b83b8f4a9c4d
parentebc755102722b91ea0e54c7db1ceeadf53130c84
hooks: Provide variables with post-opcode values

When a hook is called, it is provided with a number of variables
describing the status of the instance/node/etc. before the operation.
Some opcodes provide extra variables to see modified values from hooks,
but that's not a generic solution.

This patch modifies the code calling hooks to generate the environment
once before and once after an opcode has been executed. Doing so should
be safe—I did not find any LU.BuildHooksEnv modifying LU instance
attributes. The values collected after running the opcode are prefixed
with “GANETI_POST_”, as opposed to “GANETI_” for pre-execution
variables. The latter are still provided for backwards compatibility.

Environment variable examples:

gnt-instance start $instance:
GANETI_INSTANCE_STATUS=down
GANETI_POST_INSTANCE_STATUS=up

gnt-instance modify -B memory=512 $instance:
GANETI_INSTANCE_BE_memory=768
GANETI_POST_INSTANCE_BE_memory=512

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
doc/hooks.rst
lib/mcpu.py
test/ganeti.hooks_unittest.py