Class: Deltacloud::Runner::SSH
- Inherits:
-
Object
- Object
- Deltacloud::Runner::SSH
- Defined in:
- lib/deltacloud/runner.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#key ⇒ Object
Returns the value of attribute key.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
Instance Method Summary collapse
- #execute(command) ⇒ Object
-
#initialize(network, credentials, key = nil) ⇒ SSH
constructor
A new instance of SSH.
Constructor Details
#initialize(network, credentials, key = nil) ⇒ SSH
Returns a new instance of SSH.
64 65 66 67 |
# File 'lib/deltacloud/runner.rb', line 64 def initialize(network, credentials, key=nil) @network, @credentials, @key = network, credentials, key @result = "" end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
62 63 64 |
# File 'lib/deltacloud/runner.rb', line 62 def command @command end |
#credentials ⇒ Object
Returns the value of attribute credentials.
61 62 63 |
# File 'lib/deltacloud/runner.rb', line 61 def credentials @credentials end |
#key ⇒ Object
Returns the value of attribute key.
61 62 63 |
# File 'lib/deltacloud/runner.rb', line 61 def key @key end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
60 61 62 |
# File 'lib/deltacloud/runner.rb', line 60 def network @network end |
Instance Method Details
#execute(command) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# 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 |