Class: Kdeploy::Executor
- Inherits:
-
Object
- Object
- Kdeploy::Executor
- Defined in:
- lib/kdeploy/executor.rb
Instance Method Summary collapse
- #execute(command) ⇒ Object
-
#initialize(host_config) ⇒ Executor
constructor
A new instance of Executor.
- #upload(source, destination) ⇒ Object
- #upload_template(source, destination, variables = {}) ⇒ Object
Constructor Details
#initialize(host_config) ⇒ Executor
Returns a new instance of Executor.
8 9 10 11 12 13 14 |
# File 'lib/kdeploy/executor.rb', line 8 def initialize(host_config) @host = host_config[:name] @user = host_config[:user] @ip = host_config[:ip] @password = host_config[:password] @key = host_config[:key] end |
Instance Method Details
#execute(command) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kdeploy/executor.rb', line 16 def execute(command) Net::SSH.start(@ip, @user, ) do |ssh| stdout = String.new stderr = String.new ssh.exec!(command) do |_channel, stream, data| case stream when :stdout stdout << data when :stderr stderr << data end end { stdout: stdout.strip, stderr: stderr.strip, command: command } end rescue Net::SSH::AuthenticationFailed => e raise "SSH authentication failed: #{e.}" rescue StandardError => e raise "SSH execution failed: #{e.}" end |
#upload(source, destination) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/kdeploy/executor.rb', line 42 def upload(source, destination) Net::SCP.start(@ip, @user, ) do |scp| scp.upload!(source, destination) end rescue StandardError => e raise "SCP upload failed: #{e.}" end |
#upload_template(source, destination, variables = {}) ⇒ Object
50 51 52 53 54 |
# File 'lib/kdeploy/executor.rb', line 50 def upload_template(source, destination, variables = {}) Template.render_and_upload(self, source, destination, variables) rescue StandardError => e raise "Template upload failed: #{e.}" end |