Parent

Methods

Class/Module Index [+]

Quicksearch

Deltacloud::Runner::SSH

Attributes

command[R]
credentials[RW]
key[RW]
network[R]

Public Class Methods

new(network, credentials, key=nil) click to toggle source
# File lib/deltacloud/runner.rb, line 64
def initialize(network, credentials, key=nil)
  @network, @credentials, @key = network, credentials, key
  @result = ""
end

Public Instance Methods

execute(command) click to toggle source
# File lib/deltacloud/runner.rb, line 69
def execute(command)
  @command = command
  config = ssh_config(@network, @credentials, @key)
  begin
    session = nil
    # Default timeout for connecting to an instance.
    # 20 seconds should be OK for most of connections, if you are
    # experiencing some Exceptions with Timeouts increase this value.
    # Please keep in mind that the HTTP request timeout is set to 60
    # seconds, so you need to fit into this time
    Timeout::timeout(20) do
      session = Net::SSH.start(@network.ip, 'root', config)
    end
    session.open_channel do |channel|
      channel.on_data do |ch, data|
        @result += data
      end
      channel.exec(command)
      session.loop
    end
    session.close
  rescue Exception => e
    raise InstanceSSHError.new("#{e.class.name}: #{e.message}")
  ensure
    # FileUtils.rm(config[:keys].first) rescue nil
  end
  Deltacloud::Runner::Response.new(self, @result)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.