Sha256: 0e8757393a5c0e1f3a0ed08dd3da7b8acc93551edfea4c2007eccb664ceae5b2

Contents?: true

Size: 1.18 KB

Versions: 28

Compression:

Stored size: 1.18 KB

Contents

module Kontena::Cli::Master
  class SshCommand < Kontena::Command

    include Kontena::Cli::Common

    parameter "[COMMANDS] ...", "Run command on host"

    option ["-i", "--identity-file"], "IDENTITY_FILE", "Path to ssh private key"
    option ["-u", "--user"], "USER", "Login as a user", default: "core"

    requires_current_master

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

    def master_provider
      Kontena.run('master config get --return server.provider', returning: :result)
    end

    def execute

      commands_list.insert('--') unless commands_list.empty?

      if master_provider == 'vagrant'
        unless Kontena::PluginManager.instance.plugins.find { |plugin| plugin.name == 'kontena-plugin-vagrant' }
          exit_with_error 'You need to install vagrant plugin to ssh into this node. Use kontena plugin install vagrant'
        end
        cmd = ['vagrant', 'master', 'ssh']
        cmd += commands_list
        Kontena.run(cmd)
      else
        cmd = ['ssh']
        cmd << "#{user}@#{master_host}"
        cmd += ["-i", identity_file] if identity_file
        cmd += commands_list
        exec(*cmd)
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
kontena-cli-1.1.2 lib/kontena/cli/master/ssh_command.rb
kontena-cli-1.1.2.rc2 lib/kontena/cli/master/ssh_command.rb
kontena-cli-1.1.2.rc1 lib/kontena/cli/master/ssh_command.rb
kontena-cli-1.1.1 lib/kontena/cli/master/ssh_command.rb
kontena-cli-1.1.1.rc1 lib/kontena/cli/master/ssh_command.rb
kontena-cli-1.1.0 lib/kontena/cli/master/ssh_command.rb
kontena-cli-1.1.0.rc2 lib/kontena/cli/master/ssh_command.rb
kontena-cli-1.1.0.rc1 lib/kontena/cli/master/ssh_command.rb