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

Feature #1099: Add complete VM info to all history records, even the active ones

This commit is contained in:
Carlos Martín 2012-05-08 15:42:24 +02:00
parent de3cd97468
commit 2c88fe83c8
4 changed files with 39 additions and 22 deletions

View File

@ -45,7 +45,8 @@ public:
int hid,
const string& hostname,
const string& vmm,
const string& vnm);
const string& vnm,
const string& vm_info);
~History(){};

View File

@ -431,18 +431,18 @@ public:
/**
* Sets VM info (with monitoring info) in the history record
*/
void set_vm_info()
{
obj_template->to_xml(history->vm_info);
};
void set_vm_info()
{
to_xml_extended(history->vm_info, 0);
};
/**
* Sets VM info (with monitoring info) in the previous history record
*/
void set_previous_vm_info()
{
obj_template->to_xml(previous_history->vm_info);
};
void set_previous_vm_info()
{
to_xml_extended(previous_history->vm_info, 0);
};
/**
* Sets end time of a VM.
@ -932,10 +932,13 @@ private:
* Function that renders the VM in XML format optinally including
* extended information (all history records)
* @param xml the resulting XML string
* @param extended include additional info if true
* @param n_history Number of history records to include:
* 0: none
* 1: the last one
* 2: all
* @return a reference to the generated string
*/
string& to_xml_extended(string& xml, bool extended) const;
string& to_xml_extended(string& xml, int n_history) const;
protected:

View File

@ -53,7 +53,7 @@ History::History(
epilog_stime(0),
epilog_etime(0),
reason(NONE),
vm_info("<TEMPLATE/>"){};
vm_info("<VM/>"){};
/* -------------------------------------------------------------------------- */
@ -63,7 +63,8 @@ History::History(
int _hid,
const string& _hostname,
const string& _vmm,
const string& _vnm):
const string& _vnm,
const string& _vm_info):
oid(_oid),
seq(_seq),
hostname(_hostname),
@ -79,7 +80,7 @@ History::History(
epilog_stime(0),
epilog_etime(0),
reason(NONE),
vm_info("<TEMPLATE/>")
vm_info(_vm_info)
{
non_persistent_data();
};

View File

@ -735,6 +735,7 @@ void VirtualMachine::add_history(
{
ostringstream os;
int seq;
string vm_xml;
if (history == 0)
{
@ -747,12 +748,15 @@ void VirtualMachine::add_history(
previous_history = history;
}
to_xml_extended(vm_xml, 0);
history = new History(oid,
seq,
hid,
hostname,
vmm_mad,
vnm_mad);
vnm_mad,
vm_xml);
history_records.push_back(history);
};
@ -763,18 +767,22 @@ void VirtualMachine::add_history(
void VirtualMachine::cp_history()
{
History * htmp;
string vm_xml;
if (history == 0)
{
return;
}
to_xml_extended(vm_xml, 0);
htmp = new History(oid,
history->seq + 1,
history->hid,
history->hostname,
history->vmm_mad_name,
history->vnm_mad_name);
history->vnm_mad_name,
vm_xml);
previous_history = history;
history = htmp;
@ -788,18 +796,22 @@ void VirtualMachine::cp_history()
void VirtualMachine::cp_previous_history()
{
History * htmp;
string vm_xml;
if ( previous_history == 0 || history == 0)
{
return;
}
to_xml_extended(vm_xml, 0);
htmp = new History(oid,
history->seq + 1,
previous_history->hid,
previous_history->hostname,
previous_history->vmm_mad_name,
previous_history->vnm_mad_name);
previous_history->vnm_mad_name,
vm_xml);
previous_history = history;
history = htmp;
@ -1475,7 +1487,7 @@ error_yy:
string& VirtualMachine::to_xml(string& xml) const
{
return to_xml_extended(xml,false);
return to_xml_extended(xml, 1);
}
/* -------------------------------------------------------------------------- */
@ -1483,13 +1495,13 @@ string& VirtualMachine::to_xml(string& xml) const
string& VirtualMachine::to_xml_extended(string& xml) const
{
return to_xml_extended(xml,true);
return to_xml_extended(xml, 2);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string& VirtualMachine::to_xml_extended(string& xml, bool extended) const
string& VirtualMachine::to_xml_extended(string& xml, int n_history) const
{
string template_xml;
string history_xml;
@ -1517,11 +1529,11 @@ string& VirtualMachine::to_xml_extended(string& xml, bool extended) const
<< "<NET_RX>" << net_rx << "</NET_RX>"
<< obj_template->to_xml(template_xml);
if ( hasHistory() )
if ( hasHistory() && n_history > 0 )
{
oss << "<HISTORY_RECORDS>";
if ( extended )
if ( n_history == 2 )
{
for (unsigned int i=0; i < history_records.size(); i++)
{