Class: Roark::CLI::Create

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/roark/cli/create.rb

Instance Method Summary collapse

Methods included from Shared

#aws, #command_name, #help, #validate_account_ids_format, #validate_required_options

Constructor Details

#initializeCreate

Returns a new instance of Create.



7
8
9
10
# File 'lib/roark/cli/create.rb', line 7

def initialize
  @options = { :account_ids => [], :parameters => {}, :region => 'us-east-1' }
  @logger  = Roark.logger
end

Instance Method Details

#command_summaryObject



77
78
79
# File 'lib/roark/cli/create.rb', line 77

def command_summary
  'Creates an AMI'
end

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/roark/cli/create.rb', line 12

def create
  option_parser.parse!

  validate_required_options [:name, :template]

  

  unless File.exists? @options[:template]
    @logger.error "Template #{@options[:template]} does not exist."
    exit 1
  end

  template = File.read @options[:template]

  ami = Roark::Ami.new :aws => aws, :name => @options[:name]

  ami_create_workflow = Roark::AmiCreateWorkflow.new :account_ids => @options[:account_ids],
                                                     :ami         => ami,
                                                     :template    => template,
                                                     :parameters  => @options[:parameters]
  response = ami_create_workflow.execute

  unless response.success?
    @logger.error response.message
    exit 1
  end

  @logger.info response.message
end

#option_parserObject



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
69
70
71
72
73
74
75
# File 'lib/roark/cli/create.rb', line 42

def option_parser
  OptionParser.new do |opts|
    opts.banner = "Usage: roark create [options]"

    opts.on("-a", "--account_id [ACCOUNT_ID]", "AWS Account ID to Authorize. Can be specified multiple times.") do |o|
      @options[:account_ids] << o
    end

    opts.on("-n", "--name [NAME]", "Name of AMI") do |o|
      @options[:name] = o
    end

    opts.on("-p", "--parameters [PARAMETERS]", "Parameter name and it's value separated by '=' to pass to Cloud Formation. Can be specified multiple times.") do |o|
      data = o.split('=')
      @options[:parameters].merge!({ data.first => data[1] })
    end

    opts.on("-r", "--region [REGION]", "Region to build AMI") do |o|
      @options[:region] = o
    end

    opts.on("-t", "--template [TEMPLATE]", "Path to Cloud Formation template") do |o|
      @options[:template] = o
    end

    opts.on("--aws-access-key [KEY]", "AWS Access Key") do |o|
      @options[:aws_access_key] = o
    end

    opts.on("--aws-secret-key [KEY]", "AWS Secret Key") do |o|
      @options[:aws_secret_key] = o
    end
  end
end