1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

feature #3718: Fix errors in acct with new monitor. feature #3782: Fix

acct to account for new snapshots in running. feature #3718: Reset CPU and MEMORY counters
This commit is contained in:
Ruben S. Montero 2015-07-13 18:24:58 +02:00
parent 29d9223986
commit 0ad70f2142
4 changed files with 80 additions and 6 deletions

View File

@ -61,7 +61,9 @@ public:
DISK_ATTACH_ACTION = 21,
DISK_DETACH_ACTION = 22,
NIC_ATTACH_ACTION = 23,
NIC_DETACH_ACTION = 24
NIC_DETACH_ACTION = 24,
DISK_SNAPSHOT_CREATE_ACTION = 25,
DISK_SNAPSHOT_DELETE_ACTION = 26
};
static string action_to_str(VMAction action)
@ -139,6 +141,12 @@ public:
case NIC_DETACH_ACTION:
st = "nic-detach";
break;
case DISK_SNAPSHOT_CREATE_ACTION:
st = "snap-create";
break;
case DISK_SNAPSHOT_DELETE_ACTION:
st = "snap-delete";
break;
case NONE_ACTION:
case BOOT_ACTION:
st = "none";
@ -242,6 +250,14 @@ public:
{
action = NIC_DETACH_ACTION;
}
else if (st == "snap-create")
{
action = DISK_SNAPSHOT_CREATE_ACTION;
}
else if (st == "snap-delete")
{
action = DISK_SNAPSHOT_DELETE_ACTION;
}
else //BOOT_ACTION and others
{
action = NONE_ACTION;

View File

@ -416,14 +416,17 @@ public:
int update_info(const string& monitor_data);
/**
* Clears the VM monitor information: usage counters, last_poll,
* custom attributes, and copies it to the history record for acct.
* Clears the VM monitor information usage counters (MEMORY, CPU),
* last_poll, custom attributes, and copies it to the history record
* for acct.
*/
void reset_info()
{
last_poll = time(0);
monitoring.clear();
monitoring.replace("CPU","0.0");
monitoring.replace("MEMORY","0");
set_vm_info();

View File

@ -1620,6 +1620,7 @@ int DispatchManager::disk_snapshot_create(
string& error_str)
{
ostringstream oss;
time_t the_time;
VirtualMachine * vm = vmpool->get(vid, true);
@ -1652,6 +1653,9 @@ int DispatchManager::disk_snapshot_create(
return -1;
}
// Set the VM info in the history before the snapshot is added to VM
vm->set_vm_info();
snap_id = vm->new_disk_snapshot(did, name, error_str);
if (snap_id == -1)
@ -1692,6 +1696,29 @@ int DispatchManager::disk_snapshot_create(
break;
case VirtualMachine::ACTIVE:
the_time = time(0);
// Close current history record
vm->set_running_etime(the_time);
vm->set_etime(the_time);
vm->set_action(History::DISK_SNAPSHOT_CREATE_ACTION);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
vm->cp_history();
vm->set_stime(the_time);
vm->set_running_stime(the_time);
vmpool->update_history(vm);
vmm->trigger(VirtualMachineManager::DISK_SNAPSHOT_CREATE, vid);
break;
@ -1807,6 +1834,7 @@ int DispatchManager::disk_snapshot_delete(
string& error_str)
{
ostringstream oss;
time_t the_time;
VirtualMachine * vm = vmpool->get(vid, true);
@ -1858,6 +1886,9 @@ int DispatchManager::disk_snapshot_delete(
return -1;
}
// Set the VM info in the history before the snapshot is removed from the VM
vm->set_vm_info();
switch(state)
{
case VirtualMachine::POWEROFF:
@ -1884,9 +1915,32 @@ int DispatchManager::disk_snapshot_delete(
switch(state)
{
case VirtualMachine::ACTIVE:
the_time = time(0);
// Close current history record
vm->set_running_etime(the_time);
vm->set_etime(the_time);
vm->set_action(History::DISK_SNAPSHOT_DELETE_ACTION);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
vm->cp_history();
vm->set_stime(the_time);
vm->set_running_stime(the_time);
vmpool->update_history(vm);
case VirtualMachine::POWEROFF:
case VirtualMachine::SUSPENDED:
case VirtualMachine::ACTIVE:
tm->trigger(TransferManager::SNAPSHOT_DELETE, vid);
break;

View File

@ -201,7 +201,8 @@ module OpenNebula
HISTORY_ACTION=%w{none migrate live-migrate shutdown shutdown-hard
undeploy undeploy-hard hold release stop suspend resume boot delete
delete-recreate reboot reboot-hard resched unresched poweroff
poweroff-hard disk-attach disk-detach nic-attach nic-detach}
poweroff-hard disk-attach disk-detach nic-attach nic-detach
snap-create snap-delete}
EXTERNAL_IP_ATTRS = [
'GUEST_IP',