Class: Ec2Ssh::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/ec2-ssh/cli.rb

Defined Under Namespace

Modules: Aws, Ssh, Utils

Instance Method Summary collapse

Instance Method Details

#connectObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ec2-ssh/cli.rb', line 33

def connect
  extend Aws
  extend Ssh
  extend Utils

  set_ssh(options[:user])
  aws_init(options[:profile], options[:region])
    
  if options[:as]
    get_auto_scale_groups
  elsif options[:tag_value]
    get_instances(options[:tag_key].chomp, options[:tag_value].chomp)
  end
  
  if options[:terminal]
    open_in_terminal
  else

    if options[:parallel] && options[:sequence]
      say "You can't run both in sequence and in parallel at the same time"
      exit 1
    end

    mode = :parallel if options[:parallel] || mode.nil?
    mode = :groups   if options[:groups]
    mode = :sequence if options[:sequence]

    dsl_options = {}
    dsl_options[:in] = mode
    dsl_options[:wait]  = options[:wait] if options[:wait]
    dsl_options[:limit] = options[:groups_limit] if options[:groups_limit]
    
    say "user: #{options[:user]}\ndsl_options: #{dsl_options}\ncmd: #{options[:cmd]}", color = :cyan
    ssh_to(options[:user], dsl_options, options[:cmd])
  end
end

#versionObject



72
73
74
# File 'lib/ec2-ssh/cli.rb', line 72

def version
  say Ec2Ssh::ABOUT, color = :green
end