chef-metal-fog 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2278f6624a0634e205da58bcc1e966b22eab39cf
4
- data.tar.gz: a1f4213a340ec309ef22d4fa141262f367e379d0
3
+ metadata.gz: 3a9bcbbde03df9f791812bb29c97ed699293eb6b
4
+ data.tar.gz: a380ea7aa17ba04c859e8f99b9273a061a3d8020
5
5
  SHA512:
6
- metadata.gz: dd9e876567aaf22364a1e12efd5747464ecea0722e9758a5866feb4bb0877d3fd4a9bdc7799aa31b18c67c79c4c5b1fdc517e550812b9ea8fda7315feaaef050
7
- data.tar.gz: 9a4b72747673099393f9571bc81492b951c901e6b5773a6cb2d6918fa0dfc17f14b7ca03e078d673660dbc72ea7bec6b3a4f84da0833563f3c3b88640ea70db5
6
+ metadata.gz: e9809ef6a59ef830a3a979750c77dace55ae8d110c7472ddfab6f98725fb666c19f168a46663da8efc5ce8851c97d475694112085e99847597c4a907160f20d3
7
+ data.tar.gz: 30aaca87722bd80626ac23dba4c784b4a7280339dea19605094ecd4526258d64796fb2f7faa997c8d19a98623f6116fa67705ab15d0399f85df797647b6e5e28
@@ -26,4 +26,9 @@ class Chef::Resource::FogKeyPair < Chef::Resource::LWRPBase
26
26
  def after(&block)
27
27
  block ? @after = block : @after
28
28
  end
29
+
30
+ # We are not interested in Chef's cloning behavior here.
31
+ def load_prior_resource
32
+ Chef::Log.debug("Overloading #{resource_name}.load_prior_resource with NOOP")
33
+ end
29
34
  end
@@ -131,70 +131,66 @@ module ChefMetalFog
131
131
  # ENV['AWS_PROFILE']
132
132
  # ENV['DEFAULT_PROFILE']
133
133
  # 'default'
134
- aws_profile = if compute_options[:aws_access_key_id]
135
- Chef::Log.debug("Using AWS driver access key options")
136
- {
137
- :aws_access_key_id => compute_options[:aws_access_key_id],
138
- :aws_secret_access_key => compute_options[:aws_secret_access_key],
139
- :aws_security_token => compute_options[:aws_session_token],
140
- :region => compute_options[:region]
141
- }
142
- elsif driver_options[:aws_profile]
143
- Chef::Log.debug("Using AWS profile #{driver_options[:aws_profile]}")
144
- aws_credentials[driver_options[:aws_profile]]
145
- elsif ENV['AWS_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY']
146
- Chef::Log.debug("Using AWS environment variable access keys")
147
- {
148
- :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY'],
149
- :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AWS_SECRET_KEY'],
150
- :aws_security_token => ENV['AWS_SECURITY_TOKEN'],
151
- :region => ENV['AWS_REGION']
152
- }
153
- elsif ENV['AWS_PROFILE']
154
- Chef::Log.debug("Using AWS profile #{ENV['AWS_PROFILE']} from AWS_PROFILE environment variable")
155
- aws_credentials[ENV['AWS_PROFILE']]
156
- else
157
- Chef::Log.debug("Using AWS default profile")
158
- aws_credentials.default
134
+ if compute_options[:aws_access_key_id]
135
+ Chef::Log.debug("Using AWS driver access key options")
136
+ aws_profile = {
137
+ :aws_access_key_id => compute_options[:aws_access_key_id],
138
+ :aws_secret_access_key => compute_options[:aws_secret_access_key],
139
+ :aws_security_token => compute_options[:aws_session_token],
140
+ :region => compute_options[:region]
141
+ }
142
+ elsif driver_options[:aws_profile]
143
+ Chef::Log.debug("Using AWS profile #{driver_options[:aws_profile]}")
144
+ aws_profile = aws_credentials[driver_options[:aws_profile]]
145
+ elsif ENV['AWS_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY']
146
+ Chef::Log.debug("Using AWS environment variable access keys")
147
+ aws_profile = {
148
+ :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY'],
149
+ :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] || ENV['AWS_SECRET_KEY'],
150
+ :aws_security_token => ENV['AWS_SECURITY_TOKEN'],
151
+ :region => ENV['AWS_REGION']
152
+ }
153
+ elsif ENV['AWS_PROFILE']
154
+ Chef::Log.debug("Using AWS profile #{ENV['AWS_PROFILE']} from AWS_PROFILE environment variable")
155
+ aws_profile = aws_credentials[ENV['AWS_PROFILE']]
156
+ if !aws_profile
157
+ raise "Environment variable AWS_PROFILE is set to #{ENV['AWS_PROFILE'].inspect} but your AWS config file does not contain that profile!"
159
158
  end
160
- # Endpoint configuration
161
- if compute_options[:ec2_endpoint]
162
- aws_profile[:ec2_endpoint] = compute_options[:ec2_endpoint]
163
- elsif ENV['EC2_URL']
164
- aws_profile[:ec2_endpoint] = ENV['EC2_URL']
165
- end
166
- if compute_options[:iam_endpoint]
167
- aws_profile[:iam_endpoint] = compute_options[:iam_endpoint]
168
- elsif ENV['AWS_IAM_URL']
169
- aws_profile[:iam_endpoint] = ENV['AWS_IAM_URL']
170
159
  else
171
- aws_profile[:iam_endpoint] = "https://iam.amazonaws.com/"
160
+ Chef::Log.debug("Using AWS default profile")
161
+ aws_profile = aws_credentials.default
172
162
  end
173
163
 
164
+ default_ec2_endpoint = compute_options[:ec2_endpoint] || ENV['EC2_URL']
165
+ default_iam_endpoint = compute_options[:iam_endpoint] || ENV['AWS_IAM_URL']
166
+
174
167
  # Merge in account info for profile
175
168
  if aws_profile
176
- aws_profile = aws_profile.merge(aws_account_info_for(aws_profile))
169
+ aws_profile = aws_profile.merge(aws_account_info_for(aws_profile, default_iam_endpoint))
177
170
  end
178
171
 
179
172
  # If no profile is found (or the profile is not the right account), search
180
173
  # for a profile that matches the given account ID
181
174
  if aws_account_id && (!aws_profile || aws_profile[:aws_account_id] != aws_account_id)
182
- aws_profile = find_aws_profile_for_account_id(aws_credentials, aws_account_id)
175
+ aws_profile = find_aws_profile_for_account_id(aws_credentials, aws_account_id, iam_endpoint)
183
176
  end
184
177
 
185
178
  if !aws_profile
186
179
  raise "No AWS profile specified! Are you missing something in the Chef config or ~/.aws/config?"
187
180
  end
188
181
 
182
+ aws_profile[:ec2_endpoint] ||= default_ec2_endpoint
183
+ aws_profile[:iam_endpoint] ||= default_iam_endpoint
184
+
189
185
  aws_profile.delete_if { |key, value| value.nil? }
190
186
  aws_profile
191
187
  end
192
188
 
193
- def self.find_aws_profile_for_account_id(aws_credentials, aws_account_id)
189
+ def self.find_aws_profile_for_account_id(aws_credentials, aws_account_id, default_iam_endpoint=nil)
194
190
  aws_profile = nil
195
191
  aws_credentials.each do |profile_name, profile|
196
192
  begin
197
- aws_account_info = aws_account_info_for(profile)
193
+ aws_account_info = aws_account_info_for(profile, default_iam_endpoint)
198
194
  rescue
199
195
  Chef::Log.warn("Could not connect to AWS profile #{aws_credentials[:name]}: #{$!}")
200
196
  Chef::Log.debug($!.backtrace.join("\n"))
@@ -215,18 +211,23 @@ module ChefMetalFog
215
211
  aws_profile
216
212
  end
217
213
 
218
- def self.aws_account_info_for(aws_profile)
214
+ def self.aws_account_info_for(aws_profile, default_iam_endpoint = nil)
215
+ iam_endpoint = aws_profile[:iam_endpoint] || default_iam_endpoint
216
+
219
217
  @@aws_account_info ||= {}
220
218
  @@aws_account_info[aws_profile[:aws_access_key_id]] ||= begin
221
219
  options = {
220
+ # Endpoint configuration
222
221
  :aws_access_key_id => aws_profile[:aws_access_key_id],
223
222
  :aws_secret_access_key => aws_profile[:aws_secret_access_key],
224
- :aws_session_token => aws_profile[:aws_security_token],
225
- :host => URI(aws_profile[:iam_endpoint]).host,
226
- :scheme => URI(aws_profile[:iam_endpoint]).scheme,
227
- :port => URI(aws_profile[:iam_endpoint]).port,
228
- :path => URI(aws_profile[:iam_endpoint]).path
223
+ :aws_session_token => aws_profile[:aws_security_token]
229
224
  }
225
+ if iam_endpoint
226
+ options[:host] = URI(iam_endpoint).host
227
+ options[:scheme] = URI(iam_endpoint).scheme
228
+ options[:port] = URI(iam_endpoint).port
229
+ options[:path] = URI(iam_endpoint).path
230
+ end
230
231
  options.delete_if { |key, value| value.nil? }
231
232
 
232
233
  iam = Fog::AWS::IAM.new(options)
@@ -311,6 +312,10 @@ module ChefMetalFog
311
312
  new_config[:driver_options][:aws_account_info] = account_info
312
313
  id = "#{account_info[:aws_account_id]}:#{result[:driver_options][:compute_options][:region]}"
313
314
 
315
+ # Make sure we're using a reasonable default AMI, for now this is Ubuntu 14.04 LTS
316
+ result[:machine_options][:bootstrap_options][:image_id] ||=
317
+ default_ami_for_region(result[:driver_options][:compute_options][:region])
318
+
314
319
  [result, id]
315
320
  end
316
321
 
@@ -343,6 +348,31 @@ module ChefMetalFog
343
348
  end
344
349
  result
345
350
  end
351
+
352
+ private
353
+ def self.default_ami_for_region(region)
354
+ Chef::Log.debug("Choosing default AMI for region '#{region}'")
355
+
356
+ case region
357
+ when 'ap-northeast-1'
358
+ 'ami-c786dcc6'
359
+ when 'ap-southeast-1'
360
+ 'ami-eefca7bc'
361
+ when 'ap-southeast-2'
362
+ 'ami-996706a3'
363
+ when 'eu-west-1'
364
+ 'ami-4ab46b3d'
365
+ when 'sa-east-1'
366
+ 'ami-6770d87a'
367
+ when 'us-east-1'
368
+ 'ami-d2ff23ba'
369
+ when 'us-west-1'
370
+ 'ami-73717d36'
371
+ when 'us-west-2'
372
+ 'ami-f1ce8bc1'
373
+ end
374
+ end
375
+
346
376
  end
347
377
  end
348
378
  end
@@ -50,6 +50,18 @@ module ChefMetalFog
50
50
  bootstrap_options
51
51
  end
52
52
 
53
+ def destroy_machine(action_handler, machine_spec, machine_options)
54
+ server = server_for(machine_spec)
55
+ if server && server.state != 'archive'
56
+ action_handler.perform_action "destroy machine #{machine_spec.name} (#{machine_spec.location['server_id']} at #{driver_url})" do
57
+ server.destroy
58
+ end
59
+ end
60
+ machine_spec.location = nil
61
+ strategy = convergence_strategy_for(machine_spec, machine_options)
62
+ strategy.cleanup_convergence(action_handler, machine_spec)
63
+ end
64
+
53
65
  def self.compute_options_for(provider, id, config)
54
66
  new_compute_options = {}
55
67
  new_compute_options[:provider] = provider
@@ -1,3 +1,3 @@
1
1
  module ChefMetalFog
2
- VERSION = '0.8'
2
+ VERSION = '0.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-metal-fog
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.8'
4
+ version: '0.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2014-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef