From 3dc9a5043f9b2dd11f7005802c82548824c59107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 5 Nov 2014 13:34:29 +0100 Subject: [PATCH] Feature #3264: Add extra info to showback xml body --- src/vm/VirtualMachinePool.cc | 55 +++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 97ee2136a7..aa9ee823a1 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -475,10 +475,12 @@ void VirtualMachinePool::calculate_showback(time_t start_time, time_t end_time) vector showback_slots; vector::iterator slot_it; - // map > - map > vm_cost; - map >::iterator vm_it; - map::iterator vm_month_it; + // map > > + map > > vm_cost; + map > >::iterator vm_it; + map >::iterator vm_month_it; + + VirtualMachine* vm; int rc; ostringstream oss; @@ -615,14 +617,15 @@ void VirtualMachinePool::calculate_showback(time_t start_time, time_t end_time) cost += mem_cost * mem * n_hours; // Add to vm time slot. - map& total_cost = vm_cost[vid]; + map >& totals = vm_cost[vid]; - if(total_cost.count(t) == 0) + if(totals.count(t) == 0) { - total_cost[t] = 0; + totals[t] = make_pair(0,0); } - total_cost[t] += cost; + totals[t].first += cost; + totals[t].second += n_hours; } } } @@ -633,10 +636,30 @@ void VirtualMachinePool::calculate_showback(time_t start_time, time_t end_time) for ( vm_it = vm_cost.begin(); vm_it != vm_cost.end(); vm_it++ ) { - map& total_cost = vm_it->second; + map >& totals = vm_it->second; - for ( vm_month_it = total_cost.begin(); vm_month_it != total_cost.end(); vm_month_it++ ) + for ( vm_month_it = totals.begin(); vm_month_it != totals.end(); vm_month_it++ ) { + int vmid = vm_it->first; + + vm = get(vmid, true); + + int uid = 0; + int gid = 0; + string uname = ""; + string gname = ""; + + if (vm != 0) + { + uid = vm->get_uid(); + gid = vm->get_gid(); + + uname = vm->get_uname(); + gname = vm->get_gname(); + + vm->unlock(); + } + tm tmp_tm = *localtime(&vm_month_it->first); body.str(""); @@ -644,10 +667,15 @@ void VirtualMachinePool::calculate_showback(time_t start_time, time_t end_time) // TODO: truncate float values to 2 decimals? body << "" - << "" << vm_it->first << "" + << "" << vmid << "" + << "" << uid << "" + << "" << gid << "" + << "" << uname << "" + << "" << gname << "" << "" << tmp_tm.tm_year + 1900 << "" << "" << tmp_tm.tm_mon + 1 << "" - << "" << vm_month_it->second << "" + << "" << vm_month_it->second.first << "" + << "" << vm_month_it->second.second << "" << ""; oss.str(""); @@ -678,7 +706,8 @@ void VirtualMachinePool::calculate_showback(time_t start_time, time_t end_time) st << "VM " << vm_it->first << " cost for Y " << tmp_tm.tm_year + 1900 << " M " << tmp_tm.tm_mon + 1 - << " COST " << vm_month_it->second << " €"; + << " COST " << vm_month_it->second.first << " €" + << " HOURS " << vm_month_it->second.second; NebulaLog::log("SHOWBACK", Log::DEBUG, st); //================================================================*/