diff --git a/include/RequestManagerInfo.h b/include/RequestManagerInfo.h index cc91e86ee3..a9416f68b9 100644 --- a/include/RequestManagerInfo.h +++ b/include/RequestManagerInfo.h @@ -66,6 +66,14 @@ public: }; ~VirtualMachineInfo(){}; + + /* -------------------------------------------------------------------- */ + + void to_xml(PoolObjectSQL * object, string& str) + { + VirtualMachine * vm = static_cast(object); + vm->to_xml_extended(str); + }; }; /* ------------------------------------------------------------------------- */ diff --git a/include/RequestManagerPoolInfoFilter.h b/include/RequestManagerPoolInfoFilter.h index fd7147d1fe..b671086347 100644 --- a/include/RequestManagerPoolInfoFilter.h +++ b/include/RequestManagerPoolInfoFilter.h @@ -31,9 +31,12 @@ class RequestManagerPoolInfoFilter: public Request { protected: RequestManagerPoolInfoFilter(const string& method_name, - const string& help) - :Request(method_name,"A:si",help) - {}; + const string& help, + const string& signature) + :Request(method_name,signature,help) + { + auth_op = AuthRequest::INFO_POOL; + }; ~RequestManagerPoolInfoFilter(){}; @@ -54,9 +57,17 @@ protected: class VirtualMachinePoolInfo : public RequestManagerPoolInfoFilter { public: + /* -------------------------------------------------------------------- */ + + static const int ALL_VM; /**< VMs in any state (-2) */ + static const int NOT_DONE; /**< VMs in any state expect DONE (-1)*/ + + /* -------------------------------------------------------------------- */ + VirtualMachinePoolInfo(): RequestManagerPoolInfoFilter("VirtualMachinePoolInfo", - "Returns the virtual machine instances pool") + "Returns the virtual machine instances pool", + "A:siii") { Nebula& nd = Nebula::instance(); pool = nd.get_vmpool(); @@ -74,7 +85,8 @@ class TemplatePoolInfo : public RequestManagerPoolInfoFilter public: TemplatePoolInfo(): RequestManagerPoolInfoFilter("TemplatePoolInfo", - "Returns the virtual machine template pool") + "Returns the virtual machine template pool", + "A:siii") { Nebula& nd = Nebula::instance(); pool = nd.get_tpool(); @@ -87,13 +99,13 @@ public: /* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */ - class VirtualNetworkPoolInfo: public RequestManagerPoolInfoFilter { public: VirtualNetworkPoolInfo(): RequestManagerPoolInfoFilter("VirtualNetworkPoolInfo", - "Returns the virtual network pool") + "Returns the virtual network pool", + "A:siii") { Nebula& nd = Nebula::instance(); pool = nd.get_vnpool(); @@ -111,7 +123,8 @@ class ImagePoolInfo: public RequestManagerPoolInfoFilter public: ImagePoolInfo(): RequestManagerPoolInfoFilter("ImagePoolInfo", - "Returns the image pool") + "Returns the image pool", + "A:siii") { Nebula& nd = Nebula::instance(); pool = nd.get_ipool(); @@ -121,7 +134,6 @@ public: ~ImagePoolInfo(){}; }; - /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 3f52feb54a..857f9623bc 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -124,6 +124,14 @@ public: */ string& to_xml(string& xml) const; + /** + * Function to print the VirtualMachine object into a string in + * XML format, with extended information (full history records) + * @param xml the resulting XML string + * @return a reference to the generated string + */ + string& to_xml_extended(string& xml) const; + /** * Rebuilds the object from an xml formatted string * @param xml_str The xml-formatted string @@ -752,6 +760,12 @@ private: */ History * previous_history; + + /** + * Complete set of history records for the VM + */ + vector history_records; + // ------------------------------------------------------------------------- // Logging // ------------------------------------------------------------------------- @@ -859,6 +873,15 @@ private: */ void parse_graphics(); + /** + * 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 + * @return a reference to the generated string + */ + string& to_xml_extended(string& xml, bool extended) const; + protected: //************************************************************************** diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index 873e6de3d9..44edfc2ca2 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -139,22 +139,9 @@ public: */ int dump(ostringstream& oss, const string& where) { - return dump(oss, -1, where); + return PoolSQL::dump(oss, "VM_POOL", VirtualMachine::table, where); } - /** - * Dumps the VM pool in XML format. A filter can be also added to the query - * Also the hostname where the VirtualMachine is running is added to the - * pool - * @param oss the output stream to dump the pool contents - * @param where filter for the objects, defaults to all - * @param state include only VMs in this state. -1 means any state, - * except DONE - * - * @return 0 on success - */ - int dump(ostringstream& oss, int state, const string& where); - private: /** * Factory method to produce VM objects diff --git a/src/oca/ruby/OpenNebula/ImagePool.rb b/src/oca/ruby/OpenNebula/ImagePool.rb index 2d60908b63..4cec6b3840 100644 --- a/src/oca/ruby/OpenNebula/ImagePool.rb +++ b/src/oca/ruby/OpenNebula/ImagePool.rb @@ -47,9 +47,26 @@ module OpenNebula # XML-RPC Methods for the Image Object ####################################################################### - # Retrieves all or part of the Images in the pool. - def info() - super(IMAGE_POOL_METHODS[:info],@user_id) + # Retrieves all or part of the VirtualMachines in the pool. + def info(*args) + case args.size + when 0 + info_filter(IMAGE_POOL_METHODS[:info],@user_id,-1,-1) + when 3 + info_filter(IMAGE_POOL_METHODS[:info],args[0],args[1],args[2]) + end + end + + def info_all() + return super(IMAGE_POOL_METHODS[:info]) + end + + def info_mine() + return super(IMAGE_POOL_METHODS[:info]) + end + + def info_group() + return super(IMAGE_POOL_METHODS[:info]) end end end diff --git a/src/oca/ruby/OpenNebula/Pool.rb b/src/oca/ruby/OpenNebula/Pool.rb index 30fa180c51..2608848e84 100644 --- a/src/oca/ruby/OpenNebula/Pool.rb +++ b/src/oca/ruby/OpenNebula/Pool.rb @@ -22,7 +22,6 @@ module OpenNebula include Enumerable protected - #pool:: _String_ XML name of the root element #element:: _String_ XML name of the Pool elements #client:: _Client_ represents a XML-RPC connection @@ -48,13 +47,36 @@ module OpenNebula ####################################################################### # Common XML-RPC Methods for all the Pool Types ####################################################################### + + #Gets the pool without any filter. Host, Group and User Pools + # xml_method:: _String_ the name of the XML-RPC method + def info(xml_method) + return xmlrpc_info(xml_method) + end + def info_all(xml_method) + return xmlrpc_info(xml_method,INFO_ALL,-1,-1) + end + + def info_mine(xml_method) + return xmlrpc_info(xml_method,INFO_MINE,-1,-1) + end + + def info_group(xml_method) + return xmlrpc_info(xml_method,INFO_GROUP,-1,-1) + end + + def info_filter(xml_method, who, start_id, end_id) + return xmlrpc_info(xml_method,who, start_id, end_id) + end + + private # Calls to the corresponding info method to retreive the pool # representation in XML format # xml_method:: _String_ the name of the XML-RPC method # args:: _Array_ with additional arguments for the info call # [return] nil in case of success or an Error object - def info(xml_method,*args) + def xmlrpc_info(xml_method,*args) rc = @client.call(xml_method,*args) if !OpenNebula.is_error?(rc) @@ -66,6 +88,10 @@ module OpenNebula end public + # Constants for info queries (include/RequestManagerPoolInfoFilter.h) + INFO_GROUP = -1 + INFO_ALL = -2 + INFO_MINE = -3 # Iterates over every PoolElement in the Pool and calls the block with a # a PoolElement obtained calling the factory method diff --git a/src/oca/ruby/OpenNebula/TemplatePool.rb b/src/oca/ruby/OpenNebula/TemplatePool.rb index 8cebdd8877..c5174036bc 100644 --- a/src/oca/ruby/OpenNebula/TemplatePool.rb +++ b/src/oca/ruby/OpenNebula/TemplatePool.rb @@ -46,10 +46,26 @@ module OpenNebula # --------------------------------------------------------------------- # XML-RPC Methods for the Template Object # --------------------------------------------------------------------- + # Retrieves all or part of the VirtualMachines in the pool. + def info(*args) + case args.size + when 0 + info_filter(TEMPLATE_POOL_METHODS[:info],@user_id,-1,-1) + when 3 + info_filter(TEMPLATE_POOL_METHODS[:info],args[0],args[1],args[2]) + end + end - # Retrieves all the Templates in the pool. - def info() - super(TEMPLATE_POOL_METHODS[:info], @user_id) + def info_all() + return super(TEMPLATE_POOL_METHODS[:info]) + end + + def info_mine() + return super(TEMPLATE_POOL_METHODS[:info]) + end + + def info_group() + return super(TEMPLATE_POOL_METHODS[:info]) end end -end \ No newline at end of file +end diff --git a/src/oca/ruby/OpenNebula/VirtualMachinePool.rb b/src/oca/ruby/OpenNebula/VirtualMachinePool.rb index 766fd202dc..4613da0c2b 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachinePool.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachinePool.rb @@ -26,6 +26,10 @@ module OpenNebula :info => "vmpool.info" } + # Constants for info queries (include/RequestManagerPoolInfoFilter.h) + INFO_NOT_DONE = -1 + INFO_ALL_VM = -2 + ####################################################################### # Class constructor & Pool Methods ####################################################################### @@ -48,8 +52,54 @@ module OpenNebula ####################################################################### # Retrieves all or part of the VirtualMachines in the pool. - def info() - super(VM_POOL_METHODS[:info],@user_id) + # No arguments, returns the not-in-done VMs for the user + # [user_id, start_id, end_id] + # [user_id, start_id, end_id, state] + def info(*args) + case args.size + when 0 + info_filter(VM_POOL_METHODS[:info], + @user_id, + -1, + -1, + INFO_NOT_DONE) + when 3 + info_filter(VM_POOL_METHODS[:info], + args[0], + args[1], + args[2], + INFO_NOT_DONE) + when 4 + info_filter(VM_POOL_METHODS[:info], + args[0], + args[1], + args[2], + args[3]) + end + end + + def info_all() + return info_filter(VM_POOL_METHODS[:info], + INFO_ALL, + -1, + -1, + INFO_NOT_DONE) + end + + def info_mine() + return info_filter(VM_POOL_METHODS[:info], + INFO_MINE, + -1, + -1, + INFO_NOT_DONE) + end + + def info_group() + return info_filter(VM_POOL_METHODS[:info], + INFO_GROUP, + -1, + -1, + INFO_NOT_DONE) end end end diff --git a/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb b/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb index 0e41cc99ba..4267ac1830 100644 --- a/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb +++ b/src/oca/ruby/OpenNebula/VirtualNetworkPool.rb @@ -47,9 +47,26 @@ module OpenNebula # XML-RPC Methods for the Virtual Network Object ####################################################################### - # Retrieves all or part of the VirtualNetwork in the pool. - def info() - super(VN_POOL_METHODS[:info],@user_id) + # Retrieves all or part of the VirtualMachines in the pool. + def info(*args) + case args.size + when 0 + info_filter(VN_POOL_METHODS[:info],@user_id,-1,-1) + when 3 + info_filter(VN_POOL_METHODS[:info],args[0],args[1],args[2]) + end + end + + def info_all() + return super(VN_POOL_METHODS[:info]) + end + + def info_mine() + return super(VN_POOL_METHODS[:info]) + end + + def info_group() + return super(VN_POOL_METHODS[:info]) end end end diff --git a/src/oca/ruby/test/HostPool_spec.rb b/src/oca/ruby/test/HostPool_spec.rb index 5d08319618..7c2d083330 100644 --- a/src/oca/ruby/test/HostPool_spec.rb +++ b/src/oca/ruby/test/HostPool_spec.rb @@ -1,4 +1,5 @@ -$: << '../' +$: << '../' \ + << './' require 'OpenNebula' require 'helpers/MockClient' @@ -78,4 +79,4 @@ module OpenNebula } end end -end \ No newline at end of file +end diff --git a/src/oca/ruby/test/Host_spec.rb b/src/oca/ruby/test/Host_spec.rb index e2d8cb39e4..5d0a585b19 100644 --- a/src/oca/ruby/test/Host_spec.rb +++ b/src/oca/ruby/test/Host_spec.rb @@ -1,4 +1,5 @@ -$: << '../' +$: << '../' \ + << './' require 'OpenNebula' require 'helpers/MockClient' @@ -216,4 +217,4 @@ module OpenNebula end end -end \ No newline at end of file +end diff --git a/src/oca/ruby/test/UserPool_spec.rb b/src/oca/ruby/test/UserPool_spec.rb index 7465cfc485..22f208b6af 100644 --- a/src/oca/ruby/test/UserPool_spec.rb +++ b/src/oca/ruby/test/UserPool_spec.rb @@ -1,4 +1,5 @@ -$: << '../' +$: << '../' \ + << './' require 'OpenNebula' require 'helpers/MockClient' @@ -62,4 +63,4 @@ module OpenNebula } end end -end \ No newline at end of file +end diff --git a/src/oca/ruby/test/User_spec.rb b/src/oca/ruby/test/User_spec.rb index a02911f03e..c3f25fdbc6 100644 --- a/src/oca/ruby/test/User_spec.rb +++ b/src/oca/ruby/test/User_spec.rb @@ -1,4 +1,5 @@ -$: << '../' +$: << '../' \ + << './' require 'OpenNebula' require 'helpers/MockClient' @@ -142,4 +143,4 @@ module OpenNebula end end -end \ No newline at end of file +end diff --git a/src/oca/ruby/test/VirtualMachinePool_spec.rb b/src/oca/ruby/test/VirtualMachinePool_spec.rb index cd138b5d2f..5d08cce65f 100644 --- a/src/oca/ruby/test/VirtualMachinePool_spec.rb +++ b/src/oca/ruby/test/VirtualMachinePool_spec.rb @@ -1,4 +1,5 @@ -$: << '../' +$: << '../' \ + << './' require 'OpenNebula' require 'helpers/MockClient' @@ -114,4 +115,4 @@ module OpenNebula } end end -end \ No newline at end of file +end diff --git a/src/oca/ruby/test/VirtualMachine_spec.rb b/src/oca/ruby/test/VirtualMachine_spec.rb index 4fc6c90996..982916fa5a 100644 --- a/src/oca/ruby/test/VirtualMachine_spec.rb +++ b/src/oca/ruby/test/VirtualMachine_spec.rb @@ -1,4 +1,5 @@ -$: << '../' +$: << '../' \ + << './' require 'OpenNebula' require 'helpers/MockClient' @@ -469,4 +470,4 @@ module OpenNebula @vm.name.should eql(nil) end end -end \ No newline at end of file +end diff --git a/src/oca/ruby/test/VirtualNetworkPool_spec.rb b/src/oca/ruby/test/VirtualNetworkPool_spec.rb index fd107827c6..5bebce9fa0 100644 --- a/src/oca/ruby/test/VirtualNetworkPool_spec.rb +++ b/src/oca/ruby/test/VirtualNetworkPool_spec.rb @@ -1,4 +1,5 @@ -$: << '../' +$: << '../' \ + << './' require 'OpenNebula' require 'helpers/MockClient' @@ -84,4 +85,4 @@ module OpenNebula } end end -end \ No newline at end of file +end diff --git a/src/oca/ruby/test/VirtualNetwork_spec.rb b/src/oca/ruby/test/VirtualNetwork_spec.rb index b74982bf52..3d3431da2f 100644 --- a/src/oca/ruby/test/VirtualNetwork_spec.rb +++ b/src/oca/ruby/test/VirtualNetwork_spec.rb @@ -1,4 +1,5 @@ -$: << '../' +$: << '../' \ + << './' require 'OpenNebula' require 'helpers/MockClient' @@ -152,4 +153,4 @@ module OpenNebula end end -end \ No newline at end of file +end diff --git a/src/rm/RequestManagerPoolInfoFilter.cc b/src/rm/RequestManagerPoolInfoFilter.cc index a2dfd0ed4b..b3875a2dc2 100644 --- a/src/rm/RequestManagerPoolInfoFilter.cc +++ b/src/rm/RequestManagerPoolInfoFilter.cc @@ -27,51 +27,168 @@ const int RequestManagerPoolInfoFilter::MINE = -3; const int RequestManagerPoolInfoFilter::MINE_GROUP = -1; +/* ------------------------------------------------------------------------- */ + +const int VirtualMachinePoolInfo::ALL_VM = -2; + +const int VirtualMachinePoolInfo::NOT_DONE = -1; + /* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */ void RequestManagerPoolInfoFilter::request_execute(xmlrpc_c::paramList const& paramList) { int filter_flag = xmlrpc_c::value_int(paramList.getInt(1)); + int start_id = xmlrpc_c::value_int(paramList.getInt(2)); + int end_id = xmlrpc_c::value_int(paramList.getInt(3)); - ostringstream oss, where_string; + set::iterator it; + + ostringstream oss; + bool empty = true; + ostringstream where_string; + + ostringstream uid_filter; + ostringstream state_filter; + ostringstream id_filter; + + string uid_str; + string state_str; + string id_str; int rc; - AuthRequest::Operation request_op = AuthRequest::INFO_POOL; + AuthRequest::Operation request_op; + + // ------------------------------------------ + // User ID filter + // ------------------------------------------ if ( filter_flag < MINE ) { - failure_response(XML_RPC_API, request_error("Incorrect filter_flag","")); + failure_response(XML_RPC_API,request_error("Incorrect filter_flag","")); return; } - + switch(filter_flag) { case MINE: - where_string << "UID=" << uid; + uid_filter << "uid = " << uid; + request_op = AuthRequest::INFO_POOL_MINE; break; case ALL: + request_op = AuthRequest::INFO_POOL; break; case MINE_GROUP: - where_string << "UID=" << uid << " OR GID=" << gid; + + uid_filter << "uid = " << uid << " OR gid = " << gid; + + for ( it = group_ids.begin() ; it != group_ids.end(); it++ ) + { + where_string << " OR gid = " << *it; + } + request_op = AuthRequest::INFO_POOL_MINE; break; default: - where_string << "UID=" << filter_flag; + uid_filter << "uid = " << filter_flag; + + request_op = AuthRequest::INFO_POOL; break; } + uid_str = uid_filter.str(); + + + // ------------------------------------------ + // Resource ID filter + // ------------------------------------------ + + if ( start_id != -1 ) + { + id_filter << "oid >= " << start_id; + + if ( end_id != -1 ) + { + id_filter << " AND oid <= " << end_id; + } + } + + id_str = id_filter.str(); + + // ------------ State filter for VM -------------- + if ( auth_object == AuthRequest::VM ) + { + int state = xmlrpc_c::value_int(paramList.getInt(4)); + + if (( state < MINE ) || ( state > VirtualMachine::FAILED )) + { + failure_response(XML_RPC_API, + request_error("Incorrect filter_flag, state","")); + return; + } + + switch(state) + { + case VirtualMachinePoolInfo::ALL_VM: + break; + + case VirtualMachinePoolInfo::NOT_DONE: + state_filter << "state <> " << VirtualMachine::DONE; + break; + + default: + state_filter << "state = " << state; + break; + } + } + + state_str = state_filter.str(); + + // ------------------------------------------ + // Compound WHERE clause + // ------------------------------------------ + + if (!uid_str.empty()) + { + where_string << "(" << uid_str << ")" ; + empty = false; + } + + if (!id_str.empty()) + { + if (!empty) + { + where_string << " AND "; + } + + where_string << "(" << id_str << ")"; + empty = false; + } + + if (!state_str.empty()) + { + if (!empty) + { + where_string << " AND "; + } + + where_string << "(" << state_str << ")"; + } + + // ------------------------------------------ + // Authorize & get the pool + // ------------------------------------------ + if ( basic_authorization(-1, request_op) == false ) { return; } - - // Call the template pool dump + rc = pool->dump(oss,where_string.str()); if ( rc != 0 ) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 7d12824d81..b73c8253ab 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -70,14 +70,9 @@ VirtualMachine::VirtualMachine(int id, VirtualMachine::~VirtualMachine() { - if ( history != 0 ) + for (unsigned int i=0 ; i < history_records.size() ; i++) { - delete history; - } - - if ( previous_history != 0 ) - { - delete previous_history; + delete history_records[i]; } if ( _log != 0 ) @@ -128,18 +123,26 @@ int VirtualMachine::select(SqlDB * db) //Get History Records. Current history is built in from_xml() (if any). if( hasHistory() ) { - last_seq = history->seq; + last_seq = history->seq - 1; - if ( last_seq > 0 ) + for (int i = last_seq; i >= 0; i--) { - previous_history = new History(oid, last_seq - 1); + History * hp; - rc = previous_history->select(db); + hp = new History(oid, i); + rc = hp->select(db); if ( rc != 0) { goto error_previous_history; } + + history_records[i] = hp; + + if ( i == last_seq ) + { + previous_history = hp; + } } } @@ -168,6 +171,7 @@ int VirtualMachine::select(SqlDB * db) error_previous_history: ose << "Can not get previous history record (seq:" << history->seq << ") for VM id: " << oid; + log("ONE", Log::ERROR, ose); return -1; } @@ -560,15 +564,12 @@ void VirtualMachine::add_history( { seq = history->seq + 1; - if (previous_history != 0) - { - delete previous_history; - } - previous_history = history; } history = new History(oid,seq,hid,hostname,vm_dir,vmm_mad,tm_mad); + + history_records.push_back(history); }; /* -------------------------------------------------------------------------- */ @@ -584,21 +585,18 @@ void VirtualMachine::cp_history() } htmp = new History(oid, - history->seq + 1, - history->hid, - history->hostname, - history->vm_dir, - history->vmm_mad_name, - history->tm_mad_name); + history->seq + 1, + history->hid, + history->hostname, + history->vm_dir, + history->vmm_mad_name, + history->tm_mad_name); - if ( previous_history != 0 ) - { - delete previous_history; - } previous_history = history; + history = htmp; - history = htmp; + history_records.push_back(history); } /* -------------------------------------------------------------------------- */ @@ -614,18 +612,17 @@ void VirtualMachine::cp_previous_history() } htmp = new History(oid, - history->seq + 1, - previous_history->hid, - previous_history->hostname, - previous_history->vm_dir, - previous_history->vmm_mad_name, - previous_history->tm_mad_name); - - delete previous_history; + history->seq + 1, + previous_history->hid, + previous_history->hostname, + previous_history->vm_dir, + previous_history->vmm_mad_name, + previous_history->tm_mad_name); previous_history = history; + history = htmp; - history = htmp; + history_records.push_back(history); } /* -------------------------------------------------------------------------- */ @@ -1139,11 +1136,26 @@ error_yy: pthread_mutex_unlock(&lex_mutex); return -1; } - /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ string& VirtualMachine::to_xml(string& xml) const +{ + return to_xml_extended(xml,false); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +string& VirtualMachine::to_xml_extended(string& xml) const +{ + return to_xml_extended(xml,true); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +string& VirtualMachine::to_xml_extended(string& xml, bool extended) const { string template_xml; @@ -1172,7 +1184,21 @@ string& VirtualMachine::to_xml(string& xml) const if ( hasHistory() ) { - oss << history->to_xml(history_xml); + oss << ""; + + if ( extended ) + { + for (unsigned int i=0; i < history_records.size(); i++) + { + oss << history_records[i]->to_xml(history_xml); + } + } + else + { + oss << history->to_xml(history_xml); + } + + oss << ""; } oss << ""; @@ -1235,12 +1261,15 @@ int VirtualMachine::from_xml(const string &xml_str) // Last history entry content.clear(); - ObjectXML::get_nodes("/VM/HISTORY", content); + ObjectXML::get_nodes("/VM/HISTORY_RECORDS/HISTORY", content); if( !content.empty() ) { history = new History(oid); rc += history->from_xml_node(content[0]); + + history_records.resize(history->seq + 1); + history_records[history->seq] = history; } if (rc != 0) diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index eae0cb0fde..4cb4aa1a63 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -250,29 +250,3 @@ int VirtualMachinePool::get_pending( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - -int VirtualMachinePool::dump( ostringstream& oss, - int state, - const string& where) -{ - ostringstream where_oss; - - if ( state != -1 ) - { - where_oss << VirtualMachine::table << ".state = " << state; - } - else - { - where_oss << VirtualMachine::table << ".state <> 6"; - } - - if ( !where.empty() ) - { - where_oss << " AND " << where; - } - - return PoolSQL::dump(oss, "VM_POOL", VirtualMachine::table,where_oss.str()); -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ diff --git a/src/vm/test/VirtualMachinePoolTest.cc b/src/vm/test/VirtualMachinePoolTest.cc index aeb53b41b7..6e636d0065 100644 --- a/src/vm/test/VirtualMachinePoolTest.cc +++ b/src/vm/test/VirtualMachinePoolTest.cc @@ -76,8 +76,7 @@ const string xml_dump_where = "011VM one010000000000000000"; const string xml_history_dump = - "001VM one010000000000000000101Second VM0200000000000000000A_hostnameA_vm_dir000A_vmm_madA_tm_mad0000000201VM one0200000000000000001C_hostnameC_vm_dir200C_vmm_madC_tm_mad0000000"; - + "001VM one010000000000000000101Second VM0200000000000000000A_hostnameA_vm_dir000A_vmm_madA_tm_mad0000000201VM one0200000000000000001C_hostnameC_vm_dir200C_vmm_madC_tm_mad0000000"; /* ************************************************************************* */ /* ************************************************************************* */