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

Feature #1103: Patch by Simon Boulet

This commit is contained in:
Carlos Martín 2012-12-20 18:21:30 +01:00
parent 0595af3973
commit 64b4f0d5d9
8 changed files with 71 additions and 11 deletions

View File

@ -102,6 +102,14 @@ public:
Template::get(_name,value);
};
void get(const char *name, bool& value) const
{
string _name(name);
Template::get(_name,value);
};
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------

View File

@ -265,6 +265,19 @@ public:
const string& name,
float& value) const;
/**
* Gets the value of a Single attributes (bool) with the given name.
* @param name the attribute name.
* @param value the attribute value, a bool, false if the attribute is not
* defined or not Single
*
* @return True if the Single attribute was found and is a valid bool
* value
*/
virtual bool get(
const string& name,
bool& value) const;
friend ostream& operator<<(ostream& os, const Template& t);
/**

View File

@ -37,7 +37,8 @@ public:
const string& hook_location,
const string& remotes_location,
vector<const Attribute *>& restricted_attrs,
time_t expire_time);
time_t expire_time,
bool on_hold);
~VirtualMachinePool(){};
@ -48,7 +49,6 @@ public:
* @param vm_template a VM Template object describing the VM
* @param oid the id assigned to the VM (output)
* @param error_str Returns the error reason, if any
* @param on_hold flag to submit on hold
* @return oid on success, -1 error inserting in DB or -2 error parsing
* the template
*/
@ -59,8 +59,7 @@ public:
const string& gname,
VirtualMachineTemplate * vm_template,
int * oid,
string& error_str,
bool on_hold = false);
string& error_str);
/**
* Function to get a VM from the pool, if the object is not in memory
@ -255,6 +254,11 @@ private:
* Size, in seconds, of the historical monitoring information
*/
static time_t _monitor_expiration;
/**
* True or false whether to submit new VM on HOLD or not
*/
static bool _submit_on_hold;
};
#endif /*VIRTUAL_MACHINE_POOL_H_*/

View File

@ -517,6 +517,8 @@ void Nebula::start()
time_t vm_expiration;
time_t host_expiration;
bool vm_submit_on_hold;
vector<const Attribute *> vm_hooks;
vector<const Attribute *> host_hooks;
vector<const Attribute *> vnet_hooks;
@ -543,12 +545,15 @@ void Nebula::start()
nebula_configuration->get("VM_MONITORING_EXPIRATION_TIME",vm_expiration);
nebula_configuration->get("HOST_MONITORING_EXPIRATION_TIME",host_expiration);
nebula_configuration->get("VM_SUBMIT_ON_HOLD",vm_submit_on_hold);
vmpool = new VirtualMachinePool(db,
vm_hooks,
hook_location,
remotes_location,
vm_restricted_attrs,
vm_expiration);
vm_expiration,
vm_submit_on_hold);
hpool = new HostPool(db,
host_hooks,
hook_location,

View File

@ -244,7 +244,7 @@ int VirtualMachineAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
Template tmpl_back(*tmpl);
int rc = vmpool->allocate(att.uid, att.gid, att.uname, att.gname, ttmpl, &id,
error_str, false);
error_str);
if ( rc < 0 )
{

View File

@ -109,7 +109,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
Template tmpl_back(*tmpl);
rc = vmpool->allocate(att.uid, att.gid, att.uname, att.gname, tmpl, &vid,
error_str, false);
error_str);
if ( rc < 0 )
{

View File

@ -473,6 +473,34 @@ bool Template::get(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool Template::get(
const string& name,
bool& value) const
{
string sval;
get(name, sval);
if ( sval == "" )
{
value = false;
return false;
}
if ( sval == "1" || sval == "true" || sval == "YES" ) {
value = true;
}
else
{
value = false;
}
return true;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string& Template::to_xml(string& xml) const
{
multimap<string,Attribute *>::const_iterator it;

View File

@ -25,6 +25,7 @@
/* -------------------------------------------------------------------------- */
time_t VirtualMachinePool::_monitor_expiration;
bool VirtualMachinePool::_submit_on_hold;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -35,7 +36,8 @@ VirtualMachinePool::VirtualMachinePool(
const string& hook_location,
const string& remotes_location,
vector<const Attribute *>& restricted_attrs,
time_t expire_time)
time_t expire_time,
bool on_hold)
: PoolSQL(db, VirtualMachine::table, false)
{
const VectorAttribute * vattr;
@ -50,6 +52,7 @@ VirtualMachinePool::VirtualMachinePool(
bool state_hook = false;
_monitor_expiration = expire_time;
_submit_on_hold = on_hold;
if ( _monitor_expiration == 0 )
{
@ -222,8 +225,7 @@ int VirtualMachinePool::allocate (
const string& gname,
VirtualMachineTemplate * vm_template,
int * oid,
string& error_str,
bool on_hold)
string& error_str)
{
VirtualMachine * vm;
@ -232,7 +234,7 @@ int VirtualMachinePool::allocate (
// ------------------------------------------------------------------------
vm = new VirtualMachine(-1, uid, gid, uname, gname, vm_template);
if (on_hold == true)
if (_submit_on_hold == true)
{
vm->state = VirtualMachine::HOLD;
}