Skip to content

Commit

Permalink
allow to specify ami via opts (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakolehm authored Mar 29, 2018
1 parent 08aba2d commit 3dc3b69
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/kontena/machine/aws/master_provisioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ def run!(opts)
end
end

ami = resolve_ami(region)
abort('No valid AMI found for region') unless ami
if opts[:ami]
ami = opts[:ami]
else
ami = resolve_ami(region)
abort('No valid AMI found for region') unless ami
end
opts[:vpc] = default_vpc.vpc_id unless opts[:vpc]

raise "Missing :subnet option" if opts[:subnet].nil?
Expand Down
8 changes: 6 additions & 2 deletions lib/kontena/machine/aws/node_provisioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ def initialize(api_client, access_key_id, secret_key, region)

# @param [Hash] opts
def run!(opts)
ami = resolve_ami(region)
abort('No valid AMI found for region') unless ami
if opts[:ami]
ami = opts[:ami]
else
ami = resolve_ami(region)
abort('No valid AMI found for region') unless ami
end

opts[:vpc] = default_vpc.vpc_id unless opts[:vpc]

Expand Down
4 changes: 3 additions & 1 deletion lib/kontena/plugin/aws/master/create_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CreateCommand < Kontena::Command
option "--vault-secret", "VAULT_SECRET", "Secret key for Vault (default: generate random secret)"
option "--vault-iv", "VAULT_IV", "Initialization vector for Vault (default: generate random iv)"
option "--mongodb-uri", "URI", "External MongoDB uri (optional)"
option "--ami", "AMI", "Which Container Linux AMI to use (default: latest stable)"

def execute
require 'securerandom'
Expand All @@ -33,7 +34,8 @@ def execute
mongodb_uri: mongodb_uri,
associate_public_ip: associate_public_ip?,
security_groups: security_groups,
initial_admin_code: SecureRandom.hex(16)
initial_admin_code: SecureRandom.hex(16),
ami: ami
)
rescue Seahorse::Client::NetworkingError => ex
raise ex unless ex.message.match(/certificate verify failed/)
Expand Down
4 changes: 3 additions & 1 deletion lib/kontena/plugin/aws/nodes/create_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CreateCommand < Kontena::Command
include Kontena::Plugin::Aws::Prompts::Common

option "--count", "COUNT", "How many instances to create"
option "--ami", "AMI", "Which Container Linux AMI to use (default: latest stable)"

requires_current_master

Expand All @@ -33,7 +34,8 @@ def execute
key_pair: key_pair,
count: count,
associate_public_ip: associate_public_ip?,
security_groups: security_groups
security_groups: security_groups,
ami: ami
)
rescue Seahorse::Client::NetworkingError => ex
raise ex unless ex.message.match(/certificate verify failed/)
Expand Down

0 comments on commit 3dc3b69

Please sign in to comment.