mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Feature #3264: Method to dump showback records
This commit is contained in:
parent
68bac3a897
commit
be6dfcf8f0
@ -151,6 +151,31 @@ public:
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachinePoolShowback : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
|
||||
VirtualMachinePoolShowback():
|
||||
RequestManagerPoolInfoFilter("VirtualMachinePoolShowback",
|
||||
"Returns the virtual machine showback records",
|
||||
"A:siii")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = PoolObjectSQL::VM;
|
||||
};
|
||||
|
||||
~VirtualMachinePoolShowback(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachinePoolMonitoring : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
|
@ -230,6 +230,19 @@ public:
|
||||
int time_start,
|
||||
int time_end);
|
||||
|
||||
/**
|
||||
* Dumps the VM showback information in XML format. A filter can be also
|
||||
* added to the query as well as a time frame.
|
||||
* @param oss the output stream to dump the pool contents
|
||||
* @param where filter for the objects, defaults to all
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump_showback(ostringstream& oss,
|
||||
const string& where,
|
||||
int time_start,
|
||||
int time_end);
|
||||
|
||||
/**
|
||||
* Dumps the VM monitoring information entries in XML format. A filter
|
||||
* can be also added to the query.
|
||||
|
@ -834,6 +834,24 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
end
|
||||
|
||||
showback_desc = <<-EOT.unindent
|
||||
Development command to get raw showback data
|
||||
EOT
|
||||
|
||||
command :showback, showback_desc, [:filterflag, nil] do
|
||||
|
||||
rc = OpenNebula::VirtualMachinePool.new(helper.client).showback_xml(args[0])
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
warn rc.message
|
||||
exit -1
|
||||
else
|
||||
puts rc
|
||||
exit 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Deprecated commands
|
||||
|
||||
deprecated_command(:attachdisk, 'disk-attach')
|
||||
|
@ -27,7 +27,8 @@ module OpenNebula
|
||||
VM_POOL_METHODS = {
|
||||
:info => "vmpool.info",
|
||||
:monitoring => "vmpool.monitoring",
|
||||
:accounting => "vmpool.accounting"
|
||||
:accounting => "vmpool.accounting",
|
||||
:showback => "vmpool.showback"
|
||||
}
|
||||
|
||||
# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
|
||||
@ -162,6 +163,28 @@ module OpenNebula
|
||||
return @client.call(VM_POOL_METHODS[:monitoring], filter_flag)
|
||||
end
|
||||
|
||||
# Retrieves the showback data for all the VMs in the pool, in XML
|
||||
#
|
||||
# @param [Integer] filter_flag Optional filter flag to retrieve all or
|
||||
# part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE
|
||||
# or user_id
|
||||
# @param [Hash] options
|
||||
# @option params [Integer] :start_time Start date and time to take into account,
|
||||
# if no start_time is required use -1
|
||||
# @option params [Integer] :end_time End date and time to take into account,
|
||||
# if no end_time is required use -1
|
||||
def showback_xml(filter_flag=INFO_ALL, options={})
|
||||
|
||||
filter_flag ||= INFO_ALL
|
||||
options[:start_time] ||= -1
|
||||
options[:end_time] ||= -1
|
||||
|
||||
return @client.call(VM_POOL_METHODS[:showback],
|
||||
filter_flag,
|
||||
options[:start_time],
|
||||
options[: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,6 +300,7 @@ 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());
|
||||
|
||||
// VirtualNetwork Methods
|
||||
@ -437,6 +438,7 @@ 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);
|
||||
|
||||
/* VM Template related methods*/
|
||||
|
@ -165,6 +165,50 @@ void VirtualMachinePoolAccounting::request_execute(
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachinePoolShowback::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int filter_flag = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
int time_start = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int time_end = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
|
||||
ostringstream oss;
|
||||
string where;
|
||||
int rc;
|
||||
|
||||
if ( filter_flag < MINE )
|
||||
{
|
||||
failure_response(XML_RPC_API,
|
||||
request_error("Incorrect filter_flag",""),
|
||||
att);
|
||||
return;
|
||||
}
|
||||
|
||||
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,
|
||||
time_end);
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL,request_error("Internal Error",""), att);
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(oss.str(), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachinePoolMonitoring::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
|
@ -354,6 +354,44 @@ int VirtualMachinePool::dump_acct(ostringstream& oss,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::dump_showback(ostringstream& oss,
|
||||
const string& where,
|
||||
int time_start,
|
||||
int time_end)
|
||||
{
|
||||
ostringstream cmd;
|
||||
|
||||
cmd << "SELECT " << VirtualMachine::showback_table << ".body FROM "
|
||||
<< VirtualMachine::showback_table
|
||||
<< " INNER JOIN " << VirtualMachine::table
|
||||
<< " WHERE vmid=oid";
|
||||
|
||||
if ( !where.empty() )
|
||||
{
|
||||
cmd << " AND " << where;
|
||||
}
|
||||
|
||||
if ( time_start != -1 || time_end != -1 )
|
||||
{
|
||||
if ( time_start != -1 )
|
||||
{
|
||||
cmd << " AND (etime > " << time_start << " OR etime = 0)";
|
||||
}
|
||||
|
||||
if ( time_end != -1 )
|
||||
{
|
||||
cmd << " AND stime < " << time_end;
|
||||
}
|
||||
}
|
||||
|
||||
cmd << " ORDER BY year,month,vmid";
|
||||
|
||||
return PoolSQL::dump(oss, "SHOWBACK_RECORDS", cmd);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachinePool::clean_expired_monitoring()
|
||||
{
|
||||
if ( _monitor_expiration == 0 )
|
||||
|
Loading…
Reference in New Issue
Block a user