chef-provisioning-aws 0.1.3 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chef/provider/aws_s3_bucket.rb +36 -26
- data/lib/chef/provider/aws_subnet.rb +52 -0
- data/lib/chef/provisioning/aws_driver/driver.rb +224 -22
- data/lib/chef/provisioning/aws_driver/resources.rb +1 -1
- data/lib/chef/provisioning/aws_driver/version.rb +1 -1
- data/lib/chef/resource/aws_s3_bucket.rb +2 -0
- data/lib/chef/resource/aws_subnet.rb +25 -0
- metadata +19 -18
- data/lib/chef/resource/.DS_Store +0 -0
- data/lib/chef/resource/aws_ebs_mount.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4f9c82b6a8923c933077a7055cc31c083291527
|
4
|
+
data.tar.gz: 886d034e57402dacb17d143c1e18e9bb94129a99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21596d7e34ff111450d05400eb681844bf8321a1721d409020c5ab7227591f333ff9eb9799b8f4b98526a888a75b5ba066e66026226787c0546477aa7873d65f
|
7
|
+
data.tar.gz: d32aa0894bb97de809bc3bea3ba855c1820cb2aca2208e3a1276b1c00d83ce90ad689cc05b4be90706b3f49c2788e015834c455e7c8ad2bd5d85d8a73deea0b9
|
@@ -7,23 +7,22 @@ class Chef::Provider::AwsS3Bucket < Chef::Provider::AwsProvider
|
|
7
7
|
converge_by "Creating new S3 bucket #{fqn}" do
|
8
8
|
bucket = s3.buckets.create(fqn)
|
9
9
|
bucket.tags['Name'] = new_resource.name
|
10
|
-
if new_resource.enable_website_hosting
|
11
|
-
bucket.website_configuration = AWS::S3::WebsiteConfiguration.new(
|
12
|
-
new_resource.website_options)
|
13
|
-
end
|
14
10
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
end
|
12
|
+
|
13
|
+
if modifies_website_configuration?
|
14
|
+
if new_resource.enable_website_hosting
|
15
|
+
converge_by "Setting website configuration for bucket #{fqn}" do
|
19
16
|
existing_bucket.website_configuration = AWS::S3::WebsiteConfiguration.new(
|
20
17
|
new_resource.website_options)
|
21
|
-
|
22
|
-
|
18
|
+
end
|
19
|
+
else
|
20
|
+
converge_by "Disabling website configuration for bucket #{fqn}" do
|
21
|
+
existing_bucket.website_configuration = nil
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
26
|
-
|
25
|
+
new_resource.endpoint "#{fqn}.s3-website-#{s3_website_endpoint_region}.amazonaws.com"
|
27
26
|
new_resource.save
|
28
27
|
end
|
29
28
|
|
@@ -37,31 +36,42 @@ class Chef::Provider::AwsS3Bucket < Chef::Provider::AwsProvider
|
|
37
36
|
new_resource.delete
|
38
37
|
end
|
39
38
|
|
40
|
-
|
41
39
|
def existing_bucket
|
42
40
|
Chef::Log.debug("Checking for S3 bucket #{fqn}")
|
43
41
|
@existing_bucket ||= s3.buckets[fqn] if s3.buckets[fqn].exists?
|
44
42
|
end
|
45
43
|
|
46
|
-
def
|
47
|
-
if existing_bucket.website_configuration == nil
|
48
|
-
new_resource.enable_website_hosting
|
49
|
-
else
|
50
|
-
!new_resource.enable_website_hosting ||
|
51
|
-
!compare_website_configuration
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def compare_website_configuration
|
44
|
+
def modifies_website_configuration?
|
56
45
|
# This is incomplete, routing rules have many optional values, so its
|
57
46
|
# possible aws will put in default values for those which won't be in
|
58
47
|
# the requested config.
|
59
48
|
new_web_config = new_resource.website_options
|
60
|
-
current_web_config =
|
49
|
+
current_web_config = current_website_configuration
|
50
|
+
|
51
|
+
!!existing_bucket.website_configuration != new_resource.enable_website_hosting ||
|
52
|
+
(current_web_config[:index_document] != new_web_config.fetch(:index_document, {}) ||
|
53
|
+
current_web_config[:error_document] != new_web_config.fetch(:error_document, {}) ||
|
54
|
+
current_web_config[:routing_rules] != new_web_config.fetch(:routing_rules, []))
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
def current_website_configuration
|
58
|
+
if existing_bucket.website_configuration
|
59
|
+
existing_bucket.website_configuration.to_hash
|
60
|
+
else
|
61
|
+
{}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def s3_website_endpoint_region
|
66
|
+
# ¯\_(ツ)_/¯
|
67
|
+
case existing_bucket.location_constraint
|
68
|
+
when nil, 'US'
|
69
|
+
'us-east-1'
|
70
|
+
when 'EU'
|
71
|
+
'eu-west-1'
|
72
|
+
else
|
73
|
+
existing_bucket.location_constraint
|
74
|
+
end
|
65
75
|
end
|
66
76
|
|
67
77
|
# Fully qualified bucket name (i.e resource_region unless otherwise specified)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'chef/provider/aws_provider'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
class Chef::Provider::AwsSubnet < Chef::Provider::AwsProvider
|
5
|
+
|
6
|
+
action :create do
|
7
|
+
fail "Can't create a Subnet without a CIDR block" if new_resource.cidr_block.nil?
|
8
|
+
|
9
|
+
if existing_subnet == nil
|
10
|
+
converge_by "Creating new Subnet #{fqn} in VPC #{new_resource.vpc} in #{new_resource.region_name}" do
|
11
|
+
opts = { :vpc => vpc_id }
|
12
|
+
opts[:availability_zone] = new_resource.availability_zone if new_resource.availability_zone
|
13
|
+
subnet = ec2.subnets.create(new_resource.cidr_block, opts)
|
14
|
+
subnet.tags['Name'] = new_resource.name
|
15
|
+
subnet.tags['VPC'] = new_resource.vpc
|
16
|
+
new_resource.subnet_id subnet.id
|
17
|
+
new_resource.save
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
action :delete do
|
23
|
+
if existing_subnet
|
24
|
+
converge_by "Deleting subnet #{fqn} in VPC #{new_resource.vpc} in #{new_resource.region_name}" do
|
25
|
+
existing_subnet.delete
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
new_resource.delete
|
30
|
+
end
|
31
|
+
|
32
|
+
def vpc_id
|
33
|
+
@vpc_id ||= begin
|
34
|
+
ec2.vpcs.with_tag('Name', new_resource.vpc).first
|
35
|
+
rescue
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def existing_subnet
|
41
|
+
@subnet_id ||= begin
|
42
|
+
ec2.subnets.with_tag('Name', new_resource.name).first
|
43
|
+
rescue
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def id
|
49
|
+
new_resource.subnet_id
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -15,7 +15,8 @@ require 'chef/provisioning/aws_driver/credentials'
|
|
15
15
|
|
16
16
|
require 'yaml'
|
17
17
|
require 'aws-sdk-v1'
|
18
|
-
|
18
|
+
# loads the entire aws-sdk
|
19
|
+
AWS.eager_autoload!
|
19
20
|
|
20
21
|
class Chef
|
21
22
|
module Provisioning
|
@@ -28,7 +29,7 @@ module AWSDriver
|
|
28
29
|
attr_reader :region
|
29
30
|
|
30
31
|
# URL scheme:
|
31
|
-
# aws:
|
32
|
+
# aws:profilename:region
|
32
33
|
# TODO: migration path from fog:AWS - parse that URL
|
33
34
|
# canonical URL calls realpath on <path>
|
34
35
|
def self.from_url(driver_url, config)
|
@@ -37,17 +38,21 @@ module AWSDriver
|
|
37
38
|
|
38
39
|
def initialize(driver_url, config)
|
39
40
|
super
|
40
|
-
|
41
|
-
|
41
|
+
|
42
|
+
_, profile_name, region = driver_url.split(':')
|
43
|
+
profile_name = nil if profile_name && profile_name.empty?
|
44
|
+
region = nil if region && region.empty?
|
45
|
+
|
46
|
+
credentials = profile_name ? aws_credentials[profile_name] : aws_credentials.default
|
47
|
+
@region = region || credentials[:region]
|
42
48
|
# TODO: fix credentials here
|
43
49
|
AWS.config(:access_key_id => credentials[:aws_access_key_id],
|
44
50
|
:secret_access_key => credentials[:aws_secret_access_key],
|
45
|
-
:region =>
|
51
|
+
:region => @region)
|
46
52
|
end
|
47
53
|
|
48
54
|
def self.canonicalize_url(driver_url, config)
|
49
|
-
|
50
|
-
[ "aws:#{url}", config ]
|
55
|
+
[ driver_url, config ]
|
51
56
|
end
|
52
57
|
|
53
58
|
|
@@ -200,12 +205,61 @@ module AWSDriver
|
|
200
205
|
|
201
206
|
# Image methods
|
202
207
|
def allocate_image(action_handler, image_spec, image_options, machine_spec)
|
208
|
+
actual_image = image_for(image_spec)
|
209
|
+
if actual_image.nil? || !actual_image.exists? || actual_image.state == :failed
|
210
|
+
action_handler.perform_action "Create image #{image_spec.name} from machine #{machine_spec.name} with options #{image_options.inspect}" do
|
211
|
+
image_options[:name] ||= image_spec.name
|
212
|
+
image_options[:instance_id] ||= machine_spec.location['instance_id']
|
213
|
+
image_options[:description] ||= "Image #{image_spec.name} created from machine #{machine_spec.name}"
|
214
|
+
Chef::Log.debug "AWS Image options: #{image_options.inspect}"
|
215
|
+
image = ec2.images.create(image_options)
|
216
|
+
image_spec.location = {
|
217
|
+
'driver_url' => driver_url,
|
218
|
+
'driver_version' => Chef::Provisioning::AWSDriver::VERSION,
|
219
|
+
'image_id' => image.id,
|
220
|
+
'allocated_at' => Time.now.to_i
|
221
|
+
}
|
222
|
+
image_spec.machine_options ||= {}
|
223
|
+
image_spec.machine_options.merge!({
|
224
|
+
:bootstrap_options => {
|
225
|
+
:image_id => image.id
|
226
|
+
}
|
227
|
+
})
|
228
|
+
end
|
229
|
+
end
|
203
230
|
end
|
204
231
|
|
205
232
|
def ready_image(action_handler, image_spec, image_options)
|
233
|
+
actual_image = image_for(image_spec)
|
234
|
+
if actual_image.nil? || !actual_image.exists?
|
235
|
+
raise 'Cannot ready an image that does not exist'
|
236
|
+
else
|
237
|
+
if actual_image.state != :available
|
238
|
+
action_handler.report_progress 'Waiting for image to be ready ...'
|
239
|
+
wait_until_ready_image(action_handler, image_spec, actual_image)
|
240
|
+
else
|
241
|
+
action_handler.report_progress "Image #{image_spec.name} is ready!"
|
242
|
+
end
|
243
|
+
end
|
206
244
|
end
|
207
245
|
|
208
246
|
def destroy_image(action_handler, image_spec, image_options)
|
247
|
+
actual_image = image_for(image_spec)
|
248
|
+
snapshots = snapshots_for(image_spec)
|
249
|
+
if actual_image.nil? || !actual_image.exists?
|
250
|
+
Chef::Log.warn "Image #{image_spec.name} doesn't exist"
|
251
|
+
else
|
252
|
+
action_handler.perform_action "De-registering image #{image_spec.name}" do
|
253
|
+
actual_image.deregister
|
254
|
+
end
|
255
|
+
unless snapshots.any?
|
256
|
+
action_handler.perform_action "Deleting image #{image_spec.name} snapshots" do
|
257
|
+
snapshots.each do |snap|
|
258
|
+
snap.delete
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
209
263
|
end
|
210
264
|
|
211
265
|
# Machine methods
|
@@ -213,7 +267,7 @@ module AWSDriver
|
|
213
267
|
actual_instance = instance_for(machine_spec)
|
214
268
|
if actual_instance == nil || !actual_instance.exists? || actual_instance.status == :terminated
|
215
269
|
image_id = machine_options[:image_id] || default_ami_for_region(@region)
|
216
|
-
bootstrap_options = machine_options[:bootstrap_options] || {}
|
270
|
+
bootstrap_options = (machine_options[:bootstrap_options] || {}).to_h.dup
|
217
271
|
bootstrap_options[:image_id] = image_id
|
218
272
|
if !bootstrap_options[:key_name]
|
219
273
|
Chef::Log.debug('No key specified, generating a default one...')
|
@@ -224,6 +278,8 @@ module AWSDriver
|
|
224
278
|
action_handler.perform_action "Create #{machine_spec.name} with AMI #{image_id} in #{@region}" do
|
225
279
|
Chef::Log.debug "Creating instance with bootstrap options #{bootstrap_options}"
|
226
280
|
instance = ec2.instances.create(bootstrap_options)
|
281
|
+
# Make sure the instance is ready to be tagged
|
282
|
+
sleep 5 while instance.status == :pending
|
227
283
|
# TODO add other tags identifying user / node url (same as fog)
|
228
284
|
instance.tags['Name'] = machine_spec.name
|
229
285
|
machine_spec.location = {
|
@@ -234,10 +290,23 @@ module AWSDriver
|
|
234
290
|
'image_id' => machine_options[:image_id],
|
235
291
|
'instance_id' => instance.id
|
236
292
|
}
|
293
|
+
machine_spec.location['key_name'] = bootstrap_options[:key_name] if bootstrap_options[:key_name]
|
294
|
+
%w(is_windows ssh_username sudo use_private_ip_for_ssh ssh_gateway).each do |key|
|
295
|
+
machine_spec.location[key] = machine_options[key.to_sym] if machine_options[key.to_sym]
|
296
|
+
end
|
237
297
|
end
|
238
298
|
end
|
239
299
|
end
|
240
300
|
|
301
|
+
def allocate_machines(action_handler, specs_and_options, parallelizer)
|
302
|
+
#Chef::Log.warn("#{specs_and_options}")
|
303
|
+
create_servers(action_handler, specs_and_options, parallelizer) do |machine_spec, server|
|
304
|
+
#Chef::Log.warn("#{machine_spec}")
|
305
|
+
yield machine_spec
|
306
|
+
end
|
307
|
+
specs_and_options.keys
|
308
|
+
end
|
309
|
+
|
241
310
|
def ready_machine(action_handler, machine_spec, machine_options)
|
242
311
|
instance = instance_for(machine_spec)
|
243
312
|
|
@@ -246,18 +315,27 @@ module AWSDriver
|
|
246
315
|
end
|
247
316
|
|
248
317
|
if instance.status != :running
|
249
|
-
|
318
|
+
wait_until_machine(action_handler, machine_spec, instance) { instance.status != :stopping }
|
250
319
|
if instance.status == :stopped
|
251
320
|
action_handler.perform_action "Start #{machine_spec.name} (#{machine_spec.location['instance_id']}) in #{@region} ..." do
|
252
321
|
instance.start
|
253
322
|
end
|
254
323
|
end
|
255
|
-
|
324
|
+
wait_until_ready_machine(action_handler, machine_spec, instance)
|
256
325
|
wait_for_transport(action_handler, machine_spec, machine_options)
|
257
326
|
end
|
258
327
|
|
259
328
|
machine_for(machine_spec, machine_options, instance)
|
329
|
+
end
|
330
|
+
|
331
|
+
def connect_to_machine(name, chef_server = nil)
|
332
|
+
if name.is_a?(MachineSpec)
|
333
|
+
machine_spec = name
|
334
|
+
else
|
335
|
+
machine_spec = Chef::Provisioning::ChefMachineSpec.get(name, chef_server)
|
336
|
+
end
|
260
337
|
|
338
|
+
machine_for(machine_spec, machine_spec.location)
|
261
339
|
end
|
262
340
|
|
263
341
|
def destroy_machine(action_handler, machine_spec, machine_options)
|
@@ -332,8 +410,37 @@ module AWSDriver
|
|
332
410
|
def instance_for(machine_spec)
|
333
411
|
if machine_spec.location && machine_spec.location['instance_id']
|
334
412
|
ec2.instances[machine_spec.location['instance_id']]
|
335
|
-
|
336
|
-
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
def instances_for(machine_specs)
|
417
|
+
result = {}
|
418
|
+
machine_specs.each do |machine_spec|
|
419
|
+
if machine_spec.location && machine_spec.location['instance_id']
|
420
|
+
if machine_spec.location['driver_url'] != driver_url
|
421
|
+
raise "Switching a machine's driver from #{machine_spec.location['driver_url']} to #{driver_url} is not currently supported! Use machine :destroy and then re-create the machine on the new driver."
|
422
|
+
end
|
423
|
+
#returns nil if not found
|
424
|
+
result[machine_spec] = ec2.instances[machine_spec.location['instance_id']]
|
425
|
+
end
|
426
|
+
end
|
427
|
+
result
|
428
|
+
end
|
429
|
+
|
430
|
+
def image_for(image_spec)
|
431
|
+
if image_spec.location && image_spec.location['image_id']
|
432
|
+
ec2.images[image_spec.location['image_id']]
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
def snapshots_for(image_spec)
|
437
|
+
if image_spec.location && image_spec.location['image_id']
|
438
|
+
actual_image = image_for(image_spec)
|
439
|
+
snapshots = []
|
440
|
+
actual_image.block_device_mappings.each do |dev, opts|
|
441
|
+
snapshots << ec2.snapshots[opts[:snapshot_id]]
|
442
|
+
end
|
443
|
+
snapshots
|
337
444
|
end
|
338
445
|
end
|
339
446
|
|
@@ -457,28 +564,49 @@ module AWSDriver
|
|
457
564
|
|
458
565
|
def convergence_strategy_for(machine_spec, machine_options)
|
459
566
|
# Tell Ohai that this is an EC2 instance so that it runs the EC2 plugin
|
460
|
-
|
461
|
-
|
567
|
+
convergence_options = Cheffish::MergedConfig.new(
|
568
|
+
machine_options[:convergence_options] || {},
|
569
|
+
ohai_hints: { 'ec2' => '' })
|
462
570
|
|
463
571
|
# Defaults
|
464
572
|
if !machine_spec.location
|
465
|
-
return Chef::Provisioning::ConvergenceStrategy::NoConverge.new(
|
573
|
+
return Chef::Provisioning::ConvergenceStrategy::NoConverge.new(convergence_options, config)
|
466
574
|
end
|
467
575
|
|
468
576
|
if machine_spec.location['is_windows']
|
469
|
-
Chef::Provisioning::ConvergenceStrategy::InstallMsi.new(
|
577
|
+
Chef::Provisioning::ConvergenceStrategy::InstallMsi.new(convergence_options, config)
|
470
578
|
elsif machine_options[:cached_installer] == true
|
471
|
-
Chef::Provisioning::ConvergenceStrategy::InstallCached.new(
|
579
|
+
Chef::Provisioning::ConvergenceStrategy::InstallCached.new(convergence_options, config)
|
472
580
|
else
|
473
|
-
Chef::Provisioning::ConvergenceStrategy::InstallSh.new(
|
581
|
+
Chef::Provisioning::ConvergenceStrategy::InstallSh.new(convergence_options, config)
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
def wait_until_ready_image(action_handler, image_spec, image=nil)
|
586
|
+
wait_until_image(action_handler, image_spec, image) { image.state == :available }
|
587
|
+
end
|
588
|
+
|
589
|
+
def wait_until_image(action_handler, image_spec, image=nil, &block)
|
590
|
+
image ||= image_for(image_spec)
|
591
|
+
time_elapsed = 0
|
592
|
+
sleep_time = 10
|
593
|
+
max_wait_time = 120
|
594
|
+
if !yield(image)
|
595
|
+
action_handler.report_progress "waiting for #{image_spec.name} (#{image.id} on #{driver_url}) to be ready ..."
|
596
|
+
while time_elapsed < 120 && !yield(image)
|
597
|
+
action_handler.report_progress "been waiting #{time_elapsed}/#{max_wait_time} -- sleeping #{sleep_time} seconds for #{image_spec.name} (#{image.id} on #{driver_url}) to be ready ..."
|
598
|
+
sleep(sleep_time)
|
599
|
+
time_elapsed += sleep_time
|
600
|
+
end
|
601
|
+
action_handler.report_progress "Image #{image_spec.name} is now ready"
|
474
602
|
end
|
475
603
|
end
|
476
604
|
|
477
|
-
def
|
478
|
-
|
605
|
+
def wait_until_ready_machine(action_handler, machine_spec, instance=nil)
|
606
|
+
wait_until_machine(action_handler, machine_spec, instance) { instance.status == :running }
|
479
607
|
end
|
480
608
|
|
481
|
-
def
|
609
|
+
def wait_until_machine(action_handler, machine_spec, instance=nil, &block)
|
482
610
|
instance ||= instance_for(machine_spec)
|
483
611
|
time_elapsed = 0
|
484
612
|
sleep_time = 10
|
@@ -540,12 +668,86 @@ module AWSDriver
|
|
540
668
|
end
|
541
669
|
|
542
670
|
# Only warn the first time
|
543
|
-
default_warning = 'Using default key, which is not shared between machines! It is recommended to create an AWS key pair with the
|
671
|
+
default_warning = 'Using default key, which is not shared between machines! It is recommended to create an AWS key pair with the aws_key_pair resource, and set :bootstrap_options => { :key_name => <key name> }'
|
544
672
|
Chef::Log.warn(default_warning) if updated
|
545
673
|
|
546
674
|
default_key_name
|
547
675
|
end
|
548
676
|
|
677
|
+
def create_servers(action_handler, specs_and_options, parallelizer, &block)
|
678
|
+
specs_and_servers = instances_for(specs_and_options.keys)
|
679
|
+
|
680
|
+
by_bootstrap_options = {}
|
681
|
+
specs_and_options.each do |machine_spec, machine_options|
|
682
|
+
actual_instance = specs_and_servers[machine_spec]
|
683
|
+
if actual_instance
|
684
|
+
if actual_instance.status == :terminated
|
685
|
+
Chef::Log.warn "Machine #{machine_spec.name} (#{actual_instance.id}) is terminated. Recreating ..."
|
686
|
+
else
|
687
|
+
yield machine_spec, actual_instance if block_given?
|
688
|
+
next
|
689
|
+
end
|
690
|
+
elsif machine_spec.location
|
691
|
+
Chef::Log.warn "Machine #{machine_spec.name} (#{machine_spec.location['instance_id']} on #{driver_url}) no longer exists. Recreating ..."
|
692
|
+
end
|
693
|
+
|
694
|
+
bootstrap_options = machine_options[:bootstrap_options] || {}
|
695
|
+
by_bootstrap_options[bootstrap_options] ||= []
|
696
|
+
by_bootstrap_options[bootstrap_options] << machine_spec
|
697
|
+
end
|
698
|
+
|
699
|
+
# Create the servers in parallel
|
700
|
+
parallelizer.parallelize(by_bootstrap_options) do |bootstrap_options, machine_specs|
|
701
|
+
machine_description = if machine_specs.size == 1
|
702
|
+
"machine #{machine_specs.first.name}"
|
703
|
+
else
|
704
|
+
"machines #{machine_specs.map { |s| s.name }.join(", ")}"
|
705
|
+
end
|
706
|
+
description = [ "creating #{machine_description} on #{driver_url}" ]
|
707
|
+
bootstrap_options.each_pair { |key,value| description << " #{key}: #{value.inspect}" }
|
708
|
+
action_handler.report_progress description
|
709
|
+
if action_handler.should_perform_actions
|
710
|
+
# Actually create the servers
|
711
|
+
create_many_instances(machine_specs.size, bootstrap_options, parallelizer) do |instance|
|
712
|
+
|
713
|
+
# Assign each one to a machine spec
|
714
|
+
machine_spec = machine_specs.pop
|
715
|
+
machine_options = specs_and_options[machine_spec]
|
716
|
+
machine_spec.location = {
|
717
|
+
'driver_url' => driver_url,
|
718
|
+
'driver_version' => Chef::Provisioning::AWSDriver::VERSION,
|
719
|
+
'allocated_at' => Time.now.utc.to_s,
|
720
|
+
'host_node' => action_handler.host_node,
|
721
|
+
'image_id' => bootstrap_options[:image_id],
|
722
|
+
'instance_id' => instance.id
|
723
|
+
}
|
724
|
+
instance.tags['Name'] = machine_spec.name
|
725
|
+
machine_spec.location['key_name'] = bootstrap_options[:key_name] if bootstrap_options[:key_name]
|
726
|
+
%w(is_windows ssh_username sudo use_private_ip_for_ssh ssh_gateway).each do |key|
|
727
|
+
machine_spec.location[key] = machine_options[key.to_sym] if machine_options[key.to_sym]
|
728
|
+
end
|
729
|
+
action_handler.performed_action "machine #{machine_spec.name} created as #{instance.id} on #{driver_url}"
|
730
|
+
|
731
|
+
yield machine_spec, instance if block_given?
|
732
|
+
end
|
733
|
+
|
734
|
+
if machine_specs.size > 0
|
735
|
+
raise "Not all machines were created by create_servers"
|
736
|
+
end
|
737
|
+
end
|
738
|
+
end.to_a
|
739
|
+
end
|
740
|
+
|
741
|
+
def create_many_instances(num_servers, bootstrap_options, parallelizer)
|
742
|
+
parallelizer.parallelize(1.upto(num_servers)) do |i|
|
743
|
+
clean_bootstrap_options = Marshal.load(Marshal.dump(bootstrap_options))
|
744
|
+
instance = ec2.instances.create(clean_bootstrap_options)
|
745
|
+
|
746
|
+
yield instance if block_given?
|
747
|
+
instance
|
748
|
+
end.to_a
|
749
|
+
end
|
750
|
+
|
549
751
|
end
|
550
752
|
end
|
551
753
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
resources = %w(sqs_queue sns_topic ebs_volume s3_bucket auto_scaling_group launch_config vpc security_group eip_address)
|
1
|
+
resources = %w(sqs_queue sns_topic ebs_volume s3_bucket auto_scaling_group launch_config vpc security_group eip_address subnet)
|
2
2
|
|
3
3
|
resources.each do |r|
|
4
4
|
Chef::Log.debug "AWS driver loading resource: #{r}"
|
@@ -13,6 +13,8 @@ class Chef::Resource::AwsS3Bucket < Chef::Resource::AwsResource
|
|
13
13
|
attribute :enable_website_hosting, :kind_of => [TrueClass, FalseClass], :default => false
|
14
14
|
attribute :website_options, :kind_of => Hash
|
15
15
|
|
16
|
+
stored_attribute :endpoint
|
17
|
+
|
16
18
|
def initialize(*args)
|
17
19
|
super
|
18
20
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'chef/resource/aws_resource'
|
2
|
+
require 'chef/provisioning/aws_driver'
|
3
|
+
|
4
|
+
class Chef::Resource::AwsSubnet < Chef::Resource::AwsResource
|
5
|
+
self.resource_name = 'aws_subnet'
|
6
|
+
self.databag_name = 'aws_subnet'
|
7
|
+
|
8
|
+
actions :create, :delete, :nothing
|
9
|
+
default_action :create
|
10
|
+
|
11
|
+
attribute :name, :kind_of => String, :name_attribute => true
|
12
|
+
attribute :cidr_block, :kind_of => String
|
13
|
+
attribute :vpc, :kind_of => String
|
14
|
+
attribute :availability_zone, :kind_of => String
|
15
|
+
|
16
|
+
stored_attribute :subnet_id
|
17
|
+
|
18
|
+
def initialize(*args)
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_created
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-provisioning-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Ewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 11.16.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 11.16.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: chef-provisioning
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.9'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.9'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: aws-sdk-v1
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: Provisioner for creating aws containers in Chef Provisioning.
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/chef/provider/aws_security_group.rb
|
116
116
|
- lib/chef/provider/aws_sns_topic.rb
|
117
117
|
- lib/chef/provider/aws_sqs_queue.rb
|
118
|
+
- lib/chef/provider/aws_subnet.rb
|
118
119
|
- lib/chef/provider/aws_vpc.rb
|
119
120
|
- lib/chef/provisioning/aws_driver.rb
|
120
121
|
- lib/chef/provisioning/aws_driver/aws_profile.rb
|
@@ -123,9 +124,7 @@ files:
|
|
123
124
|
- lib/chef/provisioning/aws_driver/resources.rb
|
124
125
|
- lib/chef/provisioning/aws_driver/version.rb
|
125
126
|
- lib/chef/provisioning/driver_init/aws.rb
|
126
|
-
- lib/chef/resource/.DS_Store
|
127
127
|
- lib/chef/resource/aws_auto_scaling_group.rb
|
128
|
-
- lib/chef/resource/aws_ebs_mount.rb
|
129
128
|
- lib/chef/resource/aws_ebs_volume.rb
|
130
129
|
- lib/chef/resource/aws_eip_address.rb
|
131
130
|
- lib/chef/resource/aws_key_pair.rb
|
@@ -135,6 +134,7 @@ files:
|
|
135
134
|
- lib/chef/resource/aws_security_group.rb
|
136
135
|
- lib/chef/resource/aws_sns_topic.rb
|
137
136
|
- lib/chef/resource/aws_sqs_queue.rb
|
137
|
+
- lib/chef/resource/aws_subnet.rb
|
138
138
|
- lib/chef/resource/aws_vpc.rb
|
139
139
|
- spec/spec_helper.rb
|
140
140
|
- spec/unit/aws_driver/credentials_spec.rb
|
@@ -147,12 +147,12 @@ require_paths:
|
|
147
147
|
- lib
|
148
148
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
|
-
- -
|
155
|
+
- - ">="
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
@@ -162,3 +162,4 @@ signing_key:
|
|
162
162
|
specification_version: 4
|
163
163
|
summary: Provisioner for creating aws containers in Chef Provisioning.
|
164
164
|
test_files: []
|
165
|
+
has_rdoc:
|
data/lib/chef/resource/.DS_Store
DELETED
Binary file
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'chef/resource/aws_resource'
|
2
|
-
require 'chef_metal_aws'
|
3
|
-
|
4
|
-
class Chef::Resource::AwsEbsVolume < Chef::Resource::AwsResource
|
5
|
-
self.resource_name = 'aws_ebs_mount'
|
6
|
-
self.databag_name = 'ebs_mounts'
|
7
|
-
|
8
|
-
actions :create, :delete, :nothing
|
9
|
-
default_action :create
|
10
|
-
|
11
|
-
stored_attribute :instance_id
|
12
|
-
stored_attribute :volume_id
|
13
|
-
|
14
|
-
attribute :name, :kind_of => String, :name_attribute => true
|
15
|
-
attribute :volume_name, :kind_of => String
|
16
|
-
|
17
|
-
attribute :size
|
18
|
-
attribute :mount_point
|
19
|
-
attribute :availability_zone
|
20
|
-
|
21
|
-
|
22
|
-
def initialize(*args)
|
23
|
-
super
|
24
|
-
end
|
25
|
-
|
26
|
-
def after_created
|
27
|
-
super
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
end
|