diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index cda8ae330b..1aa4e94884 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -33,6 +33,7 @@ class VirtualMachineDriver < OpenNebulaDriver :deploy => "DEPLOY", :shutdown => "SHUTDOWN", :reboot => "REBOOT", + :reset => "RESET", :cancel => "CANCEL", :save => "SAVE", :restore => "RESTORE", @@ -75,14 +76,15 @@ class VirtualMachineDriver < OpenNebulaDriver @hosts = Array.new - register_action(ACTION[:deploy].to_sym, method("deploy")) - register_action(ACTION[:shutdown].to_sym, method("shutdown")) - register_action(ACTION[:reboot].to_sym, method("reboot")) - register_action(ACTION[:cancel].to_sym, method("cancel")) - register_action(ACTION[:save].to_sym, method("save")) - register_action(ACTION[:restore].to_sym, method("restore")) - register_action(ACTION[:migrate].to_sym, method("migrate")) - register_action(ACTION[:poll].to_sym, method("poll")) + register_action(ACTION[:deploy].to_sym, method("deploy")) + register_action(ACTION[:shutdown].to_sym, method("shutdown")) + register_action(ACTION[:reboot].to_sym, method("reboot")) + register_action(ACTION[:reset].to_sym, method("reset")) + register_action(ACTION[:cancel].to_sym, method("cancel")) + register_action(ACTION[:save].to_sym, method("save")) + register_action(ACTION[:restore].to_sym, method("restore")) + register_action(ACTION[:migrate].to_sym, method("migrate")) + register_action(ACTION[:poll].to_sym, method("poll")) end # Decodes the encoded XML driver message received from the core @@ -122,6 +124,11 @@ class VirtualMachineDriver < OpenNebulaDriver send_message(ACTION[:reboot],RESULT[:failure],id,error) end + def reset(id, drv_message) + error = "Action not implemented by driver #{self.class}" + send_message(ACTION[:reset],RESULT[:failure],id,error) + end + def cancel(id, drv_message) error = "Action not implemented by driver #{self.class}" send_message(ACTION[:cancel],RESULT[:failure],id,error) diff --git a/src/vmm_mad/dummy/one_vmm_dummy.rb b/src/vmm_mad/dummy/one_vmm_dummy.rb index 6a6d4d7d3d..f504df946b 100755 --- a/src/vmm_mad/dummy/one_vmm_dummy.rb +++ b/src/vmm_mad/dummy/one_vmm_dummy.rb @@ -56,6 +56,10 @@ class DummyDriver < VirtualMachineDriver send_message(ACTION[:reboot],RESULT[:success],id) end + def reset(id, drv_message) + send_message(ACTION[:reset],RESULT[:success],id) + end + def cancel(id, drv_message) send_message(ACTION[:cancel],RESULT[:success],id) end diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index bd53cfe49e..ebb71b1061 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -470,6 +470,17 @@ class ExecDriver < VirtualMachineDriver do_action("#{deploy_id} #{host}", id, host, ACTION[:reboot]) end + + # + # RESET action, resets a running VM + # + def reset(id, drv_message) + data = decode(drv_message) + host = data.elements['HOST'].text + deploy_id = data.elements['DEPLOY_ID'].text + + do_action("#{deploy_id} #{host}", id, host, ACTION[:reset]) + end end ################################################################################ diff --git a/src/vmm_mad/remotes/kvm/reset b/src/vmm_mad/remotes/kvm/reset new file mode 100755 index 0000000000..54054cbe86 --- /dev/null +++ b/src/vmm_mad/remotes/kvm/reset @@ -0,0 +1,27 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) # +# # +# 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. # +#--------------------------------------------------------------------------- # + +source $(dirname $0)/kvmrc +source $(dirname $0)/../../scripts_common.sh + +deploy_id=$1 + +exec_and_log "virsh --connect $LIBVIRT_URI reset $deploy_id" \ + "Could not reset domain $deploy_id" + +exit 0 diff --git a/src/vmm_mad/remotes/vmware/reset b/src/vmm_mad/remotes/vmware/reset new file mode 100755 index 0000000000..d834b11b0e --- /dev/null +++ b/src/vmm_mad/remotes/vmware/reset @@ -0,0 +1,37 @@ +#!/usr/bin/env ruby + +# ---------------------------------------------------------------------------- # +# Copyright 2010-2012, C12G Labs S.L # +# # +# 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. # +# ---------------------------------------------------------------------------- # + +ONE_LOCATION=ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION) + +if !ONE_LOCATION + RUBY_LIB_LOCATION="/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION) +else + RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby" if !defined?(RUBY_LIB_LOCATION) +end + +$: << RUBY_LIB_LOCATION +$: << File.dirname(__FILE__) + +require 'vmware_driver' + +deploy_id = ARGV[0] +host = ARGV[1] + +vmware_drv = VMwareDriver.new(host) + +vmware_drv.reset(deploy_id) diff --git a/src/vmm_mad/remotes/vmware/vmware_driver.rb b/src/vmm_mad/remotes/vmware/vmware_driver.rb index 427820ef8b..3b0bb1ca89 100644 --- a/src/vmm_mad/remotes/vmware/vmware_driver.rb +++ b/src/vmm_mad/remotes/vmware/vmware_driver.rb @@ -112,6 +112,18 @@ class VMwareDriver OpenNebula.log_debug("Domain #{deploy_id} successfully rebooted.") end + + # ------------------------------------------------------------------------ # + # Reset a running VM # + # ------------------------------------------------------------------------ # + def reset(deploy_id) + rc, info = do_action("virsh -c #{@uri} reset #{deploy_id}") + + exit info if rc == false + + OpenNebula.log_debug("Domain #{deploy_id} successfully reseted.") + end + # ------------------------------------------------------------------------ # # Migrate # # ------------------------------------------------------------------------ #