class Kontena::Cli::Master::SshCommand

Public Instance Methods

execute() click to toggle source
# File lib/kontena/cli/master/ssh_command.rb, line 68
def execute
  master_is_vagrant? ? run_vagrant_ssh : run_ssh
end
master_host() click to toggle source
# 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?() click to toggle source
# 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?() click to toggle source
# 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_ssh() click to toggle source
# 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_ssh() click to toggle source
# 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?() click to toggle source
# File lib/kontena/cli/master/ssh_command.rb, line 30
def vagrant_plugin_installed?
  Kontena::PluginManager::Common.installed?('vagrant')
end