Module: Bcome::EnvironmentSSH

Included in:
Stack::Environment
Defined in:
lib/helpers/environment_ssh.rb

Instance Method Summary collapse

Instance Method Details

#execute_cmd(raw_commands, node, proxy) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/helpers/environment_ssh.rb', line 22

def execute_cmd(raw_commands, node, proxy)
  commands = raw_commands.collect{|raw_command|
    raw_command.is_a?(::Bcome::Command) ? raw_command : ::Bcome::Command.new(raw_command, node)
  }

  ssh = ::Bcome::Ssh.new(commands, proxy, node)
  ssh.execute!
  return
end

#execute_command(commands, node) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/helpers/environment_ssh.rb', line 12

def execute_command(commands, node)
  begin
    return execute_cmd(commands, node, proxy)
  rescue Net::SSH::AuthenticationFailed
    raise "Could not authenticate connection to #{node.identifier}".failure
  rescue Net::SSH::Disconnect
    raise "SSH connection to #{node.identifier} was disconnected".failure
  end
end

#execute_scp_upload(files, remote_path, node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/helpers/environment_ssh.rb', line 32

def execute_scp_upload(files, remote_path, node)
  begin
    scp = ::Bcome::Scp.new(files, remote_path, proxy, node)
    scp.upload!
  rescue Net::SSH::AuthenticationFailed
    raise "Could not authenticate connection to #{node.identifier}".failure
  rescue Net::SSH::Disconnect 
    raise "SSH connection to #{node.identifier} was disconnected".failure
  end
end

#proxyObject



3
4
5
6
# File 'lib/helpers/environment_ssh.rb', line 3

def proxy
  return nil unless ssh_mode_type == ::SSH_JUMP_MODE_IDENTIFIER
  return Net::SSH::Proxy::Command.new(proxy_command)
end

#proxy_commandObject



8
9
10
# File 'lib/helpers/environment_ssh.rb', line 8

def proxy_command
  return "ssh -W %h:%p #{bastion_ip_address}"
end