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

#15 define hooks in the oned.conf file

git-svn-id: http://svn.opennebula.org/one/trunk@456 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2009-04-04 23:10:02 +00:00
parent 89eee6b1c4
commit 7a144a8e1e
4 changed files with 93 additions and 30 deletions

View File

@ -33,7 +33,7 @@ class VirtualMachinePool : public PoolSQL
{
public:
VirtualMachinePool(SqliteDB * db);
VirtualMachinePool(SqliteDB * db, vector<const Attribute *> hook_mads);
~VirtualMachinePool(){};

View File

@ -2,7 +2,7 @@
# OpenNebula Configuration file
#*******************************************************************************
#-------------------------------------------------------------------------------
#*******************************************************************************
# Daemon configuration attributes
#-------------------------------------------------------------------------------
# HOST_MONITORING_INTERVAL: Time in seconds between host monitorization
@ -16,7 +16,7 @@
# PORT: Port where oned will listen for xmlrpc calls.
#
# DEBUG_LEVEL: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG
#-------------------------------------------------------------------------------
#*******************************************************************************
HOST_MONITORING_INTERVAL = 10
@ -28,23 +28,23 @@ PORT=2633
DEBUG_LEVEL=3
#-------------------------------------------------------------------------------
#*******************************************************************************
# Physical Networks configuration
#-------------------------------------------------------------------------------
#*******************************************************************************
# NETWORK_SIZE: Here you can define the default size for the virtual networks
#
# MAC_PREFIX: Default MAC prefix to be used to create the auto-generated MAC
# addresses is defined here (this can be overrided by the Virtual Network
# template)
#-------------------------------------------------------------------------------
#*******************************************************************************
NETWORK_SIZE = 254
MAC_PREFIX = "00:03"
#-------------------------------------------------------------------------------
#*******************************************************************************
# Information Driver Configuration
#-------------------------------------------------------------------------------
#*******************************************************************************
# You can add more information managers with different configurations but make
# sure it has different names.
#
@ -57,7 +57,7 @@ MAC_PREFIX = "00:03"
# arguments : for the driver executable, usually a probe configuration file,
# can be an absolute path or relative to $ONE_LOCATION/etc (or
# /etc/one/ if OpenNebula was installed in /)
#-------------------------------------------------------------------------------
#*******************************************************************************
IM_MAD = [
name = "im_xen",
@ -82,9 +82,9 @@ IM_MAD = [
# arguments = "im_ec2/im_ec2.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#*******************************************************************************
# Virtualization Driver Configuration
#-------------------------------------------------------------------------------
#*******************************************************************************
# You can add more virtualization managers with different configurations but
# make sure it has different names.
#
@ -101,7 +101,7 @@ IM_MAD = [
# /etc/one/ if OpenNebula was installed in /)
#
# type : driver type, supported drivers: xen, kvm, xml
#-------------------------------------------------------------------------------
#*******************************************************************************
VM_MAD = [
name = "vmm_xen",
@ -132,9 +132,9 @@ VM_MAD = [
# type = "xml" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#*******************************************************************************
# Transfer Manager Driver Configuration
#-------------------------------------------------------------------------------
#*******************************************************************************
# You can add more transfer managers with different configurations but make
# sure it has different names.
# name : name for this transfer driver
@ -146,7 +146,7 @@ VM_MAD = [
# arguments : for the driver executable, usually a commands configuration file
# , can be an absolute path or relative to $ONE_LOCATION/etc (or
# /etc/one/ if OpenNebula was installed in /)
#-------------------------------------------------------------------------------
#*******************************************************************************
TM_MAD = [
name = "tm_ssh",
@ -171,10 +171,10 @@ TM_MAD = [
# arguments = "tm_dummy/tm_dummy.conf" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Hook Manager Driver Configuration
#-------------------------------------------------------------------------------
# Used to execute the Hooks
#*******************************************************************************
# Hook Manager Configuration
#*******************************************************************************
# The Driver (HM_MAD), used to execute the Hooks
# executable: path of the hook driver executable, can be an
# absolute path or relative to $ONE_LOCATION/lib/mads (or
# /usr/lib/one/mads/ if OpenNebula was installed in /)
@ -182,8 +182,31 @@ TM_MAD = [
# arguments : for the driver executable, can be an absolute path or relative
# to $ONE_LOCATION/etc (or /etc/one/ if OpenNebula was installed
# in /)
#
# Virtual Machine Hooks (VM_HOOK) defined by:
# name : for the hook, useful to track the hook (OPTIONAL)
# on : when the hook should be executed
# - CREATE, when the VM is created (onevm create)
# command : use absolute path here
# arguments : for the hook. You can access to VM template variables with $
# - $ATTR, the value of an attribute e.g. $NAME or $VM_ID
# - $ATTR[VAR], the value of a vector e.g. $NIC[MAC]
# - $ATTR[VAR, COND], same of previous but COND select between
# multiple ATTRs e.g. $NIC[MAC, NETWORK="Public"]
#-------------------------------------------------------------------------------
HM_MAD = [
executable = "one_hm" ]
#-------------------------------------------------------------------------------
#VM_HOOK = [
# name = "dhcp",
# on = "create",
# command = "/bin/echo",
# arguments = "$NAME $NIC[MAC] > /tmp/test.$VM_ID" ]
#-------------------------------------------------------------------------------

View File

@ -140,7 +140,11 @@ void Nebula::start()
string mac_prefix;
int size;
vmpool = new VirtualMachinePool(db);
vector<const Attribute *> vm_hooks;
nebula_configuration->get("VM_HOOK", vm_hooks);
vmpool = new VirtualMachinePool(db, vm_hooks);
hpool = new HostPool(db);
nebula_configuration->get("MAC_PREFIX", mac_prefix);

View File

@ -20,21 +20,57 @@
#include "VirtualMachineHook.h"
#include <sstream>
VirtualMachinePool::VirtualMachinePool(SqliteDB * db):
PoolSQL(db,VirtualMachine::table)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
VirtualMachinePool::VirtualMachinePool(SqliteDB * db,
vector<const Attribute *> hook_mads)
: PoolSQL(db,VirtualMachine::table)
{
/* TODO: Get the hooks from conf file / API call ?
VirtualMachineAllocateHook * test_hook;
const VectorAttribute * vattr;
test_hook = new VirtualMachineAllocateHook("test","/bin/echo",
"$NAME $VM_ID > salida");
string name;
string on;
string cmd;
string arg;
add_hook(test_hook);
*/
for (unsigned int i = 0 ; i < hook_mads.size() ; i++ )
{
vattr = static_cast<const VectorAttribute *>(hook_mads[i]);
name = vattr->vector_value("NAME");
on = vattr->vector_value("ON");
cmd = vattr->vector_value("COMMAND");
arg = vattr->vector_value("ARGUMENTS");
transform (on.begin(),on.end(),on.begin(),(int(*)(int))toupper);
if (name.empty())
{
name = cmd;
}
if ( on == "CREATE" )
{
VirtualMachineAllocateHook * hook;
hook = new VirtualMachineAllocateHook(name,cmd,arg);
add_hook(hook);
}
else
{
ostringstream oss;
oss << "Unkown VM_HOOK " << on << ". Hook not registered!";
Nebula::log("VM",Log::WARNING,oss);
}
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachinePool::allocate (
int uid,
const string& stemplate,