Class: Phase::CLI::SSH

Inherits:
Command show all
Defined in:
lib/phase/cli/ssh.rb

Direct Known Subclasses

Mosh

Constant Summary collapse

DEFAULT_CONNECTION_STRING =
"ssh -A".freeze

Instance Attribute Summary collapse

Attributes inherited from Command

#args, #options

Instance Method Summary collapse

Methods inherited from Command

#initialize

Methods included from Util::Console

#ask, #fail, #log

Constructor Details

This class inherits a constructor from Phase::CLI::Command

Instance Attribute Details

#instance=(value) ⇒ Object

Sets the attribute instance

Parameters:

  • value

    the value to set the attribute instance to.



23
24
25
# File 'lib/phase/cli/ssh.rb', line 23

def instance=(value)
  @instance = value
end

#username=(value) ⇒ Object

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



23
24
25
# File 'lib/phase/cli/ssh.rb', line 23

def username=(value)
  @username = value
end

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/phase/cli/ssh.rb', line 25

def run
  parse_connection_string
  ssh_command = args.last if args.count > 1

  if ssh_command
    # Force pseudo-tty allocation for remote console/tail tasks
    options.conn = "ssh -At" if options.conn == DEFAULT_CONNECTION_STRING

    log "running on instance #{ instance.resource.id }: `#{ ssh_command }'"
    exec "#{ options.conn } #{ username }@#{ instance.resource.dns_name } #{ ssh_command }"
  else
    log "connecting to instance #{ instance.resource.id }..."
    exec "#{ options.conn } #{ username }@#{ instance.resource.dns_name }"
  end
end