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

feature #1013: Added missing file

This commit is contained in:
Ruben S. Montero 2012-10-11 18:26:30 +02:00
parent 5a85478afa
commit 57915486b6

83
src/hm/Hook.cc Normal file
View File

@ -0,0 +1,83 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "Hook.h"
#include "Nebula.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void AllocateRemoveHook::do_hook(void *arg)
{
PoolObjectSQL * obj = static_cast<PoolObjectSQL *>(arg);
string parsed_args = args;
if ( obj == 0 )
{
return;
}
parse_hook_arguments(obj, parsed_args);
Nebula& ne = Nebula::instance();
HookManager * hm = ne.get_hm();
const HookManagerDriver * hmd = hm->get();
if ( hmd != 0 )
{
if ( remote == true )
{
string hostname;
hmd->execute(obj->get_oid(),
name,
remote_host(obj, hostname),
cmd,
parsed_args);
}
else
{
hmd->execute(obj->get_oid(), name, cmd, parsed_args);
}
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Hook::parse_hook_arguments(PoolObjectSQL *obj,
string& parsed)
{
size_t found;
found = parsed.find("$ID");
if ( found !=string::npos )
{
ostringstream oss;
oss << obj->get_oid();
parsed.replace(found, 3, oss.str());
}
found = parsed.find("$TEMPLATE");
if ( found != string::npos )
{
string templ;
parsed.replace(found, 9, obj->to_xml64(templ));
}
}