From 8a2597cd906609200047c8409c61e77e17ad8f6c Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 4 Jan 2013 00:04:01 +0100 Subject: [PATCH 1/3] feature #1556: Add a new user template to the VM to store user defined variables. Add OCA Ruby & JAVA bindings for the new update method. Add command option for onevm tool. --- include/RequestManagerUpdateTemplate.h | 28 ++++- include/VirtualMachine.h | 13 +++ src/cli/one_helper.rb | 4 +- src/cli/one_helper/onevm_helper.rb | 8 +- src/cli/onevm | 12 ++ .../opennebula/client/vm/VirtualMachine.java | 14 +++ src/oca/ruby/OpenNebula/VirtualMachine.rb | 14 ++- src/pool/PoolObjectSQL.cc | 5 +- src/rm/RequestManager.cc | 106 +++++++++--------- src/vm/VirtualMachine.cc | 68 +++++++++-- 10 files changed, 202 insertions(+), 70 deletions(-) diff --git a/include/RequestManagerUpdateTemplate.h b/include/RequestManagerUpdateTemplate.h index 511f149ce7..40c18f8102 100644 --- a/include/RequestManagerUpdateTemplate.h +++ b/include/RequestManagerUpdateTemplate.h @@ -53,7 +53,7 @@ public: TemplateUpdateTemplate(): RequestManagerUpdateTemplate("TemplateUpdateTemplate", "Updates a virtual machine template") - { + { Nebula& nd = Nebula::instance(); pool = nd.get_tpool(); auth_object = PoolObjectSQL::TEMPLATE; @@ -65,13 +65,31 @@ public: /* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */ +class VirtualMachineUpdateTemplate: public RequestManagerUpdateTemplate +{ +public: + VirtualMachineUpdateTemplate(): + RequestManagerUpdateTemplate("VirtualMachineUpdateTemplate", + "Updates a virtual machine user template") + { + Nebula& nd = Nebula::instance(); + pool = nd.get_vmpool(); + auth_object = PoolObjectSQL::VM; + }; + + ~VirtualMachineUpdateTemplate(){}; +}; + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + class ImageUpdateTemplate: public RequestManagerUpdateTemplate { public: ImageUpdateTemplate(): RequestManagerUpdateTemplate("ImageUpdateTemplate", "Updates an image template") - { + { Nebula& nd = Nebula::instance(); pool = nd.get_ipool(); auth_object = PoolObjectSQL::IMAGE; @@ -89,7 +107,7 @@ public: HostUpdateTemplate(): RequestManagerUpdateTemplate("HostUpdateTemplate", "Updates a host template") - { + { Nebula& nd = Nebula::instance(); pool = nd.get_hpool(); auth_object = PoolObjectSQL::HOST; @@ -107,7 +125,7 @@ public: VirtualNetworkUpdateTemplate(): RequestManagerUpdateTemplate("VirtualNetworkUpdateTemplate", "Updates a vnet template") - { + { Nebula& nd = Nebula::instance(); pool = nd.get_vnpool(); auth_object = PoolObjectSQL::NET; @@ -125,7 +143,7 @@ public: UserUpdateTemplate(): RequestManagerUpdateTemplate("UserUpdateTemplate", "Updates a user template") - { + { Nebula& nd = Nebula::instance(); pool = nd.get_upool(); auth_object = PoolObjectSQL::USER; diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index e23debde4b..01c8da097f 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -702,6 +702,13 @@ public: *(static_cast(obj_template))); }; + /** + * This function replaces the *user template*. + * @param tmpl_str new contents + * @param error string describing the error if any + * @return 0 on success + */ + int replace_template(const string& tmpl_str, string& error); // ------------------------------------------------------------------------ // States @@ -1044,6 +1051,12 @@ private: */ FileLog * _log; + /** + * User template to store custom metadata. This template can be updated + * + */ + Template * user_obj_template; + // ************************************************************************* // DataBase implementation (Private) // ************************************************************************* diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 8330a43446..739f123c25 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -623,7 +623,7 @@ EOT end end - def OpenNebulaHelper.update_template(id, resource, path=nil) + def OpenNebulaHelper.update_template(id, resource, path=nil, xpath='TEMPLATE') unless path require 'tempfile' @@ -637,7 +637,7 @@ EOT exit -1 end - tmp << resource.template_str + tmp << resource.template_like_str(xpath) tmp.flush editor_path = ENV["EDITOR"] ? ENV["EDITOR"] : EDITOR_PATH diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index e540239f9f..8488d27008 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -215,9 +215,15 @@ class OneVMHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE TEMPLATE",false) puts vm.template_str - if vm.has_elements?("/VM/HISTORY_RECORDS") + if vm.has_elements?("/VM/USER_TEMPLATE") puts + CLIHelper.print_header(str_h1 % "USER TEMPLATE",false) + puts vm.template_like_str('USER_TEMPLATE') + end + + if vm.has_elements?("/VM/HISTORY_RECORDS") + puts CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE HISTORY",false) format_history(vm) diff --git a/src/cli/onevm b/src/cli/onevm index 04fd4a414f..6807646bf8 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -174,6 +174,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do exit_code end + update_desc = <<-EOT.unindent + Update the *user* template contents. If a path is not provided the + editor will be launched to modify the current content. + EOT + + command :update, update_desc, :vmid, [:file, nil] do + helper.perform_action(args[0],options,"modified") do |vm| + str = OpenNebulaHelper.update_template(args[0], vm, args[1],'USER_TEMPLATE') + vm.update(str) + end + end + delete_desc = <<-EOT.unindent Deletes the given VM diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index 51f3779513..583a06ff10 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -40,6 +40,7 @@ public class VirtualMachine extends PoolElement{ private static final String ATTACH = METHOD_PREFIX + "attach"; private static final String DETACH = METHOD_PREFIX + "detach"; private static final String RENAME = METHOD_PREFIX + "rename"; + private static final String UPDATE = METHOD_PREFIX + "update"; private static final String[] VM_STATES = { @@ -168,6 +169,19 @@ public class VirtualMachine extends PoolElement{ return client.call(ALLOCATE, description, onHold); } + /** + * Replaces the user template contents for the given VM. + * + * @param client XML-RPC Client. + * @param id The id of the target vm. + * @param new_template New template contents + * @return If successful the message contains the vm id. + */ + public static OneResponse update(Client client, int id, String new_template) + { + return client.call(UPDATE, id, new_template); + } + /** * Retrieves the information of the given VM. * diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index 4ac7b6d745..7e7c39a036 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -36,10 +36,11 @@ module OpenNebula :monitoring => "vm.monitoring", :attach => "vm.attach", :detach => "vm.detach", - :rename => "vm.rename" + :rename => "vm.rename", + :update => "vm.update" } - VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED + VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED POWEROFF} LCM_STATE=%w{LCM_INIT PROLOG BOOT RUNNING MIGRATE SAVE_STOP SAVE_SUSPEND @@ -145,6 +146,15 @@ module OpenNebula super(VM_METHODS[:allocate], description, hold) end + # Replaces the template contents + # + # @param new_template New template contents. If no argument is provided + # the object will be updated using the @xml variable + def update(new_template=nil) + super(VM_METHODS[:update], new_template) + end + + # Initiates the instance of the VM on the target host. # # @param host_id [Interger] The host id (hid) of the target host where diff --git a/src/pool/PoolObjectSQL.cc b/src/pool/PoolObjectSQL.cc index f1979ab80f..e871058835 100644 --- a/src/pool/PoolObjectSQL.cc +++ b/src/pool/PoolObjectSQL.cc @@ -182,7 +182,10 @@ int PoolObjectSQL::replace_template(const string& tmpl_str, string& error) return -1; } - delete obj_template; + if ( obj_template != 0 ) + { + delete obj_template; + } obj_template = new_tmpl; diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index 004c3e2d82..89d72ff9e8 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -46,9 +46,9 @@ #include #include #include -#include +#include #include - + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -64,41 +64,41 @@ extern "C" void * rm_action_loop(void *arg) NebulaLog::log("ReM",Log::INFO,"Request Manager started."); rm = static_cast(arg); - + rm->am.loop(0,0); NebulaLog::log("ReM",Log::INFO,"Request Manager stopped."); - + return 0; } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - + extern "C" void * rm_xml_server_loop(void *arg) { RequestManager * rm; - + if ( arg == 0 ) { return 0; } rm = static_cast(arg); - + // Set cancel state for the thread - + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,0); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,0); - + //Start the server - + rm->AbyssServer = new xmlrpc_c::serverAbyss(xmlrpc_c::serverAbyss::constrOpt() .registryP(&rm->RequestManagerRegistry) .logFileName(rm->xml_log_file) .socketFd(rm->socket_fd)); - + rm->AbyssServer->run(); return 0; @@ -112,20 +112,20 @@ int RequestManager::setup_socket() int rc; int yes = 1; struct sockaddr_in rm_addr; - + socket_fd = socket(AF_INET, SOCK_STREAM, 0); - + if ( socket_fd == -1 ) { ostringstream oss; oss << "Cannot open server socket: " << strerror(errno); NebulaLog::log("ReM",Log::ERROR,oss); - - return -1; + + return -1; } - - rc = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); + + rc = setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); if ( rc == -1 ) { @@ -133,29 +133,29 @@ int RequestManager::setup_socket() oss << "Cannot set socket options: " << strerror(errno); NebulaLog::log("ReM",Log::ERROR,oss); - + close(socket_fd); - - return -1; + + return -1; } - + fcntl(socket_fd,F_SETFD,FD_CLOEXEC); // Close socket in MADs - + rm_addr.sin_family = AF_INET; rm_addr.sin_port = htons(port); rm_addr.sin_addr.s_addr = INADDR_ANY; rc = bind(socket_fd,(struct sockaddr *) &(rm_addr),sizeof(struct sockaddr)); - if ( rc == -1) + if ( rc == -1) { ostringstream oss; oss << "Cannot bind to port " << port << " : " << strerror(errno); NebulaLog::log("ReM",Log::ERROR,oss); - + close(socket_fd); - + return -1; } @@ -169,29 +169,29 @@ int RequestManager::start() { pthread_attr_t pattr; ostringstream oss; - + NebulaLog::log("ReM",Log::INFO,"Starting Request Manager..."); - + int rc = setup_socket(); - + if ( rc != 0 ) { return -1; } - + register_xml_methods(); - + pthread_attr_init (&pattr); pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE); - + pthread_create(&rm_thread,&pattr,rm_action_loop,(void *)this); - + pthread_attr_init (&pattr); pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE); - + oss << "Starting XML-RPC server, port " << port << " ..."; NebulaLog::log("ReM",Log::INFO,oss); - + pthread_create(&rm_xml_server_thread,&pattr,rm_xml_server_loop,(void *)this); return 0; @@ -199,7 +199,7 @@ int RequestManager::start() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - + void RequestManager::do_action( const string & action, void * arg) @@ -207,15 +207,15 @@ void RequestManager::do_action( if (action == ACTION_FINALIZE) { NebulaLog::log("ReM",Log::INFO,"Stopping Request Manager..."); - - pthread_cancel(rm_xml_server_thread); + + pthread_cancel(rm_xml_server_thread); pthread_join(rm_xml_server_thread,0); NebulaLog::log("ReM",Log::INFO,"XML-RPC server stopped."); delete AbyssServer; - + if ( socket_fd != -1 ) { close(socket_fd); @@ -225,14 +225,14 @@ void RequestManager::do_action( { ostringstream oss; oss << "Unknown action name: " << action; - + NebulaLog::log("ReM", Log::ERROR, oss); - } + } }; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - + void RequestManager::register_xml_methods() { // User Methods @@ -249,7 +249,7 @@ void RequestManager::register_xml_methods() // VirtualMachine Methods xmlrpc_c::methodPtr vm_deploy(new VirtualMachineDeploy()); xmlrpc_c::methodPtr vm_migrate(new VirtualMachineMigrate()); - xmlrpc_c::methodPtr vm_action(new VirtualMachineAction()); + xmlrpc_c::methodPtr vm_action(new VirtualMachineAction()); xmlrpc_c::methodPtr vm_savedisk(new VirtualMachineSaveDisk()); xmlrpc_c::methodPtr vm_monitoring(new VirtualMachineMonitoring()); xmlrpc_c::methodPtr vm_attach(new VirtualMachineAttach()); @@ -265,6 +265,7 @@ void RequestManager::register_xml_methods() // Update Template Methods xmlrpc_c::methodPtr image_update(new ImageUpdateTemplate()); + xmlrpc_c::methodPtr vm_update(new VirtualMachineUpdateTemplate()); xmlrpc_c::methodPtr template_update(new TemplateUpdateTemplate()); xmlrpc_c::methodPtr host_update(new HostUpdateTemplate()); xmlrpc_c::methodPtr vn_update(new VirtualNetworkUpdateTemplate()); @@ -312,7 +313,7 @@ void RequestManager::register_xml_methods() xmlrpc_c::methodPtr cluster_info(new ClusterInfo()); xmlrpc_c::methodPtr doc_info(new DocumentInfo()); - // PoolInfo Methods + // PoolInfo Methods xmlrpc_c::methodPtr hostpool_info(new HostPoolInfo()); xmlrpc_c::methodPtr grouppool_info(new GroupPoolInfo()); xmlrpc_c::methodPtr userpool_info(new UserPoolInfo()); @@ -382,7 +383,7 @@ void RequestManager::register_xml_methods() xmlrpc_c::methodPtr image_rename(new ImageRename()); xmlrpc_c::methodPtr doc_rename(new DocumentRename()); - /* VM related methods */ + /* VM related methods */ RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy); RequestManagerRegistry.addMethod("one.vm.action", vm_action); RequestManagerRegistry.addMethod("one.vm.migrate", vm_migrate); @@ -395,6 +396,7 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.vm.attach", vm_attach); RequestManagerRegistry.addMethod("one.vm.detach", vm_detach); RequestManagerRegistry.addMethod("one.vm.rename", vm_rename); + RequestManagerRegistry.addMethod("one.vm.update", vm_update); RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info); RequestManagerRegistry.addMethod("one.vmpool.accounting", vm_pool_acct); @@ -416,12 +418,12 @@ void RequestManager::register_xml_methods() /* Host related methods*/ RequestManagerRegistry.addMethod("one.host.enable", host_enable); RequestManagerRegistry.addMethod("one.host.update", host_update); - RequestManagerRegistry.addMethod("one.host.allocate", host_allocate); + RequestManagerRegistry.addMethod("one.host.allocate", host_allocate); RequestManagerRegistry.addMethod("one.host.delete", host_delete); RequestManagerRegistry.addMethod("one.host.info", host_info); RequestManagerRegistry.addMethod("one.host.monitoring", host_monitoring); - RequestManagerRegistry.addMethod("one.hostpool.info", hostpool_info); + RequestManagerRegistry.addMethod("one.hostpool.info", hostpool_info); RequestManagerRegistry.addMethod("one.hostpool.monitoring", host_pool_monitoring); /* Group related methods */ @@ -443,13 +445,13 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate); RequestManagerRegistry.addMethod("one.vn.update", vn_update); RequestManagerRegistry.addMethod("one.vn.delete", vn_delete); - RequestManagerRegistry.addMethod("one.vn.info", vn_info); + RequestManagerRegistry.addMethod("one.vn.info", vn_info); RequestManagerRegistry.addMethod("one.vn.chown", vn_chown); RequestManagerRegistry.addMethod("one.vn.chmod", vn_chmod); RequestManagerRegistry.addMethod("one.vn.rename", vn_rename); - RequestManagerRegistry.addMethod("one.vnpool.info", vnpool_info); - + RequestManagerRegistry.addMethod("one.vnpool.info", vnpool_info); + /* User related methods*/ RequestManagerRegistry.addMethod("one.user.allocate", user_allocate); RequestManagerRegistry.addMethod("one.user.update", user_update); @@ -464,11 +466,11 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.userquota.info", user_get_default_quota); RequestManagerRegistry.addMethod("one.userquota.update", user_set_default_quota); - + /* Image related methods*/ RequestManagerRegistry.addMethod("one.image.persistent", image_persistent); RequestManagerRegistry.addMethod("one.image.enable", image_enable); - RequestManagerRegistry.addMethod("one.image.update", image_update); + RequestManagerRegistry.addMethod("one.image.update", image_update); RequestManagerRegistry.addMethod("one.image.allocate", image_allocate); RequestManagerRegistry.addMethod("one.image.delete", image_delete); RequestManagerRegistry.addMethod("one.image.info", image_info); @@ -529,4 +531,4 @@ void RequestManager::register_xml_methods() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - + diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index c2c182e8a3..d405df16c3 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -68,6 +68,8 @@ VirtualMachine::VirtualMachine(int id, { obj_template = new VirtualMachineTemplate; } + + user_obj_template = new Template(false,'=',"USER_TEMPLATE"); } VirtualMachine::~VirtualMachine() @@ -77,15 +79,20 @@ VirtualMachine::~VirtualMachine() delete history_records[i]; } - if ( _log != 0 ) + if (_log != 0) { delete _log; } - if ( obj_template != 0 ) + if (obj_template != 0) { delete obj_template; } + + if (user_obj_template != 0) + { + delete user_obj_template; + } } /* ************************************************************************** */ @@ -2220,6 +2227,7 @@ error_yy: string& VirtualMachine::to_xml_extended(string& xml, int n_history) const { string template_xml; + string user_template_xml; string history_xml; string perm_xml; ostringstream oss; @@ -2243,7 +2251,8 @@ string& VirtualMachine::to_xml_extended(string& xml, int n_history) const << "" << cpu << "" << "" << net_tx << "" << "" << net_rx << "" - << obj_template->to_xml(template_xml); + << obj_template->to_xml(template_xml) + << user_obj_template->to_xml(user_template_xml); if ( hasHistory() && n_history > 0 ) { @@ -2319,21 +2328,34 @@ int VirtualMachine::from_xml(const string &xml_str) state = static_cast(istate); lcm_state = static_cast(ilcmstate); - // Get associated classes + // Virtual Machine template ObjectXML::get_nodes("/VM/TEMPLATE", content); if (content.empty()) { return -1; } - - // Virtual Machine template rc += obj_template->from_xml_node(content[0]); - // Last history entry ObjectXML::free_nodes(content); content.clear(); + // Virtual Machine user template + + ObjectXML::get_nodes("/VM/USER_TEMPLATE", content); + + if (content.empty()) + { + return -1; + } + + rc += user_obj_template->from_xml_node(content[0]); + + ObjectXML::free_nodes(content); + content.clear(); + + // Last history entry + ObjectXML::get_nodes("/VM/HISTORY_RECORDS/HISTORY", content); if (!content.empty()) @@ -2367,3 +2389,35 @@ string VirtualMachine::get_system_dir() const return oss.str(); }; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachine::replace_template(const string& tmpl_str, string& error) +{ + Template * new_tmpl = new Template(false,'=',"USER_TEMPLATE"); + + if ( new_tmpl == 0 ) + { + error = "Cannot allocate a new template"; + return -1; + } + + if ( new_tmpl->parse_str_or_xml(tmpl_str, error) != 0 ) + { + delete new_tmpl; + return -1; + } + + if (user_obj_template != 0) + { + delete user_obj_template; + } + + user_obj_template = new_tmpl; + + return 0; +} From 68efaa7e62012a5e79e00bb1bdb90dab3d9d9b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 8 Jan 2013 15:17:00 +0100 Subject: [PATCH 2/3] Feature #1556: Add new elem to migrator, and xsd --- share/doc/xsd/vm.xsd | 1 + .../opennebula/client/vm/VirtualMachine.java | 13 ++++++++- src/onedb/3.8.1_to_3.9.80.rb | 29 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/share/doc/xsd/vm.xsd b/share/doc/xsd/vm.xsd index ae3b333c6f..a6f1b96bbe 100644 --- a/share/doc/xsd/vm.xsd +++ b/share/doc/xsd/vm.xsd @@ -87,6 +87,7 @@ + diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index 583a06ff10..6b1509c165 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -175,7 +175,7 @@ public class VirtualMachine extends PoolElement{ * @param client XML-RPC Client. * @param id The id of the target vm. * @param new_template New template contents - * @return If successful the message contains the vm id. + * @return If an error occurs the error message contains the reason. */ public static OneResponse update(Client client, int id, String new_template) { @@ -558,6 +558,17 @@ public class VirtualMachine extends PoolElement{ return rename(client, id, name); } + /** + * Replaces this VM's user template contents. + * + * @param new_template New template contents + * @return If an error occurs the error message contains the reason. + */ + public OneResponse update(String new_template) + { + return client.call(UPDATE, id, new_template); + } + // ================================= // Helpers // ================================= diff --git a/src/onedb/3.8.1_to_3.9.80.rb b/src/onedb/3.8.1_to_3.9.80.rb index d03487348a..021b4039c3 100644 --- a/src/onedb/3.8.1_to_3.9.80.rb +++ b/src/onedb/3.8.1_to_3.9.80.rb @@ -345,6 +345,35 @@ module Migrator @db.run "DROP TABLE old_cluster_pool;" + ######################################################################## + # Feature #1556: New elem USER_TEMPLATE + ######################################################################## + + @db.run "ALTER TABLE vm_pool RENAME TO old_vm_pool;" + @db.run "CREATE TABLE vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER);" + + @db.fetch("SELECT * FROM old_vm_pool") do |row| + + doc = Document.new(row[:body]) + doc.root.add_element("USER_TEMPLATE") + + @db[:vm_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => doc.root.to_s, + :uid => row[:uid], + :gid => row[:gid], + :last_poll => row[:last_poll], + :state => row[:state], + :lcm_state => row[:lcm_state], + :owner_u => row[:owner_u], + :group_u => row[:group_u], + :other_u => row[:other_u]) + end + + @db.run "DROP TABLE old_vm_pool;" + + ######################################################################## # # Banner for the new /var/lib/one/vms directory From f51d1f1af6c8a9a7ccc4918ec63ee89e1de25c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 9 Jan 2013 12:22:50 +0100 Subject: [PATCH 3/3] Feature #1556: Remove help formatting, just in case it breaks something in the manpages later --- src/cli/onevm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/onevm b/src/cli/onevm index 6807646bf8..b023086778 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -175,7 +175,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do end update_desc = <<-EOT.unindent - Update the *user* template contents. If a path is not provided the + Update the user template contents. If a path is not provided the editor will be launched to modify the current content. EOT