class Alphonse::Connection
Attributes
config[R]
host[R]
session[R]
user[R]
Public Class Methods
new(host, user, config)
click to toggle source
# 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
Public Instance Methods
close()
click to toggle source
# File lib/alphonse/connection.rb, line 47 def close session.close end
connection_string()
click to toggle source
# File lib/alphonse/connection.rb, line 20 def connection_string "#{user}@#{host}" end
send_and_execute(command = "")
click to toggle source
# 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
Private Instance Methods
parse(command)
click to toggle source
# File lib/alphonse/connection.rb, line 53 def parse(command) case command.class.name when 'String' command == '' ? [] : [command.chomp] when 'Array' command.compact.flatten else raise Alphonse::MissingCommandError, "Command Not a String or Array: #{command.inspect}" end end