Class: Alphonse::Connection
- Inherits:
-
Object
- Object
- Alphonse::Connection
- Defined in:
- lib/alphonse/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #close ⇒ Object
- #connection_string ⇒ Object
-
#initialize(host, user, config) ⇒ Connection
constructor
A new instance of Connection.
- #send_and_execute(command = "") ⇒ Object
Constructor Details
#initialize(host, user, config) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/alphonse/connection.rb', line 9 def initialize(host, user, config) @config = config @host = host @user = user raise Alphonse::MissingUserError, "User has not been specified" unless user raise Alphonse::MissingHostError, "Host has not been specified" unless host @session = Net::SSH::Session.new(host, user) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/alphonse/connection.rb', line 8 def config @config end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/alphonse/connection.rb', line 8 def host @host end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
8 9 10 |
# File 'lib/alphonse/connection.rb', line 8 def session @session end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/alphonse/connection.rb', line 8 def user @user end |
Instance Method Details
#close ⇒ Object
47 48 49 |
# File 'lib/alphonse/connection.rb', line 47 def close session.close end |
#connection_string ⇒ Object
20 21 22 |
# File 'lib/alphonse/connection.rb', line 20 def connection_string "#{user}@#{host}" end |
#send_and_execute(command = "") ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/alphonse/connection.rb', line 24 def send_and_execute(command = "") commands = parse(command) session.open(10) results = [] commands.each do |cmd| Alphonse.logger.task cmd result = session.run(cmd) results << result if result.failure? Alphonse.logger.error result.output break else Alphonse.logger.debug result.output if config[:verbose] Alphonse.logger.info "Completed in #{result.duration}s" end end results end |