Sha256: 3a65d509d76c255a43f594bce6bc71a396b6892a69b8ea0b5f55acac311f67d3

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 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!(%w(master config get --return server.provider))
    end

    def execute
      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

2 entries across 2 versions & 1 rubygems

Version Path
kontena-cli-1.3.0.pre2 lib/kontena/cli/master/ssh_command.rb
kontena-cli-1.3.0.pre1 lib/kontena/cli/master/ssh_command.rb