diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index f10b017012..932f35534e 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -33,7 +33,7 @@ class VirtualMachinePool : public PoolSQL { public: - VirtualMachinePool(SqliteDB * db); + VirtualMachinePool(SqliteDB * db, vector hook_mads); ~VirtualMachinePool(){}; diff --git a/share/etc/oned.conf b/share/etc/oned.conf index bf383ed0ee..36412e61e0 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -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" ] +#------------------------------------------------------------------------------- + + + + + diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index c6901f66d3..8b9f405c35 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -140,7 +140,11 @@ void Nebula::start() string mac_prefix; int size; - vmpool = new VirtualMachinePool(db); + vector 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); diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 0be071d006..c5eb4e2bd8 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -20,21 +20,57 @@ #include "VirtualMachineHook.h" #include -VirtualMachinePool::VirtualMachinePool(SqliteDB * db): - PoolSQL(db,VirtualMachine::table) +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +VirtualMachinePool::VirtualMachinePool(SqliteDB * db, + vector 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(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,