Class: Stemcell::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/stemcell/command_line.rb

Constant Summary collapse

VERSION_STRING =
"Stemcell #{VERSION} (c) 2012-2016 Airbnb."
"Launch instances from metadata stored in roles!\n" \
"Usage: stemcell [chef role] [options]"
OPTION_PARSER_DEFAULTS =
{
  'non_interactive' => false,
  'aws_creds'       => 'default',
  'ssh_user'        => 'ubuntu'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chef_roleObject (readonly)

Returns the value of attribute chef_role.



9
10
11
# File 'lib/stemcell/command_line.rb', line 9

def chef_role
  @chef_role
end

#chef_rootObject (readonly)

Returns the value of attribute chef_root.



8
9
10
# File 'lib/stemcell/command_line.rb', line 8

def chef_root
  @chef_root
end

#launcherObject (readonly)

Returns the value of attribute launcher.



6
7
8
# File 'lib/stemcell/command_line.rb', line 6

def launcher
  @launcher
end

#showing_helpObject (readonly)

Returns the value of attribute showing_help.



7
8
9
# File 'lib/stemcell/command_line.rb', line 7

def showing_help
  @showing_help
end

Class Method Details

.run!Object



21
22
23
# File 'lib/stemcell/command_line.rb', line 21

def self.run!
  CommandLine.new.run!
end

Instance Method Details

#run!Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/stemcell/command_line.rb', line 25

def run!
  determine_root_and_showing_help

  initialize_launcher
  retrieve_defaults
  configure_option_parser

  options = parse_options_or_print_help
  determine_role(options)

  print_usage_and_exit unless chef_role
  # If we didn't successfully initialize the launcher, we should exit.
  exit unless @launcher

  print_version
  display_chef_repo_warnings

  # Retrieve AWS credentials via the aws-creds gems (if available)
  awc_name = options.delete('aws_creds')
  credentials = retrieve_credentials_from_awc(awc_name)
  options.merge!(credentials) if credentials
  # Move launcher in the non-interactive mode (if requested)
  launcher.interactive = !options.delete('non_interactive')

  instances = launch_instance(chef_role, options)
  tail_converge(instances, options) if options['tail']

  puts "\nDone.\n".green
end