From 30496cc8feb73b2c148eb75dc0eb19f3532f51fb Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 18 May 2013 01:05:26 +0200 Subject: [PATCH] feature #2019: Adds PREV_STATE and PREV_LCM_STATE to hook attributes. (cherry picked from commit 2d102df0c7fa6e457b2fe12ddc4141b0af924939) --- include/VirtualMachineHook.h | 10 ++++++++++ src/vm/VirtualMachineHook.cc | 31 ++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/VirtualMachineHook.h b/include/VirtualMachineHook.h index 743f196244..9c96872a7f 100644 --- a/include/VirtualMachineHook.h +++ b/include/VirtualMachineHook.h @@ -118,6 +118,16 @@ public: // ------------------------------------------------------------------------- void do_hook(void *arg); + /** + * Parses the arguments of the hook using: $ID, $TEMPLATE, $PREV_DM_STATE + * and $PREV_LCM_STATE + * @param obj pointer to the object executing the hook for + * @param the resulting parser arguments + */ + void parse_hook_arguments(PoolObjectSQL * obj, + VirtualMachine::VmState prev_dm, + VirtualMachine::LcmState prev_lcm, + string& parsed); private: /** * The target LCM state diff --git a/src/vm/VirtualMachineHook.cc b/src/vm/VirtualMachineHook.cc index 1face10cf8..c10db1b8c3 100644 --- a/src/vm/VirtualMachineHook.cc +++ b/src/vm/VirtualMachineHook.cc @@ -114,7 +114,7 @@ void VirtualMachineStateHook::do_hook(void *arg) { string parsed_args = args; - parse_hook_arguments(vm, parsed_args); + parse_hook_arguments(vm, prev_vm, prev_lcm, parsed_args); Nebula& ne = Nebula::instance(); HookManager * hm = ne.get_hm(); @@ -138,6 +138,35 @@ void VirtualMachineStateHook::do_hook(void *arg) } } } +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +void VirtualMachineStateHook::parse_hook_arguments(PoolObjectSQL * obj, + VirtualMachine::VmState prev_dm, VirtualMachine::LcmState prev_lcm, + string& parsed) +{ + Hook::parse_hook_arguments(obj, parsed); + + size_t found; + + found = parsed.find("$PREV_STATE"); + + if ( found !=string::npos ) + { + string str; + + parsed.replace(found, 11, VirtualMachine::vm_state_to_str(str, prev_dm)); + } + + found = parsed.find("$PREV_LCM_STATE"); + + if ( found != string::npos ) + { + string str; + + parsed.replace(found, 15, VirtualMachine::lcm_state_to_str(str, prev_lcm)); + } +} // ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------