mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Use open socket method for opening socket
This commit updates pool manager to use a method for opening a socket instead of opening it directly from check_pending_vm. Support is added for specifying the domain of the VM to connect to, which lays the groundwork for doing away with the assumption of having DNS search domains set for vmpooler to move VMs to the ready state. Additionally, this commit adds a block to ensure open_socket closes open connections. Without this change sockets are opened to each VM before moving to the ready state, and never explicitly closed. Also, use open socket for check_ready_vm
This commit is contained in:
parent
109f197fe7
commit
a6c8c76d31
1 changed files with 19 additions and 18 deletions
|
|
@ -26,29 +26,30 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_socket(host, domain=nil, timeout=5, port=22)
|
def open_socket(host, domain=nil, timeout=5, port=22, &block)
|
||||||
Timeout.timeout(timeout) do
|
Timeout.timeout(timeout) do
|
||||||
target_host = vm
|
target_host = host
|
||||||
target_host = "#{vm}.#{domain}" if domain
|
target_host = "#{host}.#{domain}" if domain
|
||||||
TCPSocket.new target_host, port
|
sock = TCPSocket.new target_host, port
|
||||||
|
begin
|
||||||
|
yield sock if block_given?
|
||||||
|
ensure
|
||||||
|
sock.close
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def _check_pending_vm(vm, pool, timeout, vsphere)
|
def _check_pending_vm(vm, pool, timeout, vsphere)
|
||||||
host = vsphere.find_vm(vm)
|
host = vsphere.find_vm(vm)
|
||||||
|
|
||||||
if host
|
if ! host
|
||||||
begin
|
fail_pending_vm(vm, pool, timeout, false)
|
||||||
Timeout.timeout(5) do
|
return
|
||||||
TCPSocket.new vm, 22
|
|
||||||
end
|
|
||||||
move_pending_vm_to_ready(vm, pool, host)
|
|
||||||
rescue
|
|
||||||
fail_pending_vm(vm, pool, timeout)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
fail_pending_vm(vm, pool, timeout)
|
|
||||||
end
|
end
|
||||||
|
open_socket vm
|
||||||
|
move_pending_vm_to_ready(vm, pool, host)
|
||||||
|
rescue
|
||||||
|
fail_pending_vm(vm, pool, timeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fail_pending_vm(vm, pool, timeout, exists=true)
|
def fail_pending_vm(vm, pool, timeout, exists=true)
|
||||||
|
|
@ -137,12 +138,12 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Timeout.timeout(5) do
|
open_socket vm
|
||||||
TCPSocket.new vm, 22
|
|
||||||
end
|
|
||||||
rescue
|
rescue
|
||||||
if $redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
|
if $redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
|
||||||
$logger.log('d', "[!] [#{pool}] '#{vm}' is unreachable, removed from 'ready' queue")
|
$logger.log('d', "[!] [#{pool}] '#{vm}' is unreachable, removed from 'ready' queue")
|
||||||
|
else
|
||||||
|
$logger.log('d', "[!] [#{pool}] '#{vm}' is unreachable, and failed to remove from 'ready' queue")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue