Don't operate on 'host' object if it doesn't exist

This commit is contained in:
Scott Schneider 2013-10-03 15:51:45 -07:00
parent 32fee4e0b1
commit c17637c8b1

View file

@ -115,21 +115,25 @@ loop do
$redis.srem('vmware_host_pool__completed__'+pool['name'], vm)
end
start = Time.now
host = vsphere_helper.find_vms(vm)[vm]
if host.runtime
if (
(host) and
(host.runtime)
)
start = Time.now
if host.runtime.powerState == 'poweredOn'
logger.log('d', "[ ] '#{vm}' is being shut down")
host.PowerOffVM_Task.wait_for_completion
end
end
host.Destroy_Task.wait_for_completion
finish = '%.2f' % (Time.now-start)
logger.log('s', "[-] '#{vm}' destroyed in #{finish} seconds")
end
end
# Bring the pool up to the desired size
if total < pool['size']