(POOLER-140) Ensure a VM is alive at checkout

This commit duplicates the vm_ready? check to the API layer to allow for API to validate that a VM is alive at checkout. Without this change API relies upon the checks in pool_manager validating pools. This change should allow for additional insight into whether a machine is in a ready state and resopnding at checkout time.
This commit is contained in:
kirby@puppetlabs.com 2019-07-16 09:19:47 -07:00
parent a755d8d6a2
commit d6e948d34d
5 changed files with 118 additions and 17 deletions

View file

@ -470,6 +470,29 @@ module Vmpooler
rescue
false
end
def open_socket(host, domain = nil, timeout = 1, port = 22, &_block)
Timeout.timeout(timeout) do
target_host = host
target_host = "#{host}.#{domain}" if domain
sock = TCPSocket.new target_host, port
begin
yield sock if block_given?
ensure
sock.close
end
end
end
def vm_ready?(vm_name, domain = nil)
begin
open_socket(vm_name, domain)
rescue => _err
return false
end
true
end
end
end
end