1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #513: Hooks can now use the ID or full template as arguments

This commit is contained in:
Ruben S. Montero 2011-05-13 15:57:17 +02:00
parent a7e9bd0876
commit c9d0df87a8
2 changed files with 80 additions and 53 deletions

View File

@ -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<Host *>(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();

View File

@ -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<VirtualMachine *>(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);
}
}
}