Class: Ajimi::Server::Ssh

Inherits:
Object
  • Object
show all
Defined in:
lib/ajimi/server/ssh.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Ssh

Returns a new instance of Ssh.



6
7
8
9
10
# File 'lib/ajimi/server/ssh.rb', line 6

def initialize(options = {})
  @host = options[:host]
  @user = options[:user]
  @key = options[:key]
end

Instance Method Details

#command_exec(cmd) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ajimi/server/ssh.rb', line 16

def command_exec(cmd)
  ssh_options_default = {}
  ssh_options_override = {
    keys: @key
  }
  ssh_options = ssh_options_default.merge(ssh_options_override)

  stdout = ""
  stderr = ""
  net_ssh.start(@host, @user, ssh_options) do |session|
    session.exec!(cmd) do |channel, stream, data|
      stdout << data if stream == :stdout
      stderr << data if stream == :stderr
    end
  end
  $stderr.puts stderr unless stderr == ""
  stdout
end

#net_sshObject



12
13
14
# File 'lib/ajimi/server/ssh.rb', line 12

def net_ssh
  Net::SSH
end