Class: Rays::Service::Remote::SSH

Inherits:
Object
  • Object
show all
Defined in:
lib/rays/services/remote.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port, user) ⇒ SSH

Returns a new instance of SSH.



29
30
31
32
33
34
# File 'lib/rays/services/remote.rb', line 29

def initialize(host, port, user)
  @host = host
  @port = port # TODO: not used for now.
  @user = user
  defaults
end

Instance Method Details

#copy_from(remote_file, local_file) ⇒ Object



80
81
82
# File 'lib/rays/services/remote.rb', line 80

def copy_from(remote_file, local_file)
  rays_exec("#{$rays_config.scp} #{user}@#{host}:#{remote_file} #{local_file}")
end

#copy_to(local_file, remote_file) ⇒ Object



76
77
78
# File 'lib/rays/services/remote.rb', line 76

def copy_to(local_file, remote_file)
  rays_exec("#{$rays_config.scp} #{local_file} #{user}@#{host}:#{remote_file}")
end

#exec(command) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/rays/services/remote.rb', line 67

def exec(command)
  response = ""
  Net::SSH.start("#{host}", "#{user}") do |ssh|
    response = ssh.exec!(command)
    $log.debug(response)
  end
  response
end

#hostObject

Raises:



36
37
38
39
# File 'lib/rays/services/remote.rb', line 36

def host
  raise RaysException.new(missing_environment_option('ssh', 'host')) if @host.nil?
  @host
end

#loop_exec(command) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rays/services/remote.rb', line 51

def loop_exec(command)
  begin
    Net::SSH.start("#{host}", "#{user}") do |ssh|
      ssh.open_channel do |channel|
        channel.on_data do |ch, data|
          $log.info("<!#{data}!>")
        end
        channel.exec command
      end
      ssh.loop
    end
  rescue SystemExit, Interrupt
    # Ctrl-c
  end
end

#portObject

Raises:



41
42
43
44
# File 'lib/rays/services/remote.rb', line 41

def port
  raise RaysException.new(missing_environment_option('ssh', 'port')) if @port.nil?
  @port
end

#userObject

Raises:



46
47
48
49
# File 'lib/rays/services/remote.rb', line 46

def user
  raise RaysException.new(missing_environment_option('ssh', 'user')) if @user.nil?
  @user
end