1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

feature #457: added host error hook

This commit is contained in:
Tino Vázquez 2011-01-17 15:27:10 +01:00
parent 8696b216a2
commit 366b578a7f
7 changed files with 105 additions and 5 deletions

View File

@ -527,6 +527,7 @@ TM_EXAMPLE_SHARE_FILES="share/examples/tm/tm_clone.sh \
HOOK_SHARE_FILES="share/hooks/ebtables-xen \
share/hooks/ebtables-kvm \
share/hooks/ebtables-flush \
share/hooks/host_error.rb \
share/hooks/image.rb"
#-------------------------------------------------------------------------------

View File

@ -335,8 +335,8 @@ VM_HOOK = [
HOST_HOOK = [
name = "error",
on = "ERROR",
command = "error.rb",
arguments = "-r $HID",
command = "host_error.rb",
arguments = "$HID -r",
remote = no ]
#-------------------------------------------------------------------------------

82
share/hooks/host_error.rb Executable file
View File

@ -0,0 +1,82 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
####################################################
# Script to implement host failure tolerance
# It can be set to
# -r resubmit VMs running in the host
# -d delete VMs running in the host
####################################################
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
VMDIR="/var/lib/one"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
VMDIR=ONE_LOCATION+"/var"
end
$: << RUBY_LIB_LOCATION
require 'OpenNebula'
include OpenNebula
if !(host_id=ARGV[0])
exit -1
end
if !(mode=ARGV[1]) # By default, resubmit VMs
mode = "-r"
end
begin
client = Client.new()
rescue Exception => e
puts "Error: #{e}"
exit -1
end
# Retrieve hostname
host = OpenNebula::Host.new_with_id(host_id, client)
exit -1 if OpenNebula.is_error?(host)
host.info
host_name = host.name
# Loop through all vms
vms = VirtualMachinePool.new(client)
exit -1 if OpenNebula.is_error?(host)
vms.info
vm_ids_array = vms.retrieve_elements("/VM_POOL/VM[STATE=3]/HISTORY[HOSTNAME=\"#{host_name}\"]/../ID and /VM_POOL/VM[STATE=\"3\"]")
vm_ids_array.each do |vm_id|
vm=OpenNebula::VirtualMachine.new_with_id(vm_id, client)
vm.info
if mode == "-r"
vm.resubmit
elsif mode == "-d"
vm.finalize
end
end

View File

@ -359,7 +359,7 @@ Commands:
(Set a different type for the new Image)
onevm saveas <vm_id> <disk_id> <image_name> -t/--type <type>
* delete (Deletes a VM from the pool and DB)
* delete (Deletes a VM from the pool)
onevm delete <vm_id>
* restart (Forces a re-deployment of a VM in UNKNOWN or BOOT state)

View File

@ -174,7 +174,7 @@ module OpenNebula
action('resume')
end
# Deletes a VM from the pool and DB
# Deletes a VM from the pool
def finalize
action('finalize')
end

View File

@ -31,7 +31,7 @@ module OpenNebula
#######################################################################
# +client+ a Client object that represents a XML-RPC connection
# +user_id+ is to refer to a Pool with VirtualNetworks from that user
# +user_id+ is to refer to a Pool with VirtualMachines from that user
def initialize(client, user_id=0)
super('VM_POOL','VM',client)

View File

@ -94,6 +94,23 @@ module OpenNebula
end
end
def retrieve_elements(filter)
ids_array = Array.new
if NOKOGIRI
elements=@xml.xpath(filter.to_s)
if elements.size == 0
return nil
end
elements.each{ |e| ids_array << e.text }
else
@xml.each(filter.to_s) { |e| ids_array << e.text }
end
return ids_array
end
# Gets an attribute from an elemenT
# key:: _String_ xpath for the element
# name:: _String_ name of the attribute