1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-27 13:57:23 +03:00

B: Solves issues when loading VM template in history records

This commit is contained in:
Ruben S. Montero 2017-07-18 18:19:30 +02:00
parent 7448957fa0
commit a2ad9662a7
3 changed files with 35 additions and 28 deletions

View File

@ -316,15 +316,21 @@ public:
*/ */
friend std::ostream& operator<<(std::ostream& os, ObjectXML& oxml) friend std::ostream& operator<<(std::ostream& os, ObjectXML& oxml)
{ {
xmlChar * mem; xmlNodePtr root_node = xmlDocGetRootElement(oxml.xml);
int size;
xmlDocDumpMemory(oxml.xml,&mem,&size); if ( root_node == 0 )
{
return os;
}
std::string str(reinterpret_cast<char *>(mem)); xmlBufferPtr buffer = xmlBufferCreate();
xmlNodeDump(buffer, oxml.xml, root_node, 0, 0);
std::string str(reinterpret_cast<char *>(buffer->content));
os << str; os << str;
xmlFree(mem); xmlBufferFree(buffer);
return os; return os;
}; };

View File

@ -380,11 +380,8 @@ int History::rebuild_attributes()
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ObjectXML::get_nodes("/HISTORY/VM", content); ObjectXML::get_nodes("/HISTORY/VM", content);
if (content.empty()) if (!content.empty())
{ {
return -1;
}
ObjectXML vm_info_xml(content[0]); ObjectXML vm_info_xml(content[0]);
ostringstream oss; ostringstream oss;
@ -396,6 +393,7 @@ int History::rebuild_attributes()
ObjectXML::free_nodes(content); ObjectXML::free_nodes(content);
content.clear(); content.clear();
}
non_persistent_data(); non_persistent_data();

View File

@ -505,10 +505,12 @@ int VirtualMachine::select(SqlDB * db)
return rc; return rc;
} }
//Get History Records. Current history is built in from_xml() (if any). //Get History Records.
if( hasHistory() ) if( hasHistory() )
{ {
last_seq = history->seq - 1; last_seq = history->seq;
delete history_records[last_seq];
for (int i = last_seq; i >= 0; i--) for (int i = last_seq; i >= 0; i--)
{ {
@ -525,6 +527,10 @@ int VirtualMachine::select(SqlDB * db)
history_records[i] = hp; history_records[i] = hp;
if ( i == last_seq ) if ( i == last_seq )
{
history = hp;
}
else if ( i == last_seq - 1 )
{ {
previous_history = hp; previous_history = hp;
} }
@ -2117,18 +2123,15 @@ int VirtualMachine::from_xml(const string &xml_str)
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Last history entry // Last history entry
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ObjectXML::get_nodes("/VM/HISTORY_RECORDS/HISTORY", content); int last_seq;
if (!content.empty()) if ( xpath(last_seq,"/VM/HISTORY_RECORDS/HISTORY/SEQ", -1) == 0 &&
last_seq != -1 )
{ {
history = new History(oid); history = new History(oid, last_seq);
rc += history->from_xml_node(content[0]);
history_records.resize(history->seq + 1); history_records.resize(history->seq + 1);
history_records[history->seq] = history; history_records[history->seq] = history;
ObjectXML::free_nodes(content);
content.clear();
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------