From 216b798a6cfeb2a581b28918e0f088f297372ff8 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 11 Jul 2011 18:42:22 +0200 Subject: [PATCH] Fix host_error hook for the new OCA --- share/hooks/host_error.rb | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/share/hooks/host_error.rb b/share/hooks/host_error.rb index 5bf785204f..b4f7864233 100755 --- a/share/hooks/host_error.rb +++ b/share/hooks/host_error.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env ruby +#!/usr/bin/env ruby # -------------------------------------------------------------------------- # # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) # @@ -18,9 +18,9 @@ #################################################### # Script to implement host failure tolerance -# It can be set to +# It can be set to # -r resubmit VMs running in the host -# -d delete VMs running in the host +# -d delete VMs running in the host #################################################### ONE_LOCATION=ENV["ONE_LOCATION"] @@ -64,16 +64,18 @@ host.info host_name = host.name # Loop through all vms -vms = VirtualMachinePool.new(client, -2) +vms = VirtualMachinePool.new(client) exit -1 if OpenNebula.is_error?(vms) -vms.info +vms.info_all -vm_ids_array = vms.retrieve_elements("/VM_POOL/VM[STATE=3]/HISTORY[HOSTNAME=\"#{host_name}\"]/../ID") +state = "STATE=3" +state += " or STATE=5" if force == "y" +vm_ids_array = vms.retrieve_elements("/VM_POOL/VM[#{state}]/HISTORY_RECORDS/HISTORY[HOSTNAME=\"#{host_name}\" and last()]/../../ID") if vm_ids_array - vm_ids_array.each do |vm_id| + vm_ids_array.each do |vm_id| vm=OpenNebula::VirtualMachine.new_with_id(vm_id, client) vm.info @@ -85,21 +87,3 @@ if vm_ids_array end end -if force == "y" - vm_ids_array = vms.retrieve_elements("/VM_POOL/VM[STATE=5]/HISTORY[HOSTNAME=\"#{host_name}\"]/../ID") - - if vm_ids_array - 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 - end -end - -