Class: Kontena::Cli::Master::SshCommand

Inherits:
Kontena::Command show all
Includes:
Common
Defined in:
lib/kontena/cli/master/ssh_command.rb

Instance Attribute Summary

Attributes inherited from Kontena::Command

#arguments, #exit_code, #result

Instance Method Summary collapse

Methods included from Common

#access_token=, #add_master, #any_key_to_continue, #any_key_to_continue_with_timeout, #api_url, #api_url=, #caret, #clear_current_grid, #client, #cloud_auth?, #cloud_client, #config, #confirm, #confirm_command, #current_grid, #current_master_index, #debug?, #display_account_login_info, #display_login_info, display_logo, #display_master_login_info, #error, exit_with_error, #kontena_account, #logger, #pastel, #print, #prompt, #puts, #require_api_url, #require_token, #reset_client, #reset_cloud_client, #running_quiet?, #running_silent?, #running_verbose?, #spin_if, #spinner, #sprint, #sputs, #stdin_input, #use_refresh_token, #vfakespinner, #vputs, #vspinner, #warning

Methods inherited from Kontena::Command

banner, callback_matcher, #help_requested?, inherited, #instance, load_subcommand, requires_current_account_token, requires_current_account_token?, requires_current_grid, requires_current_grid?, requires_current_master, requires_current_master?, requires_current_master_token, requires_current_master_token?, #run, #run_callbacks, #verify_current_account_token, #verify_current_grid, #verify_current_master, #verify_current_master_token

Instance Method Details

#executeObject



68
69
70
# File 'lib/kontena/cli/master/ssh_command.rb', line 68

def execute
  master_is_vagrant? ? run_vagrant_ssh : run_ssh
end

#master_hostObject



16
17
18
19
# File 'lib/kontena/cli/master/ssh_command.rb', line 16

def master_host
  require 'uri'
  URI.parse(current_master.url).host
end

#master_is_vagrant?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kontena/cli/master/ssh_command.rb', line 34

def master_is_vagrant?
  if master_provider_vagrant?
    unless vagrant_plugin_installed?
      exit_with_error 'You need to install vagrant plugin to ssh into this master. Use: kontena plugin install vagrant'
    end
    logger.debug { "Master config server.provider is vagrant" }
    true
  elsif vagrant_plugin_installed? && current_master.url.include?('192.168.66.')
    logger.debug { "Vagrant plugin installed and current_master url looks like vagrant" }
    true
  else
    logger.debug { "Assuming non-vagrant master host" }
    false
  end
end

#master_provider_vagrant?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/kontena/cli/master/ssh_command.rb', line 21

def master_provider_vagrant?
  require 'kontena/cli/master/config/get_command'
  cmd = Kontena::Cli::Master::Config::GetCommand.new([])
  cmd.parse(['server.provider'])
  cmd.response['server.provider'] == 'vagrant'
rescue => ex
  false
end

#run_sshObject



50
51
52
53
54
55
56
57
# File 'lib/kontena/cli/master/ssh_command.rb', line 50

def run_ssh
  cmd = ['ssh']
  cmd << "#{user}@#{master_host}"
  cmd += ["-i", identity_file] if identity_file
  cmd += commands_list
  logger.debug { "Executing #{cmd.inspect}" }
  exec(*cmd)
end

#run_vagrant_sshObject



59
60
61
62
63
64
65
66
# File 'lib/kontena/cli/master/ssh_command.rb', line 59

def run_vagrant_ssh
  cmd = %w(vagrant master ssh)
  unless commands_list.empty?
    cmd << '--'
    cmd.concat commands_list
  end
  Kontena.run!(cmd)
end

#vagrant_plugin_installed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/kontena/cli/master/ssh_command.rb', line 30

def vagrant_plugin_installed?
  Kontena::PluginManager::Common.installed?('vagrant')
end