mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Parallelize VM cleanup in threads
This commit is contained in:
parent
3859eb85c2
commit
47ac1ed0ff
1 changed files with 25 additions and 18 deletions
|
|
@ -93,6 +93,30 @@ def clone_vm template, pool, folder, datastore
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Destroy a VM
|
||||||
|
def destroy_vm vm
|
||||||
|
Thread.new {
|
||||||
|
host = $vsphere_helper.find_vms(vm)[vm]
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
host.Destroy_Task.wait_for_completion
|
||||||
|
finish = '%.2f' % (Time.now-start)
|
||||||
|
|
||||||
|
$logger.log('s', "[-] '#{vm}' destroyed in #{finish} seconds")
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Update loop
|
# Update loop
|
||||||
|
|
@ -202,24 +226,7 @@ loop do
|
||||||
$redis.srem('vmware_host_pool__completed__'+pool['name'], vm)
|
$redis.srem('vmware_host_pool__completed__'+pool['name'], vm)
|
||||||
end
|
end
|
||||||
|
|
||||||
host = $vsphere_helper.find_vms(vm)[vm]
|
destroy_vm(vm)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
host.Destroy_Task.wait_for_completion
|
|
||||||
finish = '%.2f' % (Time.now-start)
|
|
||||||
|
|
||||||
$logger.log('s', "[-] '#{vm}' destroyed in #{finish} seconds")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check 'failed' pool
|
# Check 'failed' pool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue