Module: Bcome::InstanceSsh

Included in:
Stack::Instance
Defined in:
lib/helpers/instance_ssh.rb

Instance Method Summary collapse

Instance Method Details

#bastion_ip_addressObject



46
47
48
# File 'lib/helpers/instance_ssh.rb', line 46

def bastion_ip_address
  return @environment.bastion_ip_address
end

#direct_ssh_commandObject



29
30
31
# File 'lib/helpers/instance_ssh.rb', line 29

def direct_ssh_command
  command = "ssh #{environment.ssh_mode_user}@#{public_ip_address}"
end

#do_ssh(command) ⇒ Object



15
16
17
18
19
# File 'lib/helpers/instance_ssh.rb', line 15

def do_ssh(command)
  result = execute_task(:run_local, command)
  raise "Unable to execute result" unless result # TODO node has not been bootstrapped most likely. Implement a fallback
  return result
end

#execute_task(task_name, *args) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/helpers/instance_ssh.rb', line 3

def execute_task(task_name, *args)
  begin
    public_send(task_name, *args)
  rescue ::Seahorse::Client::NetworkingError
    puts "Could not execute '#{task_name}'. Cannot initiate connection - check your network connection and try again.".failure
  end
end

#is_direct_ssh?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/helpers/instance_ssh.rb', line 50

def is_direct_ssh?
  environment.ssh_mode_type == ::SSH_DIRECT_MODE_IDENTIFIER
end

#is_jump_ssh?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/helpers/instance_ssh.rb', line 54

def is_jump_ssh?
  environment.ssh_mode_type == ::SSH_JUMP_MODE_IDENTIFIER
end

#is_ssh_jump_host?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/helpers/instance_ssh.rb', line 62

def is_ssh_jump_host?
  @meta_data["role"] == ::SSH_JUMP_HOST_ROLE_IDENTIFIER
end

#keysObject



42
43
44
# File 'lib/helpers/instance_ssh.rb', line 42

def keys
  [ssh_key_path]
end

#sshObject



11
12
13
# File 'lib/helpers/instance_ssh.rb', line 11

def ssh
  execute_task(:do_ssh)
end

#ssh_jump_command_to_bastionObject



21
22
23
# File 'lib/helpers/instance_ssh.rb', line 21

def ssh_jump_command_to_bastion
  command = "ssh -o UserKnownHostsFile=/dev/null -i #{ssh_key_path} #{ssh_user}@#{bastion_ip_address}"
end

#ssh_jump_command_to_internal_nodeObject



25
26
27
# File 'lib/helpers/instance_ssh.rb', line 25

def ssh_jump_command_to_internal_node
  command = "ssh -o UserKnownHostsFile=/dev/null -i #{ssh_key_path} -o \"ProxyCommand ssh -W %h:%p -i #{ssh_key_path} #{ssh_user}@#{bastion_ip_address}\" #{ssh_user}@#{ip_address}"
end

#ssh_key_pathObject



38
39
40
# File 'lib/helpers/instance_ssh.rb', line 38

def ssh_key_path
  "~/.ssh/id_rsa" 
end

#ssh_userObject



33
34
35
36
# File 'lib/helpers/instance_ssh.rb', line 33

def ssh_user
  # defined by the environment or we fall back to the local user
  return @environment.ssh_mode_user ? @environment.ssh_mode_user : `whoami`.gsub("\n","")
end