From f9b7f820c6a7b4ea05c6979c6d0ff0b8ed1175b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 4 Feb 2013 18:09:18 +0100 Subject: [PATCH 01/21] Feature #1483: Scheduler executes scheduled actions Syntax inside VM/USER_TEMPLATE: SCHED_ACTION = [ ACTION = "resume/stop/shutdown...", TIME=12345 ] --- src/scheduler/include/Scheduler.h | 3 + src/scheduler/include/VirtualMachinePoolXML.h | 40 ++++- src/scheduler/include/VirtualMachineXML.h | 10 ++ .../src/pool/VirtualMachinePoolXML.cc | 101 +++++++++++++ src/scheduler/src/sched/Scheduler.cc | 138 ++++++++++++++++++ 5 files changed, 286 insertions(+), 6 deletions(-) diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 52b0f32da5..13925a13fa 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -133,6 +133,9 @@ protected: */ virtual int set_up_pools(); + + virtual int scheduled_actions(); + private: Scheduler(Scheduler const&){}; diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index 02f3ac8989..3aa091847b 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -43,6 +43,15 @@ public: */ int set_up(); + /** + * Retrieves the VMs with scheduled actions + * + * @return 0 on success + * -1 on error + * -2 if no VMs need to be scheduled + */ + int set_up_actions(); + /** * Gets an object from the pool * @param oid the object unique identifier @@ -66,12 +75,16 @@ public: * Update the VM template * @param vid the VM id * @param st the template string + * + * @return 0 on success, -1 otherwise */ int update(int vid, const string &st) const; /** * Update the VM template * @param the VM + * + * @return 0 on success, -1 otherwise */ int update(VirtualMachineXML * vm) const { @@ -80,20 +93,35 @@ public: return update(vm->get_oid(), vm->get_template(xml)); }; + /** + * Calls one.vm.action + * + * @param vid The VM id + * @param action Action argument (shutdown, hold, release...) + * @param error_msg Error reason, if any + * + * @return 0 on success, -1 otherwise + */ + int action(int vid, const string &action, string &error_msg) const; + protected: - int get_suitable_nodes(vector& content) - { - return get_nodes("/VM_POOL/VM[STATE=1 or (LCM_STATE=3 and RESCHED=1)]", - content); - }; + int get_suitable_nodes(vector& content); virtual void add_object(xmlNodePtr node); virtual int load_info(xmlrpc_c::value &result); - /* Do live migrations to resched VMs*/ + /** + * Do live migrations to resched VMs + */ bool live_resched; + + /** + * True to retrieve pending/resched VMs, false to get VMs with scheduled + * actions + */ + bool retrieve_pending; }; #endif /* VM_POOL_XML_H_ */ diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index 3261d4a012..47fb24d86e 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -124,6 +124,16 @@ public: return xml_str; } + /** + * Returns a the VM Template + * + * @return A pointer to the VM Template (not to a copy) + */ + VirtualMachineTemplate* get_template() + { + return vm_template; + }; + /** * Function to write a Virtual Machine in an output stream */ diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index c48b131e82..0d6080d649 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -22,6 +22,8 @@ int VirtualMachinePoolXML::set_up() ostringstream oss; int rc; + retrieve_pending = true; + rc = PoolXML::set_up(); if ( rc == 0 ) @@ -50,6 +52,63 @@ int VirtualMachinePoolXML::set_up() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int VirtualMachinePoolXML::set_up_actions() +{ + ostringstream oss; + int rc; + + retrieve_pending = false; + + rc = PoolXML::set_up(); + + if ( rc == 0 ) + { + if (objects.empty()) + { + return -2; + } + + oss.str(""); + oss << "VMs with scheduled actions:" << endl; + + map::iterator it; + + for (it=objects.begin();it!=objects.end();it++) + { + oss << " " << it->first; + } + + NebulaLog::log("VM",Log::DEBUG,oss); + } + + return rc; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachinePoolXML::get_suitable_nodes(vector& content) +{ + if (retrieve_pending) + { + return get_nodes( + "/VM_POOL/VM[STATE=1 or (LCM_STATE=3 and RESCHED=1)]", + content); + } + + ostringstream oss; + + oss << "/VM_POOL/VM/USER_TEMPLATE/SCHED_ACTION[TIME < " << time(0) + << " and not(DONE > 0)]/../.."; + + return get_nodes( + oss.str().c_str(), + content); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void VirtualMachinePoolXML::add_object(xmlNodePtr node) { if ( node == 0 || node->children == 0 || node->children->next==0 ) @@ -209,3 +268,45 @@ int VirtualMachinePoolXML::update(int vid, const string &st) const return 0; } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachinePoolXML::action( + int vid, + const string& action, + string& error_msg) const +{ + xmlrpc_c::value result; + bool success; + + try + { + client->call( client->get_endpoint(), // serverUrl + "one.vm.action", // methodName + "ssi", // arguments format + &result, // resultP + client->get_oneauth().c_str(), // session + action.c_str(), // action + vid // VM ID + ); + } + catch (exception const& e) + { + return -1; + } + + vector values = + xmlrpc_c::value_array(result).vectorValueValue(); + + success = xmlrpc_c::value_boolean(values[0]); + + if (!success) + { + error_msg = xmlrpc_c::value_string( values[1] ); + + return -1; + } + + return 0; +} diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 87474a7e8a..a7fbf549ca 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -623,12 +623,150 @@ void Scheduler::dispatch() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int Scheduler::scheduled_actions() +{ + int rc = vmpool->set_up_actions(); + + if ( rc != 0 ) + { + return rc; + } + + VirtualMachineXML* vm; + VirtualMachineTemplate* vm_template; + + vector v_st; + + map::const_iterator vm_it; + + vector attributes; + vector::iterator it; + + VectorAttribute* vatt; + + time_t the_time = time(0); + + int action_time, done_time, has_time, has_done; + string action_st, error_msg; + + // TODO: Move the time string creation to a common place + + char time_str[26]; + + ostringstream oss; + ostringstream oss_aux; + +#ifdef SOLARIS + ctime_r(&(the_time),time_str,sizeof(char)*26); +#else + ctime_r(&(the_time),time_str); +#endif + + time_str[24] = '\0'; // Get rid of final enter character + + + const map vms = vmpool->get_objects(); + + for (vm_it=vms.begin(); vm_it != vms.end(); vm_it++) + { + vm = static_cast(vm_it->second); + vm_template = vm->get_template(); + + attributes.clear(); + vm_template->remove("SCHED_ACTION", attributes); + + // TODO: Sort actions by TIME + + for (it=attributes.begin(); it != attributes.end(); it++) + { + vatt = dynamic_cast(*it); + + if (vatt == 0) + { + continue; + } + + has_time = vatt->vector_value("TIME", action_time); + has_done = vatt->vector_value("DONE", done_time); + + // TODO: Transform to lower case + action_st = vatt->vector_value("ACTION"); + + if (has_time == 0 && has_done == -1 && action_time < the_time) + { + oss.str(""); + + // onevm delete command uses the xml-rpc finalize action + if (action_st == "delete") + { + action_st = "finalize"; + } + + oss << "Executing action '" << action_st << "' for VM " + << vm->get_oid() << " : "; + + if ( action_st != "shutdown" + && action_st != "hold" + && action_st != "release" + && action_st != "stop" + && action_st != "cancel" + && action_st != "suspend" + && action_st != "resume" + && action_st != "restart" + && action_st != "resubmit" + && action_st != "reboot" + && action_st != "reset" + && action_st != "poweroff" + && action_st != "finalize") + { + error_msg = "This action is not supported."; + rc = -1; + } + else + { + rc = vmpool->action(vm->get_oid(), action_st, error_msg); + } + + if (rc == 0) + { + vatt->remove("MESSAGE"); + vatt->replace("DONE", static_cast(the_time)); + + oss << "Success."; + } + else + { + oss_aux.str(""); + oss_aux << time_str << " : " << error_msg; + + vatt->replace("MESSAGE", oss_aux.str()); + + oss << "Failure. " << error_msg; + } + + NebulaLog::log("VM",Log::INFO,oss); + } + + vm_template->set(vatt); + } + + vmpool->update(vm); + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void Scheduler::do_action(const string &name, void *args) { int rc; if (name == ACTION_TIMER) { + scheduled_actions(); + rc = set_up_pools(); if ( rc != 0 ) From 3b01566e9b0172e253612595e8e2d8f1040b1320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 4 Feb 2013 18:48:05 +0100 Subject: [PATCH 02/21] Feature #1483: Create new Util.h file to define common methods, like creating log timestamp strings --- include/Util.h | 60 ++++++++++++++++++++++++++++ src/scheduler/src/sched/Scheduler.cc | 17 ++------ 2 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 include/Util.h diff --git a/include/Util.h b/include/Util.h new file mode 100644 index 0000000000..63a8df747a --- /dev/null +++ b/include/Util.h @@ -0,0 +1,60 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +#ifndef UTIL_H_ +#define UTIL_H_ + +#include + +using namespace std; + +namespace one_util +{ + string& toupper(string& st) + { + transform(st.begin(),st.end(),st.begin(),(int(*)(int))std::toupper); + return st; + }; + + string& tolower(string& st) + { + transform(st.begin(),st.end(),st.begin(),(int(*)(int))std::tolower); + return st; + }; + + string log_time(time_t the_time) + { + char time_str[26]; + +#ifdef SOLARIS + ctime_r(&(the_time),time_str,sizeof(char)*26); +#else + ctime_r(&(the_time),time_str); +#endif + + time_str[24] = '\0'; // Get rid of final enter character + + return string(time_str); + }; + + string log_time() + { + return log_time( time(0) ); + }; +} + + +#endif /* UTIL_H_ */ diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index a7fbf549ca..d1d30f6a13 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -34,6 +34,7 @@ #include "RankPolicy.h" #include "NebulaLog.h" #include "PoolObjectAuth.h" +#include "Util.h" using namespace std; @@ -649,21 +650,10 @@ int Scheduler::scheduled_actions() int action_time, done_time, has_time, has_done; string action_st, error_msg; - // TODO: Move the time string creation to a common place - - char time_str[26]; - ostringstream oss; ostringstream oss_aux; -#ifdef SOLARIS - ctime_r(&(the_time),time_str,sizeof(char)*26); -#else - ctime_r(&(the_time),time_str); -#endif - - time_str[24] = '\0'; // Get rid of final enter character - + string time_str = one_util::log_time(the_time); const map vms = vmpool->get_objects(); @@ -689,9 +679,10 @@ int Scheduler::scheduled_actions() has_time = vatt->vector_value("TIME", action_time); has_done = vatt->vector_value("DONE", done_time); - // TODO: Transform to lower case action_st = vatt->vector_value("ACTION"); + one_util::tolower(action_st); + if (has_time == 0 && has_done == -1 && action_time < the_time) { oss.str(""); From e904781cf1a5e5e99892f4534141afcc9f669473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 5 Feb 2013 15:55:17 +0100 Subject: [PATCH 03/21] Feature #1483: Add new option --schedule TIME to onevm commands --- src/cli/one_helper/onevm_helper.rb | 29 +++++ src/cli/onevm | 143 +++++++++++++++------ src/oca/ruby/opennebula/virtual_machine.rb | 20 +++ 3 files changed, 153 insertions(+), 39 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 41f1646da2..d289d0d832 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -15,6 +15,7 @@ #--------------------------------------------------------------------------- # require 'one_helper' +require 'optparse/time' class OneVMHelper < OpenNebulaHelper::OneHelper MULTIPLE={ @@ -57,6 +58,13 @@ class OneVMHelper < OpenNebulaHelper::OneHelper :description => "Creates the new VM on hold state instead of pending" } + SCHEDULE = { + :name => "schedule", + :large => "--schedule TIME", + :description => "Schedules this action to be executed after the given time", + :format => Time + } + def self.rname "VM" end @@ -141,6 +149,27 @@ class OneVMHelper < OpenNebulaHelper::OneHelper table end + + def schedule_actions(ids,options,action) + perform_actions( + ids, options, + "#{action} scheduled at #{options[:schedule]}") do |vm| + + rc = vm.info + + if OpenNebula.is_error?(rc) + puts rc.message + exit -1 + end + + tmp_str = vm.user_template_str + + tmp_str << "\nSCHED_ACTION = [ACTION = #{action}, TIME = #{options[:schedule].to_i}]" + + vm.update(tmp_str) + end + end + private def factory(id=nil) diff --git a/src/cli/onevm b/src/cli/onevm index 913518457c..cea2d42190 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -192,9 +192,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: ANY EOT - command :delete, delete_desc, [:range, :vmid_list] do - helper.perform_actions(args[0],options,"deleted") do |vm| - vm.finalize + command :delete, delete_desc, [:range, :vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"deleted") do |vm| + vm.finalize + end end end @@ -205,9 +210,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: PENDING EOT - command :hold, hold_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"put on hold") do |vm| - vm.hold + command :hold, hold_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"put on hold") do |vm| + vm.hold + end end end @@ -217,9 +227,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: HOLD EOT - command :release, release_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"released") do |vm| - vm.release + command :release, release_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"released") do |vm| + vm.release + end end end @@ -257,9 +272,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :shutdown, shutdown_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"shutting down") do |vm| - vm.shutdown + command :shutdown, shutdown_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"shutting down") do |vm| + vm.shutdown + end end end @@ -270,9 +290,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :poweroff, poweroff_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"shutting down") do |vm| - vm.poweroff + command :poweroff, poweroff_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"shutting down") do |vm| + vm.poweroff + end end end @@ -283,9 +308,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :reboot, reboot_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"rebooting") do |vm| - vm.reboot + command :reboot, reboot_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"rebooting") do |vm| + vm.reboot + end end end @@ -295,9 +325,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :reset, reset_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"resetting") do |vm| - vm.reset + command :reset, reset_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"resetting") do |vm| + vm.reset + end end end @@ -366,9 +401,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: UNKNOWN, BOOT, POWEROFF EOT - command :restart, restart_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"restarting") do |vm| - vm.restart + command :restart, restart_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"restarting") do |vm| + vm.restart + end end end @@ -380,9 +420,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: ANY, except SUSPENDED or DONE EOT - command :resubmit, resubmit_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"resubmiting") do |vm| - vm.resubmit + command :resubmit, resubmit_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"resubmiting") do |vm| + vm.resubmit + end end end @@ -394,9 +439,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :cancel, cancel_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"canceling") do |vm| - vm.cancel + command :cancel, cancel_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"canceling") do |vm| + vm.cancel + end end end @@ -407,9 +457,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :stop, stop_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"stopping") do |vm| - vm.stop + command :stop, stop_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"stopping") do |vm| + vm.stop + end end end @@ -422,9 +477,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: RUNNING EOT - command :suspend, suspend_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"suspending") do |vm| - vm.suspend + command :suspend, suspend_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"suspending") do |vm| + vm.suspend + end end end @@ -434,9 +494,14 @@ cmd=CommandParser::CmdParser.new(ARGV) do States: STOPPED, SUSPENDED EOT - command :resume, resume_desc, [:range,:vmid_list] do - helper.perform_actions(args[0],options,"resuming") do |vm| - vm.resume + command :resume, resume_desc, [:range,:vmid_list], + :options => [OneVMHelper::SCHEDULE] do + if (!options[:schedule].nil?) + helper.schedule_actions(args[0], options, @comm_name) + else + helper.perform_actions(args[0],options,"resuming") do |vm| + vm.resume + end end end diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index 94a21f22b6..ebf5be492b 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -155,6 +155,26 @@ module OpenNebula super(VM_METHODS[:update], new_template) end + # Returns the element in text form + # + # @param indent [true,false] indents the resulting string, defaults to true + # + # @return [String] The USER_TEMPLATE + def user_template_str(indent=true) + template_like_str('USER_TEMPLATE', indent) + end + + # Returns the element in XML form + # + # @return [String] The USER_TEMPLATE + def user_template_xml + if NOKOGIRI + @xml.xpath('TEMPLATE').to_s + else + @xml.elements['TEMPLATE'].to_s + end + end + # Initiates the instance of the VM on the target host. # From a75c7e5fdd494230d5f5c81df65704acd432f11d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 5 Feb 2013 17:08:04 +0100 Subject: [PATCH 04/21] Feature #1483: onevm show lists scheduled actions in a table --- src/cli/cli_helper.rb | 3 +++ src/cli/one_helper.rb | 10 ++++++++-- src/cli/one_helper/onevm_helper.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/cli/cli_helper.rb b/src/cli/cli_helper.rb index ff095ffdc5..1fbd83b1f1 100644 --- a/src/cli/cli_helper.rb +++ b/src/cli/cli_helper.rb @@ -252,6 +252,9 @@ module CLIHelper if @columns[field] minus=( @columns[field][:left] ? "-" : "" ) size=@columns[field][:size] + if @columns[field][:donottruncate] + return "%#{minus}#{size}s" % [ data.to_s ] + end return "%#{minus}#{size}.#{size}s" % [ data.to_s ] else exit -1, "Column #{field} not defined." diff --git a/src/cli/one_helper.rb b/src/cli/one_helper.rb index 9b02938cb3..f812bc0de6 100644 --- a/src/cli/one_helper.rb +++ b/src/cli/one_helper.rb @@ -577,13 +577,19 @@ EOT end end - def OpenNebulaHelper.time_to_str(time) + def OpenNebulaHelper.time_to_str(time, print_seconds=true) value=time.to_i if value==0 value='-' else - value=Time.at(value).strftime("%m/%d %H:%M:%S") + if print_seconds + value=Time.at(value).strftime("%m/%d %H:%M:%S") + else + value=Time.at(value).strftime("%m/%d %H:%M") + end end + + return value end def OpenNebulaHelper.period_to_str(time, print_seconds=true) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index d289d0d832..5ad3cd9481 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -241,12 +241,39 @@ class OneVMHelper < OpenNebulaHelper::OneHelper } puts + if vm.has_elements?("/VM/USER_TEMPLATE/SCHED_ACTION") + CLIHelper.print_header(str_h1 % "SCHEDULED ACTIONS",false) + + CLIHelper::ShowTable.new(nil, self) do + + column :"ACTION", "", :left, :size=>10 do |d| + d["ACTION"] if !d.nil? + end + + column :"SCHEDULED", "", :size=>12 do |d| + OpenNebulaHelper.time_to_str(d["TIME"], false) if !d.nil? + end + + column :"DONE", "", :size=>12 do |d| + OpenNebulaHelper.time_to_str(d["DONE"], false) if !d.nil? + end + + column :"MESSAGE", "", :left, :donottruncate, :size=>43 do |d| + d["MESSAGE"] if !d.nil? + end + end.show(vm.to_hash['VM']['USER_TEMPLATE']['SCHED_ACTION'], {}) + + puts + end + CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE TEMPLATE",false) puts vm.template_str if vm.has_elements?("/VM/USER_TEMPLATE") puts + vm.delete_element("/VM/USER_TEMPLATE/SCHED_ACTION") + CLIHelper.print_header(str_h1 % "USER TEMPLATE",false) puts vm.template_like_str('USER_TEMPLATE') end From c483e7bba0800373f3a79e6a07bb4cbe31fe2e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 6 Feb 2013 15:23:55 +0100 Subject: [PATCH 05/21] Feature #1483 #1556: VM attributes understood by opennebula are moved to TEMPLATE, the rest are left in USER_TEMPLATE --- include/Template.h | 10 +++ include/VirtualMachineTemplate.h | 7 +- src/vm/VirtualMachine.cc | 124 ++++++++++++++++++++++++------- 3 files changed, 113 insertions(+), 28 deletions(-) diff --git a/include/Template.h b/include/Template.h index 7726bdf23e..14c820723e 100644 --- a/include/Template.h +++ b/include/Template.h @@ -351,6 +351,16 @@ protected: */ bool check(string& rs_attr, const vector &restricted_attributes); + /** + * Updates the xml root element name + * + * @param _xml_root New name + */ + void set_xml_root(const char * _xml_root) + { + xml_root = _xml_root; + }; + private: bool replace_mode; diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index 0f2575f3f6..532c6fae0d 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -45,7 +45,12 @@ public: { return Template::check(rs_attr, restricted_attributes); }; - + + void set_xml_root(const char * _xml_root) + { + Template::set_xml_root(_xml_root); + }; + private: friend class VirtualMachinePool; diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 835e1d2bb4..8fd9bcfeaf 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -63,14 +63,17 @@ VirtualMachine::VirtualMachine(int id, { if (_vm_template != 0) { - obj_template = _vm_template; + // This is a VM Template, with the root TEMPLATE. + _vm_template->set_xml_root("USER_TEMPLATE"); + + user_obj_template = _vm_template; } else { - obj_template = new VirtualMachineTemplate; + user_obj_template = new Template(false,'=',"USER_TEMPLATE"); } - user_obj_template = new Template(false,'=',"USER_TEMPLATE"); + obj_template = new VirtualMachineTemplate; set_umask(umask); } @@ -236,13 +239,24 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) oss << oid; value = oss.str(); - replace_template_attribute("VMID", value); + user_obj_template->erase("VMID"); + obj_template->add("VMID", value); - get_template_attribute("NAME",name); + user_obj_template->get("TEMPLATE_ID", value); + user_obj_template->erase("TEMPLATE_ID"); + + if (!value.empty()) + { + obj_template->add("TEMPLATE_ID", value); + } + + user_obj_template->get("NAME",name); + user_obj_template->erase("NAME"); if (name.empty() == true) { - get_template_attribute("TEMPLATE_NAME", prefix); + user_obj_template->get("TEMPLATE_NAME", prefix); + user_obj_template->erase("TEMPLATE_NAME"); if (prefix.empty()) { @@ -252,8 +266,6 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) oss.str(""); oss << prefix << "-" << oid; name = oss.str(); - - replace_template_attribute("NAME", name); } else if (name.length() > 128) { @@ -266,26 +278,35 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) // Check for CPU, VCPU and MEMORY attributes // ------------------------------------------------------------------------ - if ( get_template_attribute("MEMORY", ivalue) == false || ivalue <= 0 ) + if ( user_obj_template->get("MEMORY", ivalue) == false || ivalue <= 0 ) { goto error_memory; } - if ( get_template_attribute("CPU", fvalue) == false || fvalue <= 0 ) + user_obj_template->erase("MEMORY"); + obj_template->add("MEMORY", ivalue); + + if ( user_obj_template->get("CPU", fvalue) == false || fvalue <= 0 ) { goto error_cpu; } + user_obj_template->erase("CPU"); + obj_template->add("CPU", fvalue); + // VCPU is optional, first check if the attribute exists, then check it is // an integer - get_template_attribute("VCPU", value); + user_obj_template->get("VCPU", value); if ( value.empty() == false ) { - if ( get_template_attribute("VCPU", ivalue) == false || ivalue <= 0 ) + if ( user_obj_template->get("VCPU", ivalue) == false || ivalue <= 0 ) { goto error_vcpu; } + + user_obj_template->erase("VCPU"); + obj_template->add("VCPU", ivalue); } // ------------------------------------------------------------------------ @@ -511,7 +532,14 @@ int VirtualMachine::parse_os(string& error_str) vector os_attr; VectorAttribute * os; - num = obj_template->get("OS", os_attr); + vector::iterator it; + + num = user_obj_template->remove("OS", os_attr); + + for (it=os_attr.begin(); it != os_attr.end(); it++) + { + obj_template->set(*it); + } if ( num == 0 ) { @@ -568,7 +596,7 @@ int VirtualMachine::parse_context(string& error_str) vector img_ids; - num = obj_template->remove("CONTEXT", array_context); + num = user_obj_template->remove("CONTEXT", array_context); if ( num == 0 ) { @@ -703,7 +731,14 @@ void VirtualMachine::parse_graphics() vector array_graphics; VectorAttribute * graphics; - num = obj_template->get("GRAPHICS", array_graphics); + vector::iterator it; + + num = user_obj_template->remove("GRAPHICS", array_graphics); + + for (it=array_graphics.begin(); it != array_graphics.end(); it++) + { + obj_template->set(*it); + } if ( num == 0 ) { @@ -750,7 +785,7 @@ int VirtualMachine::parse_requirements(string& error_str) string parsed; - num = obj_template->remove("REQUIREMENTS", array_reqs); + num = user_obj_template->remove("REQUIREMENTS", array_reqs); if ( num == 0 ) { @@ -838,6 +873,8 @@ int VirtualMachine::automatic_requirements(string& error_str) vector v_attributes; VectorAttribute * vatt; + vector::iterator it; + ostringstream oss; string requirements; string cluster_id = ""; @@ -847,7 +884,12 @@ int VirtualMachine::automatic_requirements(string& error_str) // Get cluster id from all DISK vector attributes (IMAGE Datastore) - num_vatts = obj_template->get("DISK",v_attributes); + num_vatts = user_obj_template->remove("DISK",v_attributes); + + for (it=v_attributes.begin(); it != v_attributes.end(); it++) + { + obj_template->set(*it); + } for(int i=0; iget("OS",v_attributes); + num_vatts = user_obj_template->remove("OS",v_attributes); + + for (it=v_attributes.begin(); it != v_attributes.end(); it++) + { + obj_template->set(*it); + } if ( num_vatts > 0 ) { @@ -897,7 +944,12 @@ int VirtualMachine::automatic_requirements(string& error_str) // Get cluster id from all NIC vector attributes v_attributes.clear(); - num_vatts = obj_template->get("NIC",v_attributes); + num_vatts = user_obj_template->remove("NIC",v_attributes); + + for (it=v_attributes.begin(); it != v_attributes.end(); it++) + { + obj_template->set(*it); + } for(int i=0; iget("REQUIREMENTS", requirements); + user_obj_template->erase("REQUIREMENTS"); if ( !requirements.empty() ) { oss << " & ( " << requirements << " )"; } - replace_template_attribute("REQUIREMENTS", oss.str()); + obj_template->add("REQUIREMENTS", oss.str()); } return 0; @@ -1289,11 +1342,23 @@ int VirtualMachine::get_disk_images(string& error_str) Nebula& nd = Nebula::instance(); ipool = nd.get_ipool(); + vector::iterator it; + // ------------------------------------------------------------------------- // The context is the first of the cdroms // ------------------------------------------------------------------------- - num_context = obj_template->get("CONTEXT", context_disks); - num_disks = obj_template->get("DISK", disks); + num_context = user_obj_template->remove("CONTEXT", context_disks); + num_disks = user_obj_template->remove("DISK", disks); + + for (it=context_disks.begin(); it != context_disks.end(); it++) + { + obj_template->set(*it); + } + + for (it=disks.begin(); it != disks.end(); it++) + { + obj_template->set(*it); + } if ( num_disks > 20 ) { @@ -1408,11 +1473,11 @@ error_duplicated_target: error_common: ImageManager * imagem = nd.get_imagem(); - vector::iterator it; + vector::iterator img_it; - for ( it=acquired_images.begin() ; it < acquired_images.end(); it++ ) + for ( img_it=acquired_images.begin() ; img_it < acquired_images.end(); img_it++ ) { - imagem->release_image(oid, *it, false); + imagem->release_image(oid, *img_it, false); } return -1; @@ -1749,7 +1814,12 @@ int VirtualMachine::get_network_leases(string& estr) Nebula& nd = Nebula::instance(); vnpool = nd.get_vnpool(); - num_nics = obj_template->get("NIC",nics); + num_nics = user_obj_template->remove("NIC",nics); + + for (vector::iterator it=nics.begin(); it != nics.end(); it++) + { + obj_template->set(*it); + } for(int i=0; i Date: Wed, 6 Feb 2013 16:34:46 +0100 Subject: [PATCH 06/21] Feature #1483 #1556: Leave SCHED_REQUIREMENTS and SCHED_RANK in the USER_TEMPLATE, so they can be edited --- include/VirtualMachine.h | 2 +- share/etc/oned.conf | 4 +++ src/scheduler/src/pool/VirtualMachineXML.cc | 16 +++++++-- src/scheduler/src/sched/Scheduler.cc | 6 ++-- src/vm/VirtualMachine.cc | 39 ++++++++++++++++----- 5 files changed, 52 insertions(+), 15 deletions(-) diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 633e186516..55a12f7024 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1177,7 +1177,7 @@ private: int parse_context(string& error_str); /** - * Parse the "REQUIREMENTS" attribute of the template by substituting + * Parse the "SCHED_REQUIREMENTS" attribute of the template by substituting * $VARIABLE, $VARIABLE[ATTR] and $VARIABLE[ATTR, ATTR = VALUE] * @param error_str Returns the error reason, if any * @return 0 on success diff --git a/share/etc/oned.conf b/share/etc/oned.conf index f32a3254f0..548408c43d 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -491,6 +491,10 @@ DEFAULT_UMASK = 177 VM_RESTRICTED_ATTR = "CONTEXT/FILES" VM_RESTRICTED_ATTR = "NIC/MAC" VM_RESTRICTED_ATTR = "NIC/VLAN_ID" + VM_RESTRICTED_ATTR = "RANK" +VM_RESTRICTED_ATTR = "SCHED_RANK" +VM_RESTRICTED_ATTR = "REQUIREMENTS" +VM_RESTRICTED_ATTR = "SCHED_REQUIREMENTS" IMAGE_RESTRICTED_ATTR = "SOURCE" diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index fd4d3561a0..91195a2ad0 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -51,7 +51,7 @@ void VirtualMachineXML::init_attributes() cpu = 0; } - result = ((*this)["/VM/TEMPLATE/RANK"]); + result = ((*this)["/VM/USER_TEMPLATE/SCHED_RANK"]); if (result.size() > 0) { @@ -59,10 +59,20 @@ void VirtualMachineXML::init_attributes() } else { - rank = ""; + // Compatibility with previous versions + result = ((*this)["/VM/USER_TEMPLATE/RANK"]); + + if (result.size() > 0) + { + rank = result[0]; + } + else + { + rank = ""; + } } - result = ((*this)["/VM/TEMPLATE/REQUIREMENTS"]); + result = ((*this)["/VM/USER_TEMPLATE/SCHED_REQUIREMENTS"]); if (result.size() > 0) { diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index d1d30f6a13..e1b7dd3a8a 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -431,7 +431,7 @@ void Scheduler::match() matched = false; n_error++; - error_msg << "Error evaluating REQUIREMENTS expression: '" + error_msg << "Error evaluating SCHED_REQUIREMENTS expression: '" << reqs << "', error: " << error; oss << "VM " << oid << ": " << error_msg.str(); @@ -454,7 +454,7 @@ void Scheduler::match() ostringstream oss; oss << "VM " << oid << ": Host " << host->get_hid() << - " filtered out. It does not fulfill REQUIREMENTS."; + " filtered out. It does not fulfill SCHED_REQUIREMENTS."; NebulaLog::log("SCHED",Log::DEBUG,oss); continue; @@ -503,7 +503,7 @@ void Scheduler::match() } else if (n_matched == 0) { - vm->log("No host meets the REQUIREMENTS expression"); + vm->log("No host meets the SCHED_REQUIREMENTS expression"); } else { diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 8fd9bcfeaf..890c7088d5 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -785,7 +785,30 @@ int VirtualMachine::parse_requirements(string& error_str) string parsed; - num = user_obj_template->remove("REQUIREMENTS", array_reqs); + num = user_obj_template->remove("SCHED_REQUIREMENTS", array_reqs); + + if ( num == 0 ) // Compatibility with old REQUIREMENTS attribute + { + vector array_reqs_aux; + vector::iterator it; + + num = user_obj_template->remove("REQUIREMENTS", array_reqs_aux); + + // Rename att to SCHED_REQUIREMENTS + for (it = array_reqs_aux.begin(); it != array_reqs_aux.end(); it++) + { + reqs = dynamic_cast(*it); + + if (reqs != 0) + { + array_reqs.push_back( new SingleAttribute( + "SCHED_REQUIREMENTS", + reqs->value()) ); + } + + delete *it; + } + } if ( num == 0 ) { @@ -793,7 +816,7 @@ int VirtualMachine::parse_requirements(string& error_str) } else if ( num > 1 ) { - error_str = "Only one REQUIREMENTS attribute can be defined."; + error_str = "Only one SCHED_REQUIREMENTS attribute can be defined."; goto error_cleanup; } @@ -801,7 +824,7 @@ int VirtualMachine::parse_requirements(string& error_str) if ( reqs == 0 ) { - error_str = "Wrong format for REQUIREMENTS attribute."; + error_str = "Wrong format for SCHED_REQUIREMENTS attribute."; goto error_cleanup; } @@ -811,8 +834,8 @@ int VirtualMachine::parse_requirements(string& error_str) { SingleAttribute * reqs_parsed; - reqs_parsed = new SingleAttribute("REQUIREMENTS",parsed); - obj_template->set(reqs_parsed); + reqs_parsed = new SingleAttribute("SCHED_REQUIREMENTS",parsed); + user_obj_template->set(reqs_parsed); } /* --- Delete old requirements attributes --- */ @@ -974,15 +997,15 @@ int VirtualMachine::automatic_requirements(string& error_str) oss.str(""); oss << "CLUSTER_ID = " << cluster_id; - user_obj_template->get("REQUIREMENTS", requirements); - user_obj_template->erase("REQUIREMENTS"); + user_obj_template->get("SCHED_REQUIREMENTS", requirements); + user_obj_template->erase("SCHED_REQUIREMENTS"); if ( !requirements.empty() ) { oss << " & ( " << requirements << " )"; } - obj_template->add("REQUIREMENTS", oss.str()); + user_obj_template->add("SCHED_REQUIREMENTS", oss.str()); } return 0; From 59f4331b05102709b5814eb7bb6f7fbe24a0501c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 6 Feb 2013 17:27:59 +0100 Subject: [PATCH 07/21] Feature #1483 #1556: onedb migrator moves rank, requirements to sched_* --- src/onedb/3.8.1_to_3.9.80.rb | 67 +++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) 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 fec8fa19f4..5e160eb340 100644 --- a/src/onedb/3.8.1_to_3.9.80.rb +++ b/src/onedb/3.8.1_to_3.9.80.rb @@ -402,6 +402,10 @@ module Migrator ######################################################################## # Feature #1556: New elem USER_TEMPLATE + # + # Feature #1483: Move scheduling attributes + # /VM/TEMPLATE/REQUIREMENTS -> USER_TEMPLATE/SCHED_REQUIREMENTS + # /VM/TEMPLATE/RANK -> USER_TEMPLATE/SCHED_RANK ######################################################################## @db.run "ALTER TABLE vm_pool RENAME TO old_vm_pool;" @@ -410,7 +414,21 @@ module Migrator @db.fetch("SELECT * FROM old_vm_pool") do |row| doc = Document.new(row[:body]) - doc.root.add_element("USER_TEMPLATE") + user_template = doc.root.add_element("USER_TEMPLATE") + + doc.root.each_element("TEMPLATE") do |e| + elem = e.delete_element("REQUIREMENTS") + + if !elem.nil? + user_template.add_element("SCHED_REQUIREMENTS").text = elem.text + end + + elem = e.delete_element("RANK") + + if !elem.nil? + user_template.add_element("SCHED_RANK").text = elem.text + end + end @db[:vm_pool].insert( :oid => row[:oid], @@ -429,6 +447,53 @@ module Migrator @db.run "DROP TABLE old_vm_pool;" + ######################################################################## + # Feature #1483: Move scheduling attributes + # /VMTEMPLATE/TEMPLATE/REQUIREMENTS -> /VMTEMPLATE/TEMPLATE/SCHED_REQUIREMENTS + # /VMTEMPLATE/TEMPLATE/RANK -> /VMTEMPLATE/TEMPLATE/SCHED_RANK + ######################################################################## + + @db.run "ALTER TABLE template_pool RENAME TO old_template_pool;" + @db.run "CREATE TABLE template_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER);" + + @db.fetch("SELECT * FROM old_template_pool") do |row| + + doc = Document.new(row[:body]) + + template = nil + + doc.root.each_element("TEMPLATE") do |e| + template = e + end + + doc.root.each_element("TEMPLATE") do |e| + elem = e.delete_element("REQUIREMENTS") + + if !elem.nil? + template.add_element("SCHED_REQUIREMENTS").text = elem.text + end + + elem = e.delete_element("RANK") + + if !elem.nil? + template.add_element("SCHED_RANK").text = elem.text + end + end + + @db[:template_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => doc.root.to_s, + :uid => row[:uid], + :gid => row[:gid], + :owner_u => row[:owner_u], + :group_u => row[:group_u], + :other_u => row[:other_u]) + end + + @db.run "DROP TABLE old_template_pool;" + + ######################################################################## # # Banner for the new /var/lib/one/vms directory From 2391713df04d494fb4cce96a73ae399c1b608fd1 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 7 Feb 2013 00:14:25 +0100 Subject: [PATCH 08/21] feature #1483: Add a separated action VM pool --- include/Util.h | 13 +-- src/scheduler/include/Scheduler.h | 19 ++-- src/scheduler/include/VirtualMachinePoolXML.h | 72 +++++++++----- src/scheduler/include/VirtualMachineXML.h | 31 +++++- .../src/pool/VirtualMachinePoolXML.cc | 94 +++++++------------ src/scheduler/src/pool/VirtualMachineXML.cc | 50 +++++++--- src/scheduler/src/sched/Scheduler.cc | 84 ++++++----------- 7 files changed, 190 insertions(+), 173 deletions(-) diff --git a/include/Util.h b/include/Util.h index 63a8df747a..336a01b9a0 100644 --- a/include/Util.h +++ b/include/Util.h @@ -19,23 +19,21 @@ #include -using namespace std; - namespace one_util { - string& toupper(string& st) + inline string& toupper(string& st) { transform(st.begin(),st.end(),st.begin(),(int(*)(int))std::toupper); return st; }; - string& tolower(string& st) + inline string& tolower(string& st) { transform(st.begin(),st.end(),st.begin(),(int(*)(int))std::tolower); return st; }; - string log_time(time_t the_time) + inline string log_time(time_t the_time) { char time_str[26]; @@ -50,11 +48,10 @@ namespace one_util return string(time_str); }; - string log_time() + inline string log_time() { return log_time( time(0) ); }; -} - +}; #endif /* UTIL_H_ */ diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 13925a13fa..0059aad843 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -50,6 +50,7 @@ protected: hpool(0), clpool(0), vmpool(0), + vmapool(0), acls(0), timer(0), url(""), @@ -79,6 +80,11 @@ protected: delete vmpool; } + if ( vmapool != 0) + { + delete vmapool; + } + if ( acls != 0) { delete acls; @@ -94,11 +100,13 @@ protected: // Pools // --------------------------------------------------------------- - HostPoolXML * hpool; - ClusterPoolXML * clpool; - VirtualMachinePoolXML * vmpool; + HostPoolXML * hpool; + ClusterPoolXML * clpool; - AclXML * acls; + VirtualMachinePoolXML * vmpool; + VirtualMachineActionsPoolXML* vmapool; + + AclXML * acls; // --------------------------------------------------------------- // Scheduler Policies @@ -134,7 +142,7 @@ protected: virtual int set_up_pools(); - virtual int scheduled_actions(); + virtual int do_scheduled_actions(); private: Scheduler(Scheduler const&){}; @@ -143,7 +151,6 @@ private: friend void * scheduler_action_loop(void *arg); - // --------------------------------------------------------------- // Scheduling Policies // --------------------------------------------------------------- diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index 3aa091847b..257f5b3dc2 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -32,7 +32,7 @@ public: bool _live_resched): PoolXML(client, machines_limit), live_resched(_live_resched){}; - ~VirtualMachinePoolXML(){}; + virtual ~VirtualMachinePoolXML(){}; /** * Retrieves the pending and rescheduling VMs @@ -43,15 +43,6 @@ public: */ int set_up(); - /** - * Retrieves the VMs with scheduled actions - * - * @return 0 on success - * -1 on error - * -2 if no VMs need to be scheduled - */ - int set_up_actions(); - /** * Gets an object from the pool * @param oid the object unique identifier @@ -93,6 +84,46 @@ public: return update(vm->get_oid(), vm->get_template(xml)); }; +protected: + + int get_suitable_nodes(vector& content) + { + return get_nodes("/VM_POOL/VM[STATE=1 or (LCM_STATE=3 and RESCHED=1)]", + content); + } + + virtual void add_object(xmlNodePtr node); + + virtual int load_info(xmlrpc_c::value &result); + + /** + * Do live migrations to resched VMs + */ + bool live_resched; +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +class VirtualMachineActionsPoolXML : public VirtualMachinePoolXML +{ +public: + + VirtualMachineActionsPoolXML(Client* client, + unsigned int machines_limit): + VirtualMachinePoolXML(client, machines_limit, false){}; + + virtual ~VirtualMachineActionsPoolXML(){}; + + /** + * Retrieves the VMs with pending actions + * + * @return 0 on success + * -1 on error + * -2 if no VMs with pending actions + */ + int set_up(); + /** * Calls one.vm.action * @@ -106,22 +137,15 @@ public: protected: - int get_suitable_nodes(vector& content); + int get_suitable_nodes(vector& content) + { + ostringstream oss; - virtual void add_object(xmlNodePtr node); + oss << "/VM_POOL/VM/USER_TEMPLATE/SCHED_ACTION[TIME < " << time(0) + << " and not(DONE > 0)]/../.."; - virtual int load_info(xmlrpc_c::value &result); - - /** - * Do live migrations to resched VMs - */ - bool live_resched; - - /** - * True to retrieve pending/resched VMs, false to get VMs with scheduled - * actions - */ - bool retrieve_pending; + return get_nodes(oss.str().c_str(), content); + } }; #endif /* VM_POOL_XML_H_ */ diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index 47fb24d86e..75fa29950a 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -125,14 +125,35 @@ public: } /** - * Returns a the VM Template + * Returns the scheduled actions of the VM * - * @return A pointer to the VM Template (not to a copy) + * @param attributes to hold the VM actions */ - VirtualMachineTemplate* get_template() + void get_actions(vector& attributes) const { - return vm_template; - }; + attributes.clear(); + + vm_template->remove("SCHED_ACTION", attributes); + } + + /** + * Sets an attribute in the VM Template, it must be allocated in the heap + * + * @param attributes to hold the VM actions + */ + void set_attribute(Attribute* att) + { + return vm_template->set(att); + } + + /** + * Checks the action to be performed and returns the corresponding XML-RPC + * method name. + * @param action_st, the action to be performed. The XML-RPC name is + * returned here + * @return 0 on success. + */ + static int parse_action_name(string& action_st); /** * Function to write a Virtual Machine in an output stream diff --git a/src/scheduler/src/pool/VirtualMachinePoolXML.cc b/src/scheduler/src/pool/VirtualMachinePoolXML.cc index 0d6080d649..ec9ff9eb63 100644 --- a/src/scheduler/src/pool/VirtualMachinePoolXML.cc +++ b/src/scheduler/src/pool/VirtualMachinePoolXML.cc @@ -22,8 +22,6 @@ int VirtualMachinePoolXML::set_up() ostringstream oss; int rc; - retrieve_pending = true; - rc = PoolXML::set_up(); if ( rc == 0 ) @@ -52,63 +50,6 @@ int VirtualMachinePoolXML::set_up() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachinePoolXML::set_up_actions() -{ - ostringstream oss; - int rc; - - retrieve_pending = false; - - rc = PoolXML::set_up(); - - if ( rc == 0 ) - { - if (objects.empty()) - { - return -2; - } - - oss.str(""); - oss << "VMs with scheduled actions:" << endl; - - map::iterator it; - - for (it=objects.begin();it!=objects.end();it++) - { - oss << " " << it->first; - } - - NebulaLog::log("VM",Log::DEBUG,oss); - } - - return rc; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -int VirtualMachinePoolXML::get_suitable_nodes(vector& content) -{ - if (retrieve_pending) - { - return get_nodes( - "/VM_POOL/VM[STATE=1 or (LCM_STATE=3 and RESCHED=1)]", - content); - } - - ostringstream oss; - - oss << "/VM_POOL/VM/USER_TEMPLATE/SCHED_ACTION[TIME < " << time(0) - << " and not(DONE > 0)]/../.."; - - return get_nodes( - oss.str().c_str(), - content); -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - void VirtualMachinePoolXML::add_object(xmlNodePtr node) { if ( node == 0 || node->children == 0 || node->children->next==0 ) @@ -268,11 +209,42 @@ int VirtualMachinePoolXML::update(int vid, const string &st) const return 0; } - /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachinePoolXML::action( +int VirtualMachineActionsPoolXML::set_up() +{ + ostringstream oss; + int rc; + + rc = PoolXML::set_up(); + + if ( rc == 0 ) + { + if (objects.empty()) + { + return -2; + } + + oss.str(""); + oss << "VMs with scheduled actions:" << endl; + + map::iterator it; + + for (it=objects.begin();it!=objects.end();it++) + { + oss << " " << it->first; + } + + NebulaLog::log("VM",Log::DEBUG,oss); + } + + return rc; +} +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachineActionsPoolXML::action( int vid, const string& action, string& error_msg) const diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index 91195a2ad0..142d4b9020 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -17,6 +17,7 @@ #include #include "VirtualMachineXML.h" +#include "Util.h" void VirtualMachineXML::init_attributes() { @@ -265,21 +266,42 @@ void VirtualMachineXML::log(const string &st) { return; } + ostringstream oss; - char str[26]; - time_t the_time = time(NULL); - - ostringstream oss; - -#ifdef SOLARIS - ctime_r(&(the_time),str,sizeof(char)*26); -#else - ctime_r(&(the_time),str); -#endif - - str[24] = '\0'; // Get rid of final enter character - - oss << str << " : " << st; + oss << one_util::log_time(time(0)) << " : " << st; vm_template->replace("SCHED_MESSAGE", oss.str()); } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachineXML::parse_action_name(string& action_st) +{ + one_util::tolower(action_st); + + // onevm delete command uses the xml-rpc finalize action + if (action_st == "delete") + { + action_st = "finalize"; + } + + if ( action_st != "shutdown" + && action_st != "hold" + && action_st != "release" + && action_st != "stop" + && action_st != "cancel" + && action_st != "suspend" + && action_st != "resume" + && action_st != "restart" + && action_st != "resubmit" + && action_st != "reboot" + && action_st != "reset" + && action_st != "poweroff" + && action_st != "finalize") + { + return -1; + } + + return 0; +}; diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index e1b7dd3a8a..2d2133b355 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -180,6 +180,8 @@ void Scheduler::start() vmpool = new VirtualMachinePoolXML(client, machines_limit, (live_rescheds == 1)); + vmapool= new VirtualMachineActionsPoolXML(client, machines_limit); + acls = new AclXML(client); // ----------------------------------------------------------- @@ -624,20 +626,11 @@ void Scheduler::dispatch() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int Scheduler::scheduled_actions() +int Scheduler::do_scheduled_actions() { - int rc = vmpool->set_up_actions(); - - if ( rc != 0 ) - { - return rc; - } - VirtualMachineXML* vm; - VirtualMachineTemplate* vm_template; - - vector v_st; + const map vms = vmapool->get_objects(); map::const_iterator vm_it; vector attributes; @@ -645,28 +638,23 @@ int Scheduler::scheduled_actions() VectorAttribute* vatt; - time_t the_time = time(0); + int action_time; + int done_time; + int has_time; + int has_done; - int action_time, done_time, has_time, has_done; string action_st, error_msg; - ostringstream oss; - ostringstream oss_aux; - + time_t the_time = time(0); string time_str = one_util::log_time(the_time); - const map vms = vmpool->get_objects(); - for (vm_it=vms.begin(); vm_it != vms.end(); vm_it++) { vm = static_cast(vm_it->second); - vm_template = vm->get_template(); - attributes.clear(); - vm_template->remove("SCHED_ACTION", attributes); + vm->get_actions(attributes); // TODO: Sort actions by TIME - for (it=attributes.begin(); it != attributes.end(); it++) { vatt = dynamic_cast(*it); @@ -676,46 +664,26 @@ int Scheduler::scheduled_actions() continue; } - has_time = vatt->vector_value("TIME", action_time); - has_done = vatt->vector_value("DONE", done_time); - + has_time = vatt->vector_value("TIME", action_time); + has_done = vatt->vector_value("DONE", done_time); action_st = vatt->vector_value("ACTION"); - one_util::tolower(action_st); - if (has_time == 0 && has_done == -1 && action_time < the_time) { - oss.str(""); + ostringstream oss; - // onevm delete command uses the xml-rpc finalize action - if (action_st == "delete") - { - action_st = "finalize"; - } + int rc = VirtualMachineXML::parse_action_name(action_st); oss << "Executing action '" << action_st << "' for VM " << vm->get_oid() << " : "; - if ( action_st != "shutdown" - && action_st != "hold" - && action_st != "release" - && action_st != "stop" - && action_st != "cancel" - && action_st != "suspend" - && action_st != "resume" - && action_st != "restart" - && action_st != "resubmit" - && action_st != "reboot" - && action_st != "reset" - && action_st != "poweroff" - && action_st != "finalize") + if ( rc != 0 ) { error_msg = "This action is not supported."; - rc = -1; } else { - rc = vmpool->action(vm->get_oid(), action_st, error_msg); + rc = vmapool->action(vm->get_oid(), action_st, error_msg); } if (rc == 0) @@ -727,7 +695,8 @@ int Scheduler::scheduled_actions() } else { - oss_aux.str(""); + ostringstream oss_aux; + oss_aux << time_str << " : " << error_msg; vatt->replace("MESSAGE", oss_aux.str()); @@ -735,13 +704,13 @@ int Scheduler::scheduled_actions() oss << "Failure. " << error_msg; } - NebulaLog::log("VM",Log::INFO,oss); + NebulaLog::log("VM", Log::INFO, oss); + + vm->set_attribute(vatt); + + vmpool->update(vm); } - - vm_template->set(vatt); } - - vmpool->update(vm); } return 0; @@ -756,7 +725,12 @@ void Scheduler::do_action(const string &name, void *args) if (name == ACTION_TIMER) { - scheduled_actions(); + rc = vmapool->set_up(); + + if ( rc == 0 ) + { + do_scheduled_actions(); + } rc = set_up_pools(); From e0f6f13e9ecf84ec143b0e956a56f34e6ad446ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 7 Feb 2013 17:15:46 +0100 Subject: [PATCH 09/21] Feature #1483: Minor fixes --- src/cli/one_helper/onevm_helper.rb | 2 +- src/scheduler/include/VirtualMachineXML.h | 2 +- src/scheduler/src/pool/VirtualMachineXML.cc | 4 ++-- src/scheduler/src/sched/Scheduler.cc | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 5ad3cd9481..507a9fca03 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -261,7 +261,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper column :"MESSAGE", "", :left, :donottruncate, :size=>43 do |d| d["MESSAGE"] if !d.nil? end - end.show(vm.to_hash['VM']['USER_TEMPLATE']['SCHED_ACTION'], {}) + end.show([vm.to_hash['VM']['USER_TEMPLATE']['SCHED_ACTION']].flatten, {}) puts end diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index 75fa29950a..29e714e085 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -125,7 +125,7 @@ public: } /** - * Returns the scheduled actions of the VM + * Removes (but does not delete) the scheduled actions of the VM * * @param attributes to hold the VM actions */ diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index 142d4b9020..08c45314b0 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -268,7 +268,7 @@ void VirtualMachineXML::log(const string &st) } ostringstream oss; - oss << one_util::log_time(time(0)) << " : " << st; + oss << one_util::log_time() << " : " << st; vm_template->replace("SCHED_MESSAGE", oss.str()); } @@ -278,7 +278,7 @@ void VirtualMachineXML::log(const string &st) int VirtualMachineXML::parse_action_name(string& action_st) { - one_util::tolower(action_st); + one_util::tolower(action_st); // onevm delete command uses the xml-rpc finalize action if (action_st == "delete") diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 2d2133b355..7fed182466 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -661,6 +661,8 @@ int Scheduler::do_scheduled_actions() if (vatt == 0) { + delete *it; + continue; } From 650d62b6fe37c4c9244a920ea32484ea143a5135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 7 Feb 2013 18:34:46 +0100 Subject: [PATCH 10/21] Feature #1483: Fix automatic requirements --- src/vm/VirtualMachine.cc | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 890c7088d5..3ef427b906 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -896,8 +896,6 @@ int VirtualMachine::automatic_requirements(string& error_str) vector v_attributes; VectorAttribute * vatt; - vector::iterator it; - ostringstream oss; string requirements; string cluster_id = ""; @@ -907,12 +905,7 @@ int VirtualMachine::automatic_requirements(string& error_str) // Get cluster id from all DISK vector attributes (IMAGE Datastore) - num_vatts = user_obj_template->remove("DISK",v_attributes); - - for (it=v_attributes.begin(); it != v_attributes.end(); it++) - { - obj_template->set(*it); - } + num_vatts = obj_template->get("DISK",v_attributes); for(int i=0; iremove("OS",v_attributes); - - for (it=v_attributes.begin(); it != v_attributes.end(); it++) - { - obj_template->set(*it); - } + num_vatts = obj_template->get("OS",v_attributes); if ( num_vatts > 0 ) { @@ -967,12 +955,7 @@ int VirtualMachine::automatic_requirements(string& error_str) // Get cluster id from all NIC vector attributes v_attributes.clear(); - num_vatts = user_obj_template->remove("NIC",v_attributes); - - for (it=v_attributes.begin(); it != v_attributes.end(); it++) - { - obj_template->set(*it); - } + num_vatts = obj_template->get("NIC",v_attributes); for(int i=0; i Date: Fri, 8 Feb 2013 12:22:21 +0100 Subject: [PATCH 11/21] Feature #1483: Fix context parsing --- src/vm/VirtualMachine.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 3ef427b906..435b11d1ff 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -596,7 +596,7 @@ int VirtualMachine::parse_context(string& error_str) vector img_ids; - num = user_obj_template->remove("CONTEXT", array_context); + num = obj_template->remove("CONTEXT", array_context); if ( num == 0 ) { From dc075e0955be8bc1ddd534f92b730763dfb3c949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 8 Feb 2013 12:46:35 +0100 Subject: [PATCH 12/21] Feature #1483 #1556: Separate requirements in two attributes AUTOMATIC_REQUIREMNTS is set by the core, cannot be edited. SCHED_REQUIREMENTS can be set and edited by the users. --- src/scheduler/src/pool/VirtualMachineXML.cc | 20 +++++++++++++++++--- src/vm/VirtualMachine.cc | 10 +--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index 08c45314b0..3ef22c174c 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -73,15 +73,29 @@ void VirtualMachineXML::init_attributes() } } - result = ((*this)["/VM/USER_TEMPLATE/SCHED_REQUIREMENTS"]); + result = ((*this)["/VM/TEMPLATE/AUTOMATIC_REQUIREMENTS"]); if (result.size() > 0) { requirements = result[0]; } - else + + result = ((*this)["/VM/USER_TEMPLATE/SCHED_REQUIREMENTS"]); + + if (result.size() > 0) { - requirements = ""; + if ( !requirements.empty() ) + { + ostringstream oss; + + oss << requirements << " & ( " << result[0] << " )"; + + requirements = oss.str(); + } + else + { + requirements = result[0]; + } } result = ((*this)["/VM/HISTORY_RECORDS/HISTORY/HID"]); diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 435b11d1ff..54c6f8a5cc 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -980,15 +980,7 @@ int VirtualMachine::automatic_requirements(string& error_str) oss.str(""); oss << "CLUSTER_ID = " << cluster_id; - user_obj_template->get("SCHED_REQUIREMENTS", requirements); - user_obj_template->erase("SCHED_REQUIREMENTS"); - - if ( !requirements.empty() ) - { - oss << " & ( " << requirements << " )"; - } - - user_obj_template->add("SCHED_REQUIREMENTS", oss.str()); + obj_template->add("AUTOMATIC_REQUIREMENTS", oss.str()); } return 0; From 90399665ef0a8172e1370ae5cdea92bba09403e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 8 Feb 2013 14:37:31 +0100 Subject: [PATCH 13/21] Feature #1483: Make --schedule option verbose by default --- src/cli/one_helper/onevm_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 507a9fca03..153a6c207a 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -151,6 +151,9 @@ class OneVMHelper < OpenNebulaHelper::OneHelper def schedule_actions(ids,options,action) + # Verbose by default + options[:verbose] = true + perform_actions( ids, options, "#{action} scheduled at #{options[:schedule]}") do |vm| From 36473f11fd0edf5dfdcb9345334d0e3327a24d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 8 Feb 2013 14:59:29 +0100 Subject: [PATCH 14/21] Feature #1483: Add an ID to each SCHED_ACTION to make them easier to edit manually with onevm update --- src/cli/one_helper/onevm_helper.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 153a6c207a..aaa53b8435 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -165,9 +165,17 @@ class OneVMHelper < OpenNebulaHelper::OneHelper exit -1 end + ids = vm.retrieve_elements('USER_TEMPLATE/SCHED_ACTION/ID') + + id = 0 + if (!ids.nil? && !ids.empty?) + ids.map! {|e| e.to_i } + id = ids.max + 1 + end + tmp_str = vm.user_template_str - tmp_str << "\nSCHED_ACTION = [ACTION = #{action}, TIME = #{options[:schedule].to_i}]" + tmp_str << "\nSCHED_ACTION = [ID = #{id}, ACTION = #{action}, TIME = #{options[:schedule].to_i}]" vm.update(tmp_str) end @@ -249,6 +257,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper CLIHelper::ShowTable.new(nil, self) do + column :"ID", "", :size=>2 do |d| + d["ID"] if !d.nil? + end + column :"ACTION", "", :left, :size=>10 do |d| d["ACTION"] if !d.nil? end @@ -261,7 +273,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper OpenNebulaHelper.time_to_str(d["DONE"], false) if !d.nil? end - column :"MESSAGE", "", :left, :donottruncate, :size=>43 do |d| + column :"MESSAGE", "", :left, :donottruncate, :size=>40 do |d| d["MESSAGE"] if !d.nil? end end.show([vm.to_hash['VM']['USER_TEMPLATE']['SCHED_ACTION']].flatten, {}) From f9c59f0cfadff7b6e01a8a01159f8663eeca4cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 8 Feb 2013 16:33:56 +0100 Subject: [PATCH 15/21] Feature #1483: Fix sched_actions. Last change was deleting future actions --- src/scheduler/src/sched/Scheduler.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 7fed182466..812b7c68cf 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -707,12 +707,12 @@ int Scheduler::do_scheduled_actions() } NebulaLog::log("VM", Log::INFO, oss); - - vm->set_attribute(vatt); - - vmpool->update(vm); } + + vm->set_attribute(vatt); } + + vmpool->update(vm); } return 0; From 617b3c12e814c70901118932ed8b4e49c7cdcdcf Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 8 Feb 2013 20:14:41 +0100 Subject: [PATCH 16/21] feature-1483: SCHED attributes can be modified by default --- share/etc/oned.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 548408c43d..18dcb1cca9 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -492,9 +492,9 @@ VM_RESTRICTED_ATTR = "CONTEXT/FILES" VM_RESTRICTED_ATTR = "NIC/MAC" VM_RESTRICTED_ATTR = "NIC/VLAN_ID" -VM_RESTRICTED_ATTR = "RANK" -VM_RESTRICTED_ATTR = "SCHED_RANK" -VM_RESTRICTED_ATTR = "REQUIREMENTS" -VM_RESTRICTED_ATTR = "SCHED_REQUIREMENTS" +#VM_RESTRICTED_ATTR = "RANK" +#VM_RESTRICTED_ATTR = "SCHED_RANK" +#VM_RESTRICTED_ATTR = "REQUIREMENTS" +#VM_RESTRICTED_ATTR = "SCHED_REQUIREMENTS" IMAGE_RESTRICTED_ATTR = "SOURCE" From abb62dddebe80980cbbda315537e186b83c0866a Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 8 Feb 2013 20:24:27 +0100 Subject: [PATCH 17/21] feature #1483: Prevents deleting of NULL pointer --- src/scheduler/src/sched/Scheduler.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 812b7c68cf..cd9855892a 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -661,7 +661,10 @@ int Scheduler::do_scheduled_actions() if (vatt == 0) { - delete *it; + if ( *it != 0 ) + { + delete *it; + } continue; } From f4434f00adc7fc187f2ccd92478fb84ecb03017a Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 8 Feb 2013 21:03:47 +0100 Subject: [PATCH 18/21] feature #1483: Simplify REQUIREMENTS compatibility check --- src/vm/VirtualMachine.cc | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 54c6f8a5cc..72f7556379 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -789,25 +789,11 @@ int VirtualMachine::parse_requirements(string& error_str) if ( num == 0 ) // Compatibility with old REQUIREMENTS attribute { - vector array_reqs_aux; - vector::iterator it; - - num = user_obj_template->remove("REQUIREMENTS", array_reqs_aux); - - // Rename att to SCHED_REQUIREMENTS - for (it = array_reqs_aux.begin(); it != array_reqs_aux.end(); it++) - { - reqs = dynamic_cast(*it); - - if (reqs != 0) - { - array_reqs.push_back( new SingleAttribute( - "SCHED_REQUIREMENTS", - reqs->value()) ); - } - - delete *it; - } + num = user_obj_template->remove("REQUIREMENTS", array_reqs); + } + else + { + user_obj_template->erase("REQUIREMENTS"); } if ( num == 0 ) @@ -838,15 +824,9 @@ int VirtualMachine::parse_requirements(string& error_str) user_obj_template->set(reqs_parsed); } - /* --- Delete old requirements attributes --- */ + /* --- Delete old requirements attribute --- */ - for (int i = 0; i < num ; i++) - { - if (array_reqs[i] != 0) - { - delete array_reqs[i]; - } - } + delete array_reqs[0]; return rc; From 4e41c91022abc23fac75f01de9f3dbfa673e5b85 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 8 Feb 2013 21:50:40 +0100 Subject: [PATCH 19/21] feature #1483: Moved implementation of util functions to a cc file --- include/Util.h | 32 ++++---------------------- src/common/SConstruct | 3 ++- src/common/Util.cc | 53 +++++++++++++++++++++++++++++++++++++++++++ src/nebula/SConstruct | 2 +- 4 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 src/common/Util.cc diff --git a/include/Util.h b/include/Util.h index 336a01b9a0..be18222f1a 100644 --- a/include/Util.h +++ b/include/Util.h @@ -21,37 +21,13 @@ namespace one_util { - inline string& toupper(string& st) - { - transform(st.begin(),st.end(),st.begin(),(int(*)(int))std::toupper); - return st; - }; + std::string& toupper(std::string& st); - inline string& tolower(string& st) - { - transform(st.begin(),st.end(),st.begin(),(int(*)(int))std::tolower); - return st; - }; + std::string& tolower(std::string& st); - inline string log_time(time_t the_time) - { - char time_str[26]; + std::string log_time(time_t the_time); -#ifdef SOLARIS - ctime_r(&(the_time),time_str,sizeof(char)*26); -#else - ctime_r(&(the_time),time_str); -#endif - - time_str[24] = '\0'; // Get rid of final enter character - - return string(time_str); - }; - - inline string log_time() - { - return log_time( time(0) ); - }; + std::string log_time(); }; #endif /* UTIL_H_ */ diff --git a/src/common/SConstruct b/src/common/SConstruct index 3b24d2edac..5f3867988a 100644 --- a/src/common/SConstruct +++ b/src/common/SConstruct @@ -25,7 +25,8 @@ source_files=[ 'ActionManager.cc', 'Attribute.cc', 'mem_collector.c', - 'SSLTools.cc' + 'SSLTools.cc', + 'Util.cc' ] # Build library diff --git a/src/common/Util.cc b/src/common/Util.cc new file mode 100644 index 0000000000..6a73eb4de5 --- /dev/null +++ b/src/common/Util.cc @@ -0,0 +1,53 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +#include "Util.h" +#include + +using namespace std; + +string& one_util::toupper(string& st) +{ + transform(st.begin(),st.end(),st.begin(),(int(*)(int))toupper); + return st; +}; + +string& one_util::tolower(string& st) +{ + transform(st.begin(),st.end(),st.begin(),(int(*)(int))tolower); + return st; +}; + +string one_util::log_time(time_t the_time) +{ + char time_str[26]; + +#ifdef SOLARIS + ctime_r(&(the_time),time_str,sizeof(char)*26); +#else + ctime_r(&(the_time),time_str); +#endif + + time_str[24] = '\0'; // Get rid of final enter character + + return string(time_str); +}; + +string one_util::log_time() +{ + return log_time( time(0) ); +}; + diff --git a/src/nebula/SConstruct b/src/nebula/SConstruct index aef1674a7d..7d389a5159 100644 --- a/src/nebula/SConstruct +++ b/src/nebula/SConstruct @@ -25,7 +25,7 @@ lib_name='nebula_core' source_files=[ 'SystemDB.cc', 'Nebula.cc', - 'NebulaTemplate.cc', + 'NebulaTemplate.cc' ] # Build library From 2e72c6c68b751c08fab997bcd47f9271b0375ebe Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 8 Feb 2013 21:51:30 +0100 Subject: [PATCH 20/21] feature #1483: Inline hints for simple util functions --- include/Util.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/Util.h b/include/Util.h index be18222f1a..a8876ba16d 100644 --- a/include/Util.h +++ b/include/Util.h @@ -21,13 +21,13 @@ namespace one_util { - std::string& toupper(std::string& st); + inline std::string& toupper(std::string& st); - std::string& tolower(std::string& st); + inline std::string& tolower(std::string& st); std::string log_time(time_t the_time); - std::string log_time(); + inline std::string log_time(); }; #endif /* UTIL_H_ */ From d920864c6a45da83ae3ebac2ca33de76da376c02 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 8 Feb 2013 21:58:34 +0100 Subject: [PATCH 21/21] Revert "feature #1483: Inline hints for simple util functions" This reverts commit 2e72c6c68b751c08fab997bcd47f9271b0375ebe. --- include/Util.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/Util.h b/include/Util.h index a8876ba16d..be18222f1a 100644 --- a/include/Util.h +++ b/include/Util.h @@ -21,13 +21,13 @@ namespace one_util { - inline std::string& toupper(std::string& st); + std::string& toupper(std::string& st); - inline std::string& tolower(std::string& st); + std::string& tolower(std::string& st); std::string log_time(time_t the_time); - inline std::string log_time(); + std::string log_time(); }; #endif /* UTIL_H_ */