mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Quick hack to auto-destroy long-running VMs
This commit is contained in:
parent
c4b85d0306
commit
009cf789ab
1 changed files with 22 additions and 0 deletions
|
|
@ -79,6 +79,19 @@ def check_ready_vm vm, pool, ttl
|
|||
}
|
||||
end
|
||||
|
||||
def check_running_vm vm, pool, ttl
|
||||
Thread.new {
|
||||
host = $vsphere_helper.find_vms(vm)[vm]
|
||||
|
||||
if ((((Time.now - host.runtime.bootTime)/60).to_s[/^\d+\.\d{1}/].to_f) > ttl)
|
||||
$redis.srem('vmware_host_pool__running__'+pool, vm)
|
||||
$redis.sadd('vmware_host_pool__completed__'+pool, vm)
|
||||
|
||||
$logger.log('d', "[!] [#{pool}] '#{vm}' reached end of TTL after #{ttl} minutes")
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
# Clone a VM
|
||||
def clone_vm template, pool, folder, datastore
|
||||
Thread.new {
|
||||
|
|
@ -197,6 +210,15 @@ def check_pool pool
|
|||
inventory[vm['name']] = 1
|
||||
end
|
||||
|
||||
# RUNNING
|
||||
$redis.smembers('vmware_host_pool__running__'+pool['name']).each do |vm|
|
||||
if (! inventory[vm])
|
||||
$redis.srem('vmware_host_pool__running__'+pool['name'], vm)
|
||||
end
|
||||
|
||||
check_running_vm(vm, pool['name'], config[:config]['ttl'])
|
||||
end
|
||||
|
||||
# READY
|
||||
$redis.smembers('vmware_host_pool__ready__'+pool['name']).each do |vm|
|
||||
if (! inventory[vm])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue