Class: Bcome::Interactive::SessionItem::TransparentSsh
- Inherits:
-
Base
- Object
- Base
- Bcome::Interactive::SessionItem::TransparentSsh
show all
- Defined in:
- lib/objects/interactive/session_item/transparent_ssh.rb
Constant Summary
collapse
- END_SESSION_KEY =
'\\q'.freeze
- HELP_KEY =
'\\?'.freeze
- LIST_KEY =
'\\l'.freeze
- DANGER_CMD =
"rm\s+-r|rm\s+-f|rm\s+-fr|rm\s+-rf|rm".freeze
Instance Method Summary
collapse
Methods inherited from Base
#bcome_identifier, #get_input, #has_start_message?, #initialize, #node, #options, #set_response_on_session
Instance Method Details
#action ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 22
def action
input = get_input
if exit?(input)
close_ssh_connections
return
end
if (input)
elsif list_machines?(input)
list_machines
elsif command_may_be_unwise?(input)
handle_the_unwise(input)
else
execute_on_machines(input)
end
action
end
|
#close_ssh_connections ⇒ Object
88
89
90
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 88
def close_ssh_connections
node.close_ssh_connections
end
|
#command_may_be_unwise?(input) ⇒ Boolean
55
56
57
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 55
def command_may_be_unwise?(input)
input =~ /#{DANGER_CMD}/
end
|
#do ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 13
def do
puts ''
open_ssh_connections
puts ''
list_machines
action
end
|
#execute_on_machines(user_input) ⇒ Object
105
106
107
108
109
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 105
def execute_on_machines(user_input)
machines.pmap do |machine|
machine.run(user_input)
end
end
|
#exit?(input) ⇒ Boolean
71
72
73
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 71
def exit?(input)
input == END_SESSION_KEY
end
|
#handle_the_unwise(input) ⇒ Object
49
50
51
52
53
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 49
def handle_the_unwise(input)
if prompt_for_confirmation('Command may be dangerous to run on all machines. Are you sure you want to proceed? [Y|N] > '.error)
execute_on_machines(input)
end
end
|
#indicate_failed_nodes(unconnected_nodes) ⇒ Object
92
93
94
95
96
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 92
def indicate_failed_nodes(unconnected_nodes)
unconnected_nodes.each do |node|
puts "\s\s - #{node.namespace}".bc_cyan
end
end
|
#list_machines ⇒ Object
98
99
100
101
102
103
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 98
def list_machines
puts "\n"
machines.each do |machine|
puts "\s- #{machine.namespace}"
end
end
|
#list_machines?(input) ⇒ Boolean
79
80
81
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 79
def list_machines?(input)
input == LIST_KEY
end
|
#machines ⇒ Object
9
10
11
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 9
def machines
node.server? ? [node] : node.machines
end
|
#open_ssh_connections ⇒ Object
83
84
85
86
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 83
def open_ssh_connections
::Bcome::Ssh::ConnectionHandler.connect(node, show_progress: true)
system('clear')
end
|
#prompt_for_confirmation(message) ⇒ Object
59
60
61
62
63
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 59
def prompt_for_confirmation(message)
answer = get_input(message)
prompt_for_confirmation(message) unless %w[Y N].include?(answer)
answer == 'Y'
end
|
42
43
44
45
46
47
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 42
def
warning = "\n\sCommands entered here will be executed on " + 'EVERY'.underline + ' machine in your selection.'
second_warning = "\n\n\s" + 'Use with CAUTION.'.warning
info = "\n\n\s\\l list machines\n\s\\q to quit\n\s\\? this message".informational
puts "#{warning}#{second_warning}#{info}\n"
end
|
75
76
77
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 75
def (input)
input == HELP_KEY
end
|
#start_message ⇒ Object
65
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 65
def start_message; end
|
#terminal_prompt ⇒ Object
67
68
69
|
# File 'lib/objects/interactive/session_item/transparent_ssh.rb', line 67
def terminal_prompt
">\s".bold.terminal_prompt
end
|