diff --git a/src/host/HostHook.cc b/src/host/HostHook.cc index 060bc6b56d..8467b615bc 100644 --- a/src/host/HostHook.cc +++ b/src/host/HostHook.cc @@ -18,6 +18,30 @@ #include "Host.h" #include "Nebula.h" +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +static void parse_host_arguments(Host *host, string& parsed) +{ + size_t found; + + found = parsed.find("$HID"); + + if ( found !=string::npos ) + { + ostringstream oss; + oss << host->get_oid(); + + parsed.replace(found,4,oss.str()); + } + + found = parsed.find("$TEMPLATE"); + + if ( found != string::npos ) + { + string templ; + parsed.replace(found,9,host->to_xml64(templ)); + } +} // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- @@ -26,7 +50,6 @@ void HostAllocateHook::do_hook(void *arg) Host * host; string parsed_args = args; - size_t found; host = static_cast(arg); @@ -34,16 +57,8 @@ void HostAllocateHook::do_hook(void *arg) { return; } - - found = args.find("$HID"); - - if ( found !=string::npos ) - { - ostringstream oss; - oss << host->get_oid(); - - parsed_args.replace(found,4,oss.str()); - } + + parse_host_arguments(host,parsed_args); Nebula& ne = Nebula::instance(); HookManager * hm = ne.get_hm(); @@ -156,17 +171,8 @@ void HostStateHook::do_hook(void *arg) if ( cur_state == this->state ) { string parsed_args = args; - size_t found; - found = args.find("$HID"); - - if ( found !=string::npos ) - { - ostringstream oss; - oss << host->get_oid(); - - parsed_args.replace(found,4,oss.str()); - } + parse_host_arguments(host,parsed_args); Nebula& ne = Nebula::instance(); HookManager * hm = ne.get_hm(); diff --git a/src/vm/VirtualMachineHook.cc b/src/vm/VirtualMachineHook.cc index 6283408b39..8d98e970e6 100644 --- a/src/vm/VirtualMachineHook.cc +++ b/src/vm/VirtualMachineHook.cc @@ -21,11 +21,36 @@ // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- +static void parse_vm_arguments(VirtualMachine *vm, string& parsed) +{ + size_t found; + + found = parsed.find("$VMID"); + + if ( found !=string::npos ) + { + ostringstream oss; + oss << vm->get_oid(); + + parsed.replace(found,5,oss.str()); + } + + found = parsed.find("$TEMPLATE"); + + if ( found != string::npos ) + { + string templ; + parsed.replace(found,9,vm->to_xml64(templ)); + } +} + +// ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + void VirtualMachineAllocateHook::do_hook(void *arg) { VirtualMachine * vm; - int rc; - string parsed_args; + string parsed_args = args; vm = static_cast(arg); @@ -34,18 +59,15 @@ void VirtualMachineAllocateHook::do_hook(void *arg) return; } - rc = vm->parse_template_attribute(args, parsed_args); + parse_vm_arguments(vm, parsed_args); - if ( rc == 0) + Nebula& ne = Nebula::instance(); + HookManager * hm = ne.get_hm(); + const HookManagerDriver * hmd = hm->get(); + + if ( hmd != 0 ) { - Nebula& ne = Nebula::instance(); - HookManager * hm = ne.get_hm(); - const HookManagerDriver * hmd = hm->get(); - - if ( hmd != 0 ) - { - hmd->execute(vm->get_oid(),name,cmd,parsed_args); - } + hmd->execute(vm->get_oid(),name,cmd,parsed_args); } } @@ -143,29 +165,28 @@ void VirtualMachineStateHook::do_hook(void *arg) if ( cur_lcm == lcm && cur_vm == this->vm ) { - string parsed_args; + string parsed_args = args; - if ( vm->parse_template_attribute(args, parsed_args) == 0) + parse_vm_arguments(vm,parsed_args); + + Nebula& ne = Nebula::instance(); + HookManager * hm = ne.get_hm(); + + const HookManagerDriver * hmd = hm->get(); + + if ( hmd != 0 ) { - Nebula& ne = Nebula::instance(); - HookManager * hm = ne.get_hm(); - - const HookManagerDriver * hmd = hm->get(); - - if ( hmd != 0 ) + if ( ! remote ) { - if ( ! remote ) - { - hmd->execute(vm->get_oid(),name,cmd,parsed_args); - } - else if ( vm->hasHistory() ) - { - hmd->execute(vm->get_oid(), - name, - vm->get_hostname(), - cmd, - parsed_args); - } + hmd->execute(vm->get_oid(),name,cmd,parsed_args); + } + else if ( vm->hasHistory() ) + { + hmd->execute(vm->get_oid(), + name, + vm->get_hostname(), + cmd, + parsed_args); } } }