Class: Pipes::SshPipe

Inherits:
SystemPipe show all
Defined in:
lib/ssh_pipe.rb

Constant Summary

Constants inherited from SystemPipe

Pipes::SystemPipe::NUMBER_ONLY_REGEX

Instance Attribute Summary collapse

Attributes inherited from SystemPipe

#abandoned_pipes_count, #initial_command, #pipe

Instance Method Summary collapse

Methods inherited from SystemPipe

#backup_file, #backup_timestamp, #close_with_timeout, #cp, #current_time, #ensure_started, #extract_number_from_string, #flush_until, #follow_file, #follow_file_command, #make_path, #puts_command_read_number, #puts_limit_one_line, #puts_with_output_to_dev_null, #retry_after_timeout, #retry_pipe, #run_command_and_ensure_return_code, #start_pipe, #write_file

Constructor Details

#initialize(ssh_hosts, user = nil) ⇒ SshPipe

Returns a new instance of SshPipe.



6
7
8
9
10
11
12
13
14
# File 'lib/ssh_pipe.rb', line 6

def initialize(ssh_hosts, user = nil)
  @hosts = ssh_hosts.clone
  @initialization_command = initial_ssh_command(ssh_hosts.shift,user)

  ssh_hosts.each do |host|
    @initialization_command += "ssh #{host} "
  end
  super(initialization_command)
end

Instance Attribute Details

#hostsObject (readonly)

Returns the value of attribute hosts.



4
5
6
# File 'lib/ssh_pipe.rb', line 4

def hosts
  @hosts
end

#initialization_commandObject (readonly)

Returns the value of attribute initialization_command.



4
5
6
# File 'lib/ssh_pipe.rb', line 4

def initialization_command
  @initialization_command
end

Instance Method Details

#closeObject



38
39
40
41
# File 'lib/ssh_pipe.rb', line 38

def close
  puts "exit"
  super
end

#initial_ssh_command(host, user) ⇒ Object



16
17
18
19
20
21
# File 'lib/ssh_pipe.rb', line 16

def initial_ssh_command(host,user)
  ssh_command =  "ssh #{ssh_options}"
  ssh_command += "#{user}@" if user_specified(user)
  ssh_command += "#{host} "
  ssh_command
end

#ssh_optionsObject



24
25
26
27
28
29
30
31
32
# File 'lib/ssh_pipe.rb', line 24

def ssh_options
  options  = "-o 'StrictHostKeyChecking no' "
  options += "-o 'UserKnownHostsFile=/dev/null' "
  options += "-o 'ConnectionAttempts 5' "
  options += "-o 'CheckHostIP no' "
  options += "-o 'PasswordAuthentication no' "
  options += "-o 'ForwardAgent true' "
  options
end

#user_specified(user) ⇒ Object



34
35
36
# File 'lib/ssh_pipe.rb', line 34

def user_specified(user)
  user && (not user.empty?)
end