Class: Octosh::Shell
- Inherits:
-
Object
- Object
- Octosh::Shell
- Defined in:
- lib/octosh/shell.rb
Instance Method Summary collapse
- #disconnect ⇒ Object
-
#initialize(hosts, options) ⇒ Shell
constructor
A new instance of Shell.
- #preprocess_command(command) ⇒ Object
- #prompt_for_password(password_prompt, uniform_password, host = "current host") ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(hosts, options) ⇒ Shell
Returns a new instance of Shell.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/octosh/shell.rb', line 16 def initialize(hosts, ) colors = Octosh::COLORS::COLORS.dup @workers = [] hosts.each do |host| prompt_for_password([:password_prompt], [:uniform_password]) exec_user,hostname = "" if host.include? '@' # USer defined with host, override provided user exec_user,hostname = host.split('@') else exec_user = [:default_user] hostname = host end = .dup [:color] = colors.shift colors << [:color] worker = Octosh::Worker.new(hostname, exec_user, @password, ) worker.connect @workers << worker end end |
Instance Method Details
#disconnect ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/octosh/shell.rb', line 83 def disconnect @workers.each do |worker| print "Closing connection to #{worker.host} . . . ".colorize(worker.[:color].to_sym) worker.disconnect puts "OK".colorize(worker.[:color].to_sym) end end |
#preprocess_command(command) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/octosh/shell.rb', line 76 def preprocess_command(command) if command.downcase == "exit" disconnect exit end end |
#prompt_for_password(password_prompt, uniform_password, host = "current host") ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/octosh/shell.rb', line 38 def prompt_for_password(password_prompt, uniform_password, host="current host") if password_prompt # Password authentication if uniform_password and @password.nil? # One password for all hosts @password = Octosh::Helper.password_prompt("Password: ") elsif not uniform_password # One password for each host @password = Octosh::Helper.password_prompt("Password for #{host}: ") end end end |
#start ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/octosh/shell.rb', line 51 def start puts "Starting Octoshell connected to #{@workers.length} hosts" @workers.each do |worker| puts worker.host.colorize(worker.[:color].to_sym) end while true print ">> " command = "" begin command = gets.chomp! rescue Interrupt disconnect exit end preprocess_command(command || "") Parallel.each(@workers, :in_threads => @workers.length) do |worker| output = worker.exec(command) do |output| print output.colorize(worker.[:color].to_sym) end end end end |