Class: Bcome::Ssh::Connector
Class Method Summary
collapse
Instance Method Summary
collapse
#cursor, #do_signal, #fork_process, #signal_failure, #signal_stop, #signal_success, #start_indicator, #stop_indicator, #wrap_indicator
Constructor Details
#initialize(node, config) ⇒ Connector
Returns a new instance of Connector.
15
16
17
18
19
20
21
|
# File 'lib/objects/ssh/connector.rb', line 15
def initialize(node, config)
@node = node
@config = config
set_servers
@connected_machines = []
@connection_exceptions = {}
end
|
Class Method Details
.connect(node, config = {}) ⇒ Object
9
10
11
12
|
# File 'lib/objects/ssh/connector.rb', line 9
def connect(node, config = {})
handler = new(node, config)
handler.connect
end
|
Instance Method Details
#connect ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/objects/ssh/connector.rb', line 31
def connect
return if number_unconnected_machines == 0 && !ping?
if show_progress?
print "\n"
wrap_indicator type: :progress, size: @servers_to_connect.size, title: 'Opening connections' do
open_connections
end
else
open_connections
end
report_connection_outcome
end
|
#open_connections ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/objects/ssh/connector.rb', line 67
def open_connections
@servers_to_connect.pmap do |machine|
begin
machine.open_ssh_connection(ping?)
if machine.has_ssh_connection?
@servers_to_connect -= [machine]
@connected_machines << machine
signal_success if show_progress?
else
signal_failure if show_progress?
end
rescue Errno::EPIPE, Bcome::Exception::CouldNotInitiateSshConnection, ::Bcome::Exception::InvalidProxyConfig => e
signal_failure if show_progress?
@connection_exceptions[machine] = e
end
end
end
|
#ping? ⇒ Boolean
27
28
29
|
# File 'lib/objects/ssh/connector.rb', line 27
def ping?
@config[:is_ping] ? true : false
end
|
#report_connection_outcome ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/objects/ssh/connector.rb', line 46
def report_connection_outcome
print "\n"
if ping?
@connected_machines.pmap do |machine|
puts machine.print_ping_result
end
@servers_to_connect.each do |machine|
ping_result = {
success: false,
error: @connection_exceptions[machine]
}
puts machine.print_ping_result(ping_result)
end
end
puts "Failed to connect to #{@servers_to_connect.size} node#{@servers_to_connect.size > 1 ? 's' : ''}".error if @servers_to_connect.any?
end
|
#show_progress? ⇒ Boolean
23
24
25
|
# File 'lib/objects/ssh/connector.rb', line 23
def show_progress?
@config[:show_progress] ? true : false
end
|