Class: Oode::Session
- Inherits:
-
Object
- Object
- Oode::Session
- Defined in:
- lib/oode/net/session.rb
Direct Known Subclasses
Constant Summary collapse
- SERVER =
'ssh.inf.ed.ac.uk'
- DEFAULT_HOST =
'student.login'
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #close ⇒ Object
- #connection ⇒ Object
- #exec!(command, options = {}) ⇒ Object
-
#initialize(user, options = {}) ⇒ Session
constructor
A new instance of Session.
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, = {}) @user = user @machine = [: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
#user ⇒ Object (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
#close ⇒ Object
35 36 37 |
# File 'lib/oode/net/session.rb', line 35 def close @session.close end |
#connection ⇒ Object
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, = {}) host = [:machine] || @machine out = @session.exec!("ssh #{host} #{command}") out.chomp unless out.nil? end |