From d3feae9b03d5c0e493a7ea4bf96787ccdc3d5084 Mon Sep 17 00:00:00 2001
From: Tino Vazquez <tinova@opennebula.org>
Date: Tue, 26 May 2015 17:15:20 +0200
Subject: [PATCH] Bug #3818: Fix wrong polling in shutdown

---
 src/vmm_mad/remotes/vmware/shutdown | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/vmm_mad/remotes/vmware/shutdown b/src/vmm_mad/remotes/vmware/shutdown
index fbaac03238..50041948de 100755
--- a/src/vmm_mad/remotes/vmware/shutdown
+++ b/src/vmm_mad/remotes/vmware/shutdown
@@ -28,6 +28,7 @@ $: << RUBY_LIB_LOCATION
 $: << File.dirname(__FILE__)
 
 require 'vmware_driver'
+require 'vi_driver'
 
 #------------------------------------------------------------------------------
 # Wait the VM to shutdown TIMEOUT (xPOLL_INTERVAL) seconds.
@@ -39,12 +40,14 @@ TIMEOUT=300
 deploy_id = ARGV[0]
 host      = ARGV[1]
 
+VIDriver::initialize(host)
+
 vmware_drv = VMwareDriver.new(host)
 
 vmware_drv.shutdown(deploy_id)
 
 count=0
-while (vmware_drv.poll(deploy_id).match(/STATE=(.*)/)[1] != "d") do
+while (VIDriver::poll_vm(deploy_id).match(/STATE=(.*)/)[1] != "d") do
 	sleep POLL_INTERVAL
 	if count > TIMEOUT then
 	    OpenNebula.log_debug("Timeout reached and VM #{deploy_id} is still alive.")