Skip to content

Commit

Permalink
insert a bootstrap helper for customization
Browse files Browse the repository at this point in the history
so that drivers can add additional bootstrapping options
  • Loading branch information
Thom May committed Jun 16, 2014
1 parent ebc499b commit ae0540d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
8 changes: 5 additions & 3 deletions lib/chef_metal_fog/fog_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,13 @@ def overwrite_default_key_willy_nilly(action_handler)
'metal_default'
end

def bootstrap_helper(action_handler, machine_spec, machine_options, bootstrap_options)

This comment has been minimized.

Copy link
@jkeiser

jkeiser Jun 16, 2014

Hmm, I think you had it right before, especially since not all providers will implement tags. Maybe the sweet spot is to have some helper methods like protected default_tags?

Partly this is just me trying to deal with my personal issues around methods named "helper" :)

This comment has been minimized.

Copy link
@thommay

thommay Jun 17, 2014

Owner

So the problem is that some drivers will extensively rewrite bootstrap_options_for and some will not touch it. I played around with overriding the method and calling super, but that turns into some unpleasant contortions. (I hate calling methods "helper", but I really couldn't think of a better name in this instance).
I'll play with breaking the flow into methods and see what that's like, and I'll try and avoid calling any of them "helper"...

bootstrap_options
end

def bootstrap_options_for(action_handler, machine_spec, machine_options)
bootstrap_options = symbolize_keys(machine_options[:bootstrap_options] || {})
if provider == 'AWS' && !bootstrap_options[:key_name]
bootstrap_options[:key_name] = overwrite_default_key_willy_nilly(action_handler)
end
bootstrap_options = bootstrap_helper(action_handler, machine_spec, machine_options, bootstrap_options)
tags = {
'Name' => machine_spec.name,
'BootstrapId' => machine_spec.id,
Expand Down
7 changes: 7 additions & 0 deletions lib/chef_metal_fog/providers/aws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def default_ssh_username
'ubuntu'
end

def bootstrap_helper(action_handler, machine_spec, machine_options, bootstrap_options)
unless bootstrap_options[:key_name]
bootstrap_options[:key_name] = overwrite_default_key_willy_nilly(action_handler)
end
bootstrap_options
end

def self.get_aws_profile(driver_options, aws_account_id)
aws_credentials = get_aws_credentials(driver_options)
compute_options = driver_options[:compute_options] || {}
Expand Down
13 changes: 1 addition & 12 deletions lib/chef_metal_fog/providers/digitalocean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,11 @@ def creator
''
end

def bootstrap_options_for(action_handler, machine_spec, machine_options)
bootstrap_options = symbolize_keys(machine_options[:bootstrap_options] || {})
def bootstrap_helper(action_handler, machine_spec, machine_options, bootstrap_options)
unless bootstrap_options[:key_name]
bootstrap_options[:key_name] = overwrite_default_key_willy_nilly(action_handler)
end

tags = {
'Name' => machine_spec.name,
'BootstrapId' => machine_spec.id,
'BootstrapHost' => Socket.gethostname,
'BootstrapUser' => Etc.getlogin
}
# User-defined tags override the ones we set
tags.merge!(bootstrap_options[:tags]) if bootstrap_options[:tags]
bootstrap_options.merge!({ :tags => tags })

if !bootstrap_options[:image_id]
bootstrap_options[:image_name] ||= 'CentOS 6.4 x32'
bootstrap_options[:image_id] = compute.images.select { |image| image.name == bootstrap_options[:image_name] }.first.id
Expand Down

0 comments on commit ae0540d

Please sign in to comment.