1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-22 22:03:39 +03:00

F #5005: Add user ids and action request id to history records. Removed

uneeded reason history entry. Updated cli
This commit is contained in:
Ruben S. Montero 2017-02-10 14:19:55 +01:00
parent 62d9ec2b39
commit 0f7e642516
14 changed files with 103 additions and 158 deletions

View File

@ -29,12 +29,6 @@ using namespace std;
class History:public ObjectSQL, public ObjectXML
{
public:
enum EndReason
{
NONE = 0, /** < History record is not closed yet */
ERROR = 1, /** < History record was closed because of an error */
USER = 2 /** < History record was closed because of a user action */
};
enum VMAction
{ //Associated XML-RPC API call
@ -81,7 +75,8 @@ public:
DISK_SAVEAS_ACTION = 40, // "one.vm.disksaveas"
DISK_SNAPSHOT_REVERT_ACTION = 41, // "one.vm.disksnapshotrevert"
RECOVER_ACTION = 42, // "one.vm.recover"
RETRY_ACTION = 43 // "one.vm.recover"
RETRY_ACTION = 43, // "one.vm.recover"
MONITOR_ACTION = 44 // internal, monitoring process
};
static string action_to_str(VMAction action);
@ -162,8 +157,6 @@ private:
time_t epilog_stime;
time_t epilog_etime;
EndReason reason;
VMAction action;
string vm_info;

View File

@ -452,6 +452,16 @@ public:
return (previous_history!=0);
};
bool is_history_open() const
{
return (history != 0) && (history->etime == 0);
}
bool is_previous_history_open() const
{
return (previous_history != 0) && (previous_history->etime == 0);
}
/**
* Returns the VMM driver name for the current host. The hasHistory()
* function MUST be called before this one.
@ -637,15 +647,6 @@ public:
return previous_history->hostname;
};
/**
* Returns the reason that closed the history record in the previous host
* @return the reason to close the history record in the previous host
*/
const History::EndReason get_previous_reason() const
{
return previous_history->reason;
};
/**
* Returns the action that closed the current history record. The hasHistory()
* function MUST be called before this one.
@ -815,24 +816,6 @@ public:
history->epilog_etime=_etime;
};
/**
* Sets the reason that closed the history record
* @param _reason reason to close the history record
*/
void set_reason(History::EndReason _reason)
{
history->reason=_reason;
};
/**
* Sets the reason that closed the history record in the previous host
* @param _reason reason to close the history record in the previous host
*/
void set_previous_reason(History::EndReason _reason)
{
previous_history->reason=_reason;
};
/**
* Sets the action that closed the history record
* @param action that closed the history record
@ -847,6 +830,16 @@ public:
history->req_id = req_id;
};
void set_internal_action(History::VMAction action)
{
history->action = action;
history->uid = -1;
history->gid = -1;
history->req_id = -1;
};
void clear_action()
{
history->action = History::NONE_ACTION;
@ -857,13 +850,14 @@ public:
history->req_id = -1;
}
/**
* Sets the action that closed the history record in the previous host
* @param action that closed the history record in the previous host
*/
void set_previous_action(History::VMAction action)
void set_previous_action(History::VMAction action, int uid, int gid,int rid)
{
previous_history->action = action;
previous_history->uid = uid;
previous_history->gid = gid;
previous_history->req_id = rid;
};
// ------------------------------------------------------------------------

View File

@ -30,13 +30,6 @@
<xs:element name="ESTIME" type="xs:integer"/>
<xs:element name="EETIME" type="xs:integer"/>
<!-- REASON values:
NONE = 0 History record is not closed yet
ERROR = 1 History record was closed because of an error
USER = 2 History record was closed because of a user action
-->
<xs:element name="REASON" type="xs:integer"/>
<!-- ACTION values:
NONE_ACTION = 0
MIGRATE_ACTION = 1
@ -67,6 +60,22 @@
DISK_SNAPSHOT_DELETE_ACTION = 26
TERMINATE_ACTION = 27
TERMINATE_HARD_ACTION = 28
DISK_RESIZE_ACTION = 29
DEPLOY_ACTION = 30
CHOWN_ACTION = 31
CHMOD_ACTION = 32
UPDATECONF_ACTION = 33
RENAME_ACTION = 34
RESIZE_ACTION = 35
UPDATE_ACTION = 36
SNAPSHOT_CREATE_ACTION = 37
SNAPSHOT_DELETE_ACTION = 38
SNAPSHOT_REVERT_ACTION = 39
DISK_SAVEAS_ACTION = 40
DISK_SNAPSHOT_REVERT_ACTION = 41
RECOVER_ACTION = 42
RETRY_ACTION = 43
MONITOR_ACTION = 44
-->
<xs:element name="ACTION" type="xs:integer"/>

View File

@ -87,13 +87,6 @@
<xs:element name="ESTIME" type="xs:integer"/>
<xs:element name="EETIME" type="xs:integer"/>
<!-- REASON values:
NONE = 0 History record is not closed yet
ERROR = 1 History record was closed because of an error
USER = 2 History record was closed because of a user action
-->
<xs:element name="REASON" type="xs:integer"/>
<!-- ACTION values:
NONE_ACTION = 0
MIGRATE_ACTION = 1
@ -124,6 +117,22 @@
DISK_SNAPSHOT_DELETE_ACTION = 26
TERMINATE_ACTION = 27
TERMINATE_HARD_ACTION = 28
DISK_RESIZE_ACTION = 29
DEPLOY_ACTION = 30
CHOWN_ACTION = 31
CHMOD_ACTION = 32
UPDATECONF_ACTION = 33
RENAME_ACTION = 34
RESIZE_ACTION = 35
UPDATE_ACTION = 36
SNAPSHOT_CREATE_ACTION = 37
SNAPSHOT_DELETE_ACTION = 38
SNAPSHOT_REVERT_ACTION = 39
DISK_SAVEAS_ACTION = 40
DISK_SNAPSHOT_REVERT_ACTION = 41
RECOVER_ACTION = 42
RETRY_ACTION = 43
MONITOR_ACTION = 44
-->
<xs:element name="ACTION" type="xs:integer"/>
</xs:sequence>

View File

@ -21,11 +21,6 @@
:size: 16
:left: true
:REASON:
:desc: VM state change reason
:size: 4
:left: true
:START_TIME:
:desc: Start time
:size: 14
@ -58,7 +53,6 @@
- :VID
- :HOSTNAME
- :ACTION
- :REASON
- :START_TIME
- :END_TIME
- :MEMORY

View File

@ -135,10 +135,6 @@ class AcctHelper < OpenNebulaHelper::OneHelper
VirtualMachine.get_history_action d["ACTION"]
end
column :REASON, "VM state change reason", :left, :size=>4 do |d|
VirtualMachine.get_reason d["REASON"]
end
column :START_TIME, "Start time", :size=>14 do |d|
OpenNebulaHelper.time_to_str(d['STIME'])
end
@ -187,7 +183,7 @@ class AcctHelper < OpenNebulaHelper::OneHelper
OpenNebulaHelper.unit_to_str(total_disk_size * 1024.0, {})
end
default :VID, :HOSTNAME, :ACTION, :REASON, :START_TIME, :END_TIME, :MEMORY, :CPU, :NETRX, :NETTX, :DISK
default :VID, :HOSTNAME, :ACTION, :START_TIME, :END_TIME, :MEMORY, :CPU, :NETRX, :NETTX, :DISK
end
SHOWBACK_TABLE = CLIHelper::ShowTable.new(self.table_conf("oneshowback.yaml"), nil) do

View File

@ -1023,10 +1023,6 @@ in the frontend machine.
VirtualMachine.get_history_action d["ACTION"]
end
column :REASON, "VM state change reason", :left, :size=>4 do |d|
VirtualMachine.get_reason d["REASON"]
end
column :DS, "System Datastore", :size=>4 do |d|
d["DS_ID"]
end

View File

@ -1219,7 +1219,6 @@ int DispatchManager::attach(int vid, VirtualMachineTemplate * tmpl,
vm->set_etime(the_time);
vm->set_action(History::DISK_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_reason(History::USER);
vmpool->update_history(vm);
@ -1310,7 +1309,6 @@ int DispatchManager::detach(int vid, int disk_id, const RequestAttributes& ra,
vm->set_etime(the_time);
vm->set_action(History::DISK_DETACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_reason(History::USER);
vmpool->update_history(vm);
@ -1592,8 +1590,6 @@ int DispatchManager::attach_nic(int vid, VirtualMachineTemplate* tmpl,
vm->set_action(History::NIC_ATTACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
@ -1685,8 +1681,6 @@ int DispatchManager::detach_nic(int vid, int nic_id,const RequestAttributes& ra,
vm->set_action(History::NIC_DETACH_ACTION, ra.uid, ra.gid, ra.req_id);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
@ -1819,8 +1813,6 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name,
vm->set_action(History::DISK_SNAPSHOT_CREATE_ACTION, ra.uid, ra.gid,
ra.req_id);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
@ -2017,8 +2009,6 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id,
vm->set_action(History::DISK_SNAPSHOT_DELETE_ACTION, ra.uid, ra.gid,
ra.req_id);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
@ -2134,8 +2124,6 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size,
vm->set_action(History::DISK_RESIZE_ACTION, ra.uid, ra.gid,
ra.req_id);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record

View File

@ -83,7 +83,7 @@ void DispatchManager::stop_success_action(int vid)
//Set history action field to perform the right TM command on resume
if (vm->get_action() == History::NONE_ACTION)
{
vm->set_action(History::STOP_ACTION, -1, -1, -1);
vm->set_internal_action(History::STOP_ACTION);
vmpool->update_history(vm);
}
@ -130,7 +130,7 @@ void DispatchManager::undeploy_success_action(int vid)
//Set history action field to perform the right TM command on resume
if (vm->get_action() == History::NONE_ACTION)
{
vm->set_action(History::UNDEPLOY_ACTION, -1, -1, -1);
vm->set_internal_action(History::UNDEPLOY_ACTION);
vmpool->update_history(vm);
}

View File

@ -128,7 +128,6 @@ void LifeCycleManager::suspend_action(const LCMAction& la)
vm->set_action(History::SUSPEND_ACTION, la.uid(), la.gid(), la.req_id());
vmpool->update_history(vm);
//----------------------------------------------------
@ -244,7 +243,10 @@ void LifeCycleManager::migrate_action(const LCMAction& la)
vm->set_stime(the_time);
vm->set_previous_action(History::MIGRATE_ACTION);
vm->set_previous_action(History::MIGRATE_ACTION, la.uid(), la.gid(),
la.req_id());
vm->set_action(History::MIGRATE_ACTION, la.uid(), la.gid(), la.req_id());
vmpool->update_history(vm);
@ -267,10 +269,15 @@ void LifeCycleManager::migrate_action(const LCMAction& la)
if (vm->get_state() == VirtualMachine::POWEROFF)
{
vm->set_state(VirtualMachine::PROLOG_MIGRATE_POWEROFF);
vm->set_action(History::MIGRATE_ACTION, la.uid(), la.gid(),
la.req_id());
}
else if (vm->get_state() == VirtualMachine::SUSPENDED)
{
vm->set_state(VirtualMachine::PROLOG_MIGRATE_SUSPEND);
vm->set_action(History::MIGRATE_ACTION, la.uid(), la.gid(),
la.req_id());
}
else //VirtualMachine::UNKNOWN
{
@ -280,9 +287,8 @@ void LifeCycleManager::migrate_action(const LCMAction& la)
vm->set_previous_etime(the_time);
vm->set_previous_action(History::MIGRATE_ACTION);
vm->set_previous_reason(History::USER);
vm->set_previous_action(History::MIGRATE_ACTION, la.uid(), la.gid(),
la.req_id());
vm->set_previous_vm_info();
@ -365,7 +371,11 @@ void LifeCycleManager::live_migrate_action(const LCMAction& la)
vmpool->update_history(vm);
vm->set_previous_action(History::LIVE_MIGRATE_ACTION);
vm->set_previous_action(History::LIVE_MIGRATE_ACTION, la.uid(),la.gid(),
la.req_id());
vm->set_action(History::LIVE_MIGRATE_ACTION, la.uid(), la.gid(),
la.req_id());
vmpool->update_previous_history(vm);
@ -415,8 +425,6 @@ void LifeCycleManager::shutdown_action(const LCMAction& la, bool hard)
vm->set_action(History::TERMINATE_HARD_ACTION, la.uid(), la.gid(),
la.req_id());
//----------------------------------------------------
vmm->trigger(VMMAction::CANCEL,vid);
}
else
@ -424,8 +432,6 @@ void LifeCycleManager::shutdown_action(const LCMAction& la, bool hard)
vm->set_action(History::TERMINATE_ACTION, la.uid(), la.gid(),
la.req_id());
//----------------------------------------------------
vmm->trigger(VMMAction::SHUTDOWN,vid);
}
@ -675,6 +681,8 @@ void LifeCycleManager::restore_action(const LCMAction& la)
vm->set_running_stime(the_time);
vm->set_action(History::RESUME_ACTION, la.uid(), la.gid(), la.req_id());
vmpool->update_history(vm);
//----------------------------------------------------
@ -718,7 +726,7 @@ void LifeCycleManager::restart_action(const LCMAction& la)
{
time_t the_time = time(0);
vm->set_state(VirtualMachine::ACTIVE); // Only needed by poweroff
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::BOOT_POWEROFF);
@ -732,6 +740,8 @@ void LifeCycleManager::restart_action(const LCMAction& la)
vm->set_running_stime(the_time);
vm->set_action(History::RESUME_ACTION, la.uid(), la.gid(), la.req_id());
vmpool->update_history(vm);
vmm->trigger(VMMAction::DEPLOY, vid);
@ -941,7 +951,6 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose,
vm->set_etime(the_time);
vm->set_vm_info();
vm->set_reason(History::USER);
vm->get_requirements(cpu, mem, disk, pci);
@ -1099,7 +1108,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose,
vm->set_previous_etime(the_time);
vm->set_previous_vm_info();
vm->set_previous_running_etime(the_time);
vm->set_previous_reason(History::USER);
vmpool->update_previous_history(vm);
hpool->del_capacity(vm->get_previous_hid(), vm->get_oid(), cpu,
@ -1125,7 +1134,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose,
vm->set_previous_etime(the_time);
vm->set_previous_vm_info();
vm->set_previous_running_etime(the_time);
vm->set_previous_reason(History::USER);
vmpool->update_previous_history(vm);
hpool->del_capacity(vm->get_previous_hid(), vm->get_oid(), cpu,

View File

@ -63,8 +63,6 @@ void LifeCycleManager::save_success_action(int vid)
vm->set_previous_running_etime(the_time);
vm->set_previous_reason(History::USER);
vmpool->update_previous_history(vm);
vm->set_prolog_stime(the_time);
@ -102,8 +100,6 @@ void LifeCycleManager::save_success_action(int vid)
vm->set_vm_info();
vm->set_reason(History::USER);
vmpool->update_history(vm);
//----------------------------------------------------
@ -133,8 +129,6 @@ void LifeCycleManager::save_success_action(int vid)
vm->set_running_etime(the_time);
vm->set_reason(History::USER);
vmpool->update_history(vm);
//----------------------------------------------------
@ -180,8 +174,6 @@ void LifeCycleManager::save_failure_action(int vid)
vm->set_vm_info();
vm->set_reason(History::ERROR);
vmpool->update_history(vm);
vm->get_requirements(cpu, mem, disk, pci);
@ -194,8 +186,6 @@ void LifeCycleManager::save_failure_action(int vid)
vm->set_previous_running_etime(the_time);
vm->set_previous_reason(History::USER);
vmpool->update_previous_history(vm);
// --- Add new record by copying the previous one
@ -286,8 +276,6 @@ void LifeCycleManager::deploy_success_action(int vid)
vm->set_previous_running_etime(the_time);
vm->set_previous_reason(History::USER);
vmpool->update_previous_history(vm);
vm->get_requirements(cpu, mem, disk, pci);
@ -317,6 +305,10 @@ void LifeCycleManager::deploy_success_action(int vid)
{
vm->set_state(VirtualMachine::RUNNING);
vm->clear_action();
vmpool->update_history(vm);
vmpool->update(vm);
}
else
@ -363,8 +355,6 @@ void LifeCycleManager::deploy_failure_action(int vid)
vm->set_vm_info();
vm->set_reason(History::ERROR);
vmpool->update_history(vm);
vm->set_previous_etime(the_time);
@ -373,8 +363,6 @@ void LifeCycleManager::deploy_failure_action(int vid)
vm->set_previous_running_etime(the_time);
vm->set_previous_reason(History::USER);
vmpool->update_previous_history(vm);
vm->get_requirements(cpu, mem, disk, pci);
@ -425,9 +413,6 @@ void LifeCycleManager::deploy_failure_action(int vid)
vm->set_etime(the_time);
vm->set_running_etime(the_time);
vm->set_reason(History::ERROR);
vm->set_action(History::RESUME_ACTION);
vm->set_state(VirtualMachine::POWEROFF);
vm->set_state(VirtualMachine::LCM_INIT);
@ -439,9 +424,6 @@ void LifeCycleManager::deploy_failure_action(int vid)
vm->set_etime(the_time);
vm->set_running_etime(the_time);
vm->set_reason(History::ERROR);
vm->set_action(History::RESUME_ACTION);
vm->set_state(VirtualMachine::SUSPENDED);
vm->set_state(VirtualMachine::LCM_INIT);
@ -508,8 +490,6 @@ void LifeCycleManager::shutdown_success_action(int vid)
vm->set_running_etime(the_time);
vm->set_reason(History::USER);
vmpool->update_history(vm);
//----------------------------------------------------
@ -537,8 +517,6 @@ void LifeCycleManager::shutdown_success_action(int vid)
vm->set_vm_info();
vm->set_reason(History::USER);
vmpool->update_history(vm);
//----------------------------------------------------
@ -566,8 +544,6 @@ void LifeCycleManager::shutdown_success_action(int vid)
vm->set_running_etime(the_time);
vm->set_reason(History::USER);
vmpool->update_history(vm);
//----------------------------------------------------
@ -608,7 +584,7 @@ void LifeCycleManager::shutdown_failure_action(int vid)
vmpool->update(vm);
vm->set_action(History::NONE_ACTION);
vm->clear_action();
vmpool->update_history(vm);
@ -731,10 +707,6 @@ void LifeCycleManager::prolog_success_action(int vid)
vm->set_vm_info();
vm->set_reason(History::USER);
vm->set_action(History::MIGRATE_ACTION);
vmpool->update_history(vm);
if (lcm_state == VirtualMachine::PROLOG_MIGRATE_POWEROFF||
@ -821,8 +793,6 @@ void LifeCycleManager::prolog_failure_action(int vid)
// Close current history record
vm->set_prolog_etime(t);
vm->set_etime(t);
vm->set_reason(History::ERROR);
vm->set_action(History::MIGRATE_ACTION);
vm->set_vm_info();
@ -1106,7 +1076,7 @@ void LifeCycleManager::monitor_suspend_action(int vid)
vm->set_vm_info();
vm->set_reason(History::ERROR);
vm->set_internal_action(History::MONITOR_ACTION);
vmpool->update_history(vm);
@ -1198,7 +1168,7 @@ void LifeCycleManager::monitor_poweroff_action(int vid)
vm->set_vm_info();
vm->set_reason(History::USER);
vm->set_internal_action(History::MONITOR_ACTION);
vmpool->update_history(vm);

View File

@ -203,14 +203,6 @@ module OpenNebula
"DISK_RESIZE_UNDEPLOYED" => "drsz"
}
MIGRATE_REASON=%w{NONE ERROR USER}
SHORT_MIGRATE_REASON={
"NONE" => "none",
"ERROR" => "erro",
"USER" => "user"
}
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
@ -218,7 +210,7 @@ module OpenNebula
disk-snapshot-create disk-snapshot-delete terminate terminate-hard
disk-resize deploy chown chmod updateconf rename resize update
snapshot-resize snapshot-delete snapshot-revert disk-saveas
disk-snapshot-revert recover retry}
disk-snapshot-revert recover retry monitor}
EXTERNAL_IP_ATTRS = [
'GUEST_IP',
@ -266,13 +258,6 @@ module OpenNebula
XMLElement.build_xml(vm_xml, 'VM')
end
def VirtualMachine.get_reason(reason)
reason=MIGRATE_REASON[reason.to_i]
reason_str=SHORT_MIGRATE_REASON[reason]
reason_str
end
def VirtualMachine.get_history_action(action)
return HISTORY_ACTION[action.to_i]
end

View File

@ -1056,7 +1056,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
return;
}
if((vm->hasPreviousHistory() && vm->get_previous_reason()== History::NONE)||
if( vm->is_previous_history_open() ||
(vm->get_state() != VirtualMachine::POWEROFF &&
vm->get_state() != VirtualMachine::SUSPENDED &&
(vm->get_state() != VirtualMachine::ACTIVE ||

View File

@ -54,7 +54,6 @@ History::History(
running_etime(0),
epilog_stime(0),
epilog_etime(0),
reason(NONE),
action(NONE_ACTION),
vm_info("<VM/>"){};
@ -86,7 +85,6 @@ History::History(
running_etime(0),
epilog_stime(0),
epilog_etime(0),
reason(NONE),
action(NONE_ACTION),
vm_info(_vm_info)
{
@ -311,7 +309,6 @@ string& History::to_xml(string& xml, bool database) const
"<RETIME>" << running_etime << "</RETIME>"<<
"<ESTIME>" << epilog_stime << "</ESTIME>"<<
"<EETIME>" << epilog_etime << "</EETIME>"<<
"<REASON>" << reason << "</REASON>"<<
"<ACTION>" << action << "</ACTION>"<<
"<UID>" << uid << "</UID>"<<
"<GID>" << gid << "</GID>"<<
@ -335,7 +332,7 @@ string& History::to_xml(string& xml, bool database) const
int History::rebuild_attributes()
{
int int_reason, int_action;
int int_action;
int rc = 0;
rc += xpath(seq, "/HISTORY/SEQ", -1);
@ -359,14 +356,12 @@ int History::rebuild_attributes()
rc += xpath<time_t>(epilog_stime , "/HISTORY/ESTIME", 0);
rc += xpath<time_t>(epilog_etime , "/HISTORY/EETIME", 0);
rc += xpath(int_reason , "/HISTORY/REASON", 0);
rc += xpath(int_action , "/HISTORY/ACTION", 0);
rc += xpath(uid, "/HISTORY/UID", -1);
rc += xpath(gid, "/HISTORY/GID", -1);
rc += xpath(req_id, "/HISTORY/REQUEST_ID", -1);
reason = static_cast<EndReason>(int_reason);
action = static_cast<VMAction>(int_action);
non_persistent_data();
@ -508,6 +503,9 @@ string History::action_to_str(VMAction action)
case RETRY_ACTION:
st = "retry";
break;
case MONITOR_ACTION:
st = "monitor";
break;
case NONE_ACTION:
st = "none";
break;
@ -678,6 +676,10 @@ int History::action_from_str(const string& st, VMAction& action)
{
action = RETRY_ACTION;
}
else if ( st == "monitor")
{
action = MONITOR_ACTION;
}
else
{
action = NONE_ACTION;