mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-29 18:50:08 +03:00
Feature #3458: Add a default cost to oned.conf
This commit is contained in:
parent
f29bc3c161
commit
2706e3f546
@ -38,7 +38,9 @@ public:
|
||||
const string& remotes_location,
|
||||
vector<const Attribute *>& restricted_attrs,
|
||||
time_t expire_time,
|
||||
bool on_hold);
|
||||
bool on_hold,
|
||||
float default_cpu_cost,
|
||||
float default_mem_cost);
|
||||
|
||||
~VirtualMachinePool(){};
|
||||
|
||||
@ -325,6 +327,12 @@ private:
|
||||
*/
|
||||
static bool _submit_on_hold;
|
||||
|
||||
/**
|
||||
* Default values for cpu and memory cost
|
||||
*/
|
||||
static float _default_cpu_cost;
|
||||
static float _default_mem_cost;
|
||||
|
||||
/**
|
||||
* Callback used in calculate_showback
|
||||
*/
|
||||
|
@ -108,6 +108,19 @@ FEDERATION = [
|
||||
MASTER_ONED = ""
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
# Default showback cost
|
||||
#-------------------------------------------------------------------------------
|
||||
# The following attributes define the default cost for Virtual Machines that
|
||||
# don't have a CPU or MEMORY cost. This is used by the oneshowback calculate
|
||||
# method.
|
||||
#*******************************************************************************
|
||||
|
||||
DEFAULT_COST = [
|
||||
CPU_COST = 0,
|
||||
MEMORY_COST = 0
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
# XML-RPC server configuration
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -466,6 +466,8 @@ void Nebula::start(bool bootstrap_only)
|
||||
time_t host_expiration;
|
||||
|
||||
bool vm_submit_on_hold;
|
||||
float cpu_cost;
|
||||
float mem_cost;
|
||||
|
||||
vector<const Attribute *> vm_hooks;
|
||||
vector<const Attribute *> host_hooks;
|
||||
@ -482,6 +484,8 @@ void Nebula::start(bool bootstrap_only)
|
||||
vector<const Attribute *> inherit_datastore_attrs;
|
||||
vector<const Attribute *> inherit_vnet_attrs;
|
||||
|
||||
vector<const Attribute *> default_cost;
|
||||
|
||||
clpool = new ClusterPool(db);
|
||||
docpool = new DocumentPool(db);
|
||||
zonepool= new ZonePool(db, is_federation_slave());
|
||||
@ -507,13 +511,41 @@ void Nebula::start(bool bootstrap_only)
|
||||
|
||||
nebula_configuration->get("VM_SUBMIT_ON_HOLD",vm_submit_on_hold);
|
||||
|
||||
rc = nebula_configuration->get("DEFAULT_COST", default_cost);
|
||||
|
||||
cpu_cost = 0;
|
||||
mem_cost = 0;
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
const VectorAttribute * vatt = static_cast<const VectorAttribute *>
|
||||
(default_cost[0]);
|
||||
|
||||
rc = vatt->vector_value("CPU_COST", cpu_cost);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
cpu_cost = 0;
|
||||
}
|
||||
|
||||
rc = vatt->vector_value("MEMORY_COST", mem_cost);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
mem_cost = 0;
|
||||
}
|
||||
}
|
||||
|
||||
vmpool = new VirtualMachinePool(db,
|
||||
vm_hooks,
|
||||
hook_location,
|
||||
remotes_location,
|
||||
vm_restricted_attrs,
|
||||
vm_expiration,
|
||||
vm_submit_on_hold);
|
||||
vm_submit_on_hold,
|
||||
cpu_cost,
|
||||
mem_cost);
|
||||
|
||||
hpool = new HostPool(db,
|
||||
host_hooks,
|
||||
hook_location,
|
||||
|
@ -215,6 +215,19 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
|
||||
vattribute = new VectorAttribute("FEDERATION",vvalue);
|
||||
conf_default.insert(make_pair(vattribute->name(),vattribute));
|
||||
|
||||
/*
|
||||
#*******************************************************************************
|
||||
# Default showback cost
|
||||
#*******************************************************************************
|
||||
*/
|
||||
vvalue.clear();
|
||||
vvalue.insert(make_pair("CPU_COST","0"));
|
||||
vvalue.insert(make_pair("MEMORY_COST","0"));
|
||||
|
||||
vattribute = new VectorAttribute("DEFAULT_COST",vvalue);
|
||||
conf_default.insert(make_pair(vattribute->name(),vattribute));
|
||||
|
||||
/*
|
||||
#*******************************************************************************
|
||||
# XML-RPC server configuration
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
time_t VirtualMachinePool::_monitor_expiration;
|
||||
bool VirtualMachinePool::_submit_on_hold;
|
||||
float VirtualMachinePool::_default_cpu_cost;
|
||||
float VirtualMachinePool::_default_mem_cost;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -37,7 +39,9 @@ VirtualMachinePool::VirtualMachinePool(
|
||||
const string& remotes_location,
|
||||
vector<const Attribute *>& restricted_attrs,
|
||||
time_t expire_time,
|
||||
bool on_hold)
|
||||
bool on_hold,
|
||||
float default_cpu_cost,
|
||||
float default_mem_cost)
|
||||
: PoolSQL(db, VirtualMachine::table, true, false)
|
||||
{
|
||||
const VectorAttribute * vattr;
|
||||
@ -52,6 +56,8 @@ VirtualMachinePool::VirtualMachinePool(
|
||||
|
||||
_monitor_expiration = expire_time;
|
||||
_submit_on_hold = on_hold;
|
||||
_default_cpu_cost = default_cpu_cost;
|
||||
_default_mem_cost = default_mem_cost;
|
||||
|
||||
if ( _monitor_expiration == 0 )
|
||||
{
|
||||
@ -699,8 +705,8 @@ int VirtualMachinePool::calculate_showback(
|
||||
history.xpath(cpu, "/HISTORY/VM/TEMPLATE/CPU", 0);
|
||||
history.xpath(mem, "/HISTORY/VM/TEMPLATE/MEMORY", 0);
|
||||
|
||||
history.xpath(cpu_cost, "/HISTORY/VM/TEMPLATE/CPU_COST", 0);
|
||||
history.xpath(mem_cost, "/HISTORY/VM/TEMPLATE/MEMORY_COST", 0);
|
||||
history.xpath(cpu_cost, "/HISTORY/VM/TEMPLATE/CPU_COST", _default_cpu_cost);
|
||||
history.xpath(mem_cost, "/HISTORY/VM/TEMPLATE/MEMORY_COST", _default_mem_cost);
|
||||
|
||||
#ifdef SBDDEBUG
|
||||
int seq;
|
||||
@ -860,11 +866,13 @@ int VirtualMachinePool::calculate_showback(
|
||||
debug << "VM " << vm_it->first
|
||||
<< " cost for Y " << tmp_tm.tm_year + 1900
|
||||
<< " M " << tmp_tm.tm_mon + 1
|
||||
<< " COST " << cost << " €"
|
||||
<< " HOURS " << hours;
|
||||
<< " COST " << one_util::float_to_str(
|
||||
vm_month_it->second.cpu_cost +
|
||||
vm_month_it->second.mem_cost) << " €"
|
||||
<< " HOURS " << vm_month_it->second.hours;
|
||||
|
||||
NebulaLog::log("SHOWBACK", Log::DEBUG, debug);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user