Class: Oode::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/oode/net/session.rb

Direct Known Subclasses

Transferer

Constant Summary collapse

SERVER =
'ssh.inf.ed.ac.uk'
DEFAULT_HOST =
'student.login'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, options = {}) ⇒ Session

Returns a new instance of Session.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/oode/net/session.rb', line 18

def initialize(user, options = {})
  @user = user
  @machine = options[:machine] || DEFAULT_HOST
  
  begin
    @session = Net::SSH.start(SERVER, user.username, :password => user.password)
  rescue Net::SSH::AuthenticationFailed
    error "Your login credentials were incorrect. Please fix this and try again."
  rescue Net::SSH::Exception
    error SSH_ERROR
  end
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



16
17
18
# File 'lib/oode/net/session.rb', line 16

def user
  @user
end

Instance Method Details

#closeObject



35
36
37
# File 'lib/oode/net/session.rb', line 35

def close
  @session.close
end

#connectionObject



31
32
33
# File 'lib/oode/net/session.rb', line 31

def connection
  @session
end

#exec!(command, options = {}) ⇒ Object



39
40
41
42
43
# File 'lib/oode/net/session.rb', line 39

def exec!(command, options = {})
  host = options[:machine] || @machine
  out = @session.exec!("ssh #{host} #{command}")
  out.chomp unless out.nil?
end