mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-08 21:17:43 +03:00
Feature #3264: Add a method to calculate the showback data
This commit is contained in:
parent
5c30484027
commit
d2cc25ba8e
@ -363,4 +363,29 @@ public:
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachinePoolCalculateShowback : public RequestManagerVirtualMachine
|
||||
{
|
||||
public:
|
||||
|
||||
VirtualMachinePoolCalculateShowback():
|
||||
RequestManagerVirtualMachine("VirtualMachinePoolCalculateShowback",
|
||||
"Processes all the history records, and stores the monthly cost for each VM",
|
||||
"A:sii")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = PoolObjectSQL::VM;
|
||||
};
|
||||
|
||||
~VirtualMachinePoolCalculateShowback(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
||||
|
@ -276,8 +276,14 @@ public:
|
||||
/**
|
||||
* Processes all the history records, and stores the monthly cost for each
|
||||
* VM
|
||||
* @param start_time Time to start processing. This date will be reset to
|
||||
* the first day of the month, at 00:00
|
||||
* @param end_time Time to stop processing. The data will actually be
|
||||
* processed up to the month before this date.
|
||||
*/
|
||||
void calculate_showback();
|
||||
void calculate_showback(
|
||||
time_t start_time,
|
||||
time_t end_time);
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -852,6 +852,44 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
end
|
||||
|
||||
START_TIME = {
|
||||
:name => "start_time",
|
||||
:short => "-s TIME",
|
||||
:large => "--start TIME" ,
|
||||
:description => "Start date for the showback data to process",
|
||||
:format => Time
|
||||
}
|
||||
|
||||
END_TIME = {
|
||||
:name => "end_time",
|
||||
:short => "-e TIME",
|
||||
:large => "--end TIME" ,
|
||||
:description => "End date for the showback data to process",
|
||||
:format => Time
|
||||
}
|
||||
|
||||
calculate_showback_desc = <<-EOT.unindent
|
||||
Development command to calculate showback data
|
||||
EOT
|
||||
|
||||
command :"calculate-showback", calculate_showback_desc, :options =>
|
||||
[START_TIME, END_TIME] do
|
||||
|
||||
start_time = options[:start_time] ? options[:start_time].to_i : -1
|
||||
end_time = options[:end_time] ? options[:end_time].to_i : -1
|
||||
|
||||
rc = OpenNebula::VirtualMachinePool.new(helper.client).calculate_showback(start_time, end_time)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
warn rc.message
|
||||
exit -1
|
||||
else
|
||||
puts rc
|
||||
exit 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Deprecated commands
|
||||
|
||||
deprecated_command(:attachdisk, 'disk-attach')
|
||||
|
@ -28,7 +28,8 @@ module OpenNebula
|
||||
:info => "vmpool.info",
|
||||
:monitoring => "vmpool.monitoring",
|
||||
:accounting => "vmpool.accounting",
|
||||
:showback => "vmpool.showback"
|
||||
:showback => "vmpool.showback",
|
||||
:calculate_showback => "vmpool.calculateshowback"
|
||||
}
|
||||
|
||||
# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
|
||||
@ -185,6 +186,23 @@ module OpenNebula
|
||||
options[:end_time])
|
||||
end
|
||||
|
||||
# Processes all the history records, and stores the monthly cost for
|
||||
# each VM
|
||||
#
|
||||
# @param [Integer]
|
||||
# @param [Integer] start_time Time to start processing. This date will
|
||||
# be reset to the first day of the month, at 00:00
|
||||
# @param [Integer] end_time Time to stop processing. The data will
|
||||
# actually be processed up to the month before this date.
|
||||
def calculate_showback(start_time, end_time)
|
||||
start_time ||= -1
|
||||
end_time ||= -1
|
||||
|
||||
return @client.call(VM_POOL_METHODS[:calculate_showback],
|
||||
start_time,
|
||||
end_time)
|
||||
end
|
||||
|
||||
# Retrieves the accounting data for all the VMs in the pool
|
||||
#
|
||||
# @param [Integer] filter_flag Optional filter flag to retrieve all or
|
||||
|
@ -300,9 +300,11 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr vm_recover(new VirtualMachineRecover());
|
||||
|
||||
xmlrpc_c::methodPtr vm_pool_acct(new VirtualMachinePoolAccounting());
|
||||
xmlrpc_c::methodPtr vm_pool_showback(new VirtualMachinePoolShowback());
|
||||
xmlrpc_c::methodPtr vm_pool_monitoring(new VirtualMachinePoolMonitoring());
|
||||
|
||||
xmlrpc_c::methodPtr vm_pool_showback(new VirtualMachinePoolShowback());
|
||||
xmlrpc_c::methodPtr vm_pool_calculate_showback(new VirtualMachinePoolCalculateShowback());
|
||||
|
||||
// VirtualNetwork Methods
|
||||
xmlrpc_c::methodPtr vn_add_ar(new VirtualNetworkAddAddressRange());
|
||||
xmlrpc_c::methodPtr vn_rm_ar(new VirtualNetworkRmAddressRange());
|
||||
@ -438,8 +440,9 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
|
||||
RequestManagerRegistry.addMethod("one.vmpool.accounting", vm_pool_acct);
|
||||
RequestManagerRegistry.addMethod("one.vmpool.showback", vm_pool_showback);
|
||||
RequestManagerRegistry.addMethod("one.vmpool.monitoring", vm_pool_monitoring);
|
||||
RequestManagerRegistry.addMethod("one.vmpool.showback", vm_pool_showback);
|
||||
RequestManagerRegistry.addMethod("one.vmpool.calculateshowback", vm_pool_calculate_showback);
|
||||
|
||||
/* VM Template related methods*/
|
||||
RequestManagerRegistry.addMethod("one.template.update", template_update);
|
||||
|
@ -187,10 +187,6 @@ void VirtualMachinePoolShowback::request_execute(
|
||||
|
||||
where_filter(att, filter_flag, -1, -1, "", "", false, false, false, where);
|
||||
|
||||
// TODO debug: this will be a separate xml-rpc call
|
||||
(static_cast<VirtualMachinePool *>(pool))->calculate_showback();
|
||||
|
||||
|
||||
rc = (static_cast<VirtualMachinePool *>(pool))->dump_showback(oss,
|
||||
where,
|
||||
time_start,
|
||||
|
@ -2219,3 +2219,31 @@ void VirtualMachineRecover::request_execute(
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachinePoolCalculateShowback::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int time_start = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
int time_end = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
|
||||
ostringstream oss;
|
||||
string where;
|
||||
int rc;
|
||||
|
||||
// TODO: do a better auth? allow any user in the oneadmin group?
|
||||
if ( att.uid != 0 )
|
||||
{
|
||||
failure_response(AUTHORIZATION,
|
||||
authorization_error("Action reserved for oneadmin only", att),
|
||||
att);
|
||||
return;
|
||||
}
|
||||
|
||||
(static_cast<VirtualMachinePool *>(pool))->calculate_showback(time_start, time_end);
|
||||
|
||||
// TODO: return value?
|
||||
success_response("", att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ int VirtualMachinePool::min_stime_cb(void * _min_stime, int num, char **values,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void VirtualMachinePool::calculate_showback()
|
||||
void VirtualMachinePool::calculate_showback(time_t start_time, time_t end_time)
|
||||
{
|
||||
vector<xmlNodePtr> nodes;
|
||||
vector<xmlNodePtr>::iterator node_it;
|
||||
@ -480,9 +480,6 @@ void VirtualMachinePool::calculate_showback()
|
||||
map<int, map<time_t, float> >::iterator vm_it;
|
||||
map<time_t, float>::iterator vm_month_it;
|
||||
|
||||
time_t start_time;
|
||||
time_t end_time;
|
||||
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
ostringstream body;
|
||||
@ -500,9 +497,14 @@ void VirtualMachinePool::calculate_showback()
|
||||
// Set start and end times for the window to process
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// TODO: init from params?
|
||||
start_time = time(0);
|
||||
if (end_time == -1)
|
||||
{
|
||||
end_time = time(0);
|
||||
}
|
||||
|
||||
if (start_time == -1)
|
||||
{
|
||||
start_time = time(0);
|
||||
|
||||
// Set start time to the lowest stime from the history records
|
||||
|
||||
@ -514,6 +516,7 @@ void VirtualMachinePool::calculate_showback()
|
||||
rc = db->exec(oss, this);
|
||||
|
||||
unset_callback();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Get accounting history records
|
||||
|
Loading…
Reference in New Issue
Block a user