1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-26 09: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)
{
xmlChar * mem;
int size;
xmlNodePtr root_node = xmlDocGetRootElement(oxml.xml);
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;
xmlFree(mem);
xmlBufferFree(buffer);
return os;
};

View File

@ -380,23 +380,21 @@ int History::rebuild_attributes()
// -------------------------------------------------------------------------
ObjectXML::get_nodes("/HISTORY/VM", content);
if (content.empty())
if (!content.empty())
{
return -1;
ObjectXML vm_info_xml(content[0]);
ostringstream oss;
oss << vm_info_xml;
vm_info = oss.str();
ObjectXML::free_nodes(content);
content.clear();
}
ObjectXML vm_info_xml(content[0]);
ostringstream oss;
oss << vm_info_xml;
vm_info = oss.str();
ObjectXML::free_nodes(content);
content.clear();
non_persistent_data();
if (rc != 0)

View File

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