class Bcome::Interactive::SessionItem::TransparentSsh

Constants

DANGER_CMD
END_SESSION_KEY
HELP_KEY
LIST_KEY
RECONNECT_CMD

Public Instance Methods

action() click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 26
def action
  input = get_input

  return if exit?(input)

  if show_menu?(input)
    show_menu
  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() click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 86
def close_ssh_connections
  node.close_ssh_connections
end
command_may_be_unwise?(input) click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 53
def command_may_be_unwise?(input)
  input =~ /#{DANGER_CMD}/
end
do() click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 16
def do
  puts ''
  open_ssh_connections
  puts "\nINTERACTIVE COMMAND SESSION".underline
  show_menu
  puts ''
  list_machines
  action
end
execute_on_machines(user_input) click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 103
def execute_on_machines(user_input)
  machines.pmap do |machine|
    begin
      machine.run(user_input)
    rescue IOError => e
      puts "Reopening connection to\s".informational + machine.identifier
      machine.reopen_ssh_connection
      machine.run(user_input)
    rescue Exception => e
      puts "Error connecting to #{machine.identifier} (#{e.message})".error
    end
  end
end
exit?(input) click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 69
def exit?(input)
  input == END_SESSION_KEY
end
handle_the_unwise(input) click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 49
def handle_the_unwise(input)
  execute_on_machines(input) if prompt_for_confirmation('Command may be dangerous to run on all machines. Are you sure you want to proceed? [Y|N] > '.error)
end
indicate_failed_nodes(unconnected_nodes) click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 90
def indicate_failed_nodes(unconnected_nodes)
  unconnected_nodes.each do |node|
    puts "\s\s - #{node.namespace}"
  end
end
list_machines() click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 96
def list_machines
  puts "\n"
  machines.each do |machine|
    puts "- #{machine.namespace}"
  end
end
list_machines?(input) click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 77
def list_machines?(input)
  input == LIST_KEY
end
machines() click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 11
def machines
  skip_for_hidden = true
  node.server? ? [node] : node.machines(skip_for_hidden)
end
open_ssh_connections() click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 81
def open_ssh_connections
  ::Bcome::Ssh::Connector.connect(node, show_progress: true)
  # system('clear')
end
prompt_for_confirmation(message) click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 57
def prompt_for_confirmation(message)
  answer = get_input(message)
  prompt_for_confirmation(message) unless %w[Y N].include?(answer)
  answer == 'Y'
end
show_menu() click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 43
def show_menu
  warning = "\nCommands entered here will be executed on" + "\severy\s".warning + "machine in your selection. \n\nUse with caution or hit \\q if you're unsure what this is."
  info = "\n\n\\l list machines\n\\q to quit\n\\? this message".informational
  puts warning + "#{info}\n"
end
show_menu?(input) click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 73
def show_menu?(input)
  input == HELP_KEY
end
start_message() click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 63
def start_message; end
terminal_prompt() click to toggle source
# File lib/objects/interactive/session_item/transparent_ssh.rb, line 65
def terminal_prompt
  "enter a command>\s"
end