feature #2019: Adds PREV_STATE and PREV_LCM_STATE to hook attributes.

(cherry picked from commit 2d102df0c7)
This commit is contained in:
Ruben S. Montero authored and Jaime Melis committed 2013-05-20 14:58:49 +02:00
1 parent d493e9dc4f
commit 30496cc8fe
2 files changed
+40 -1

No files matched your search

+10
View File
@@ -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
+30 -1
View File
@@ -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));
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------