ec2launcher 1.0.10 → 1.0.11
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.
- data/CHANGELOG.md +4 -0
- data/lib/ec2launcher/block_device_builder.rb +63 -41
- data/lib/ec2launcher/dsl/application.rb +297 -0
- data/lib/ec2launcher/dsl/block_device.rb +96 -0
- data/lib/ec2launcher/dsl/config.rb +78 -0
- data/lib/ec2launcher/dsl/email_notification.rb +67 -0
- data/lib/ec2launcher/dsl/environment.rb +221 -0
- data/lib/ec2launcher/hostname_generator.rb +117 -0
- data/lib/ec2launcher/init_options.rb +18 -7
- data/lib/ec2launcher/version.rb +1 -1
- data/lib/ec2launcher.rb +111 -148
- metadata +7 -6
- data/lib/ec2launcher/application.rb +0 -295
- data/lib/ec2launcher/block_device.rb +0 -94
- data/lib/ec2launcher/config.rb +0 -76
- data/lib/ec2launcher/email_notification.rb +0 -65
- data/lib/ec2launcher/environment.rb +0 -219
data/lib/ec2launcher.rb
CHANGED
@@ -6,14 +6,16 @@ require 'optparse'
|
|
6
6
|
require 'ostruct'
|
7
7
|
require 'aws-sdk'
|
8
8
|
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require "ec2launcher/defaults"
|
12
|
-
require "ec2launcher/backoff_runner"
|
9
|
+
require 'ec2launcher/version'
|
10
|
+
require 'ec2launcher/defaults'
|
13
11
|
|
14
|
-
require 'ec2launcher/
|
15
|
-
require 'ec2launcher/
|
12
|
+
require 'ec2launcher/dsl/config'
|
13
|
+
require 'ec2launcher/dsl/application'
|
14
|
+
require 'ec2launcher/dsl/environment'
|
15
|
+
|
16
|
+
require 'ec2launcher/backoff_runner'
|
16
17
|
require 'ec2launcher/block_device_builder'
|
18
|
+
require 'ec2launcher/hostname_generator'
|
17
19
|
|
18
20
|
module EC2Launcher
|
19
21
|
|
@@ -60,7 +62,7 @@ module EC2Launcher
|
|
60
62
|
filename = File.join(app_dir, application_name)
|
61
63
|
next if File.directory?(filename)
|
62
64
|
|
63
|
-
apps = EC2Launcher::ApplicationDSL.execute(File.read(filename)).applications
|
65
|
+
apps = EC2Launcher::DSL::ApplicationDSL.execute(File.read(filename)).applications
|
64
66
|
apps.each do |new_application|
|
65
67
|
@applications[new_application.name] = new_application
|
66
68
|
validate_application(filename, new_application)
|
@@ -199,28 +201,36 @@ module EC2Launcher
|
|
199
201
|
##############################
|
200
202
|
# HOSTNAME
|
201
203
|
##############################
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
204
|
+
hostname_generator = EC2Launcher::HostnameGenerator.new(@ec2, @environment, @application)
|
205
|
+
short_hostnames = []
|
206
|
+
fqdn_names = []
|
207
|
+
if @options.count > 1
|
208
|
+
1.upto(@options.count).each do |i|
|
209
|
+
short_hostname = hostname_generator.generate_hostname()
|
210
|
+
long_hostname = hostname_generator.generate_long_name(short_hostname, @environment.domain_name)
|
211
|
+
short_hostnames << short_hostname
|
212
|
+
fqdn_names << long_hostname
|
209
213
|
end
|
210
214
|
else
|
211
|
-
|
212
|
-
|
213
|
-
|
215
|
+
if @options.hostname.nil?
|
216
|
+
short_hostname = hostname_generator.generate_hostname()
|
217
|
+
long_hostname = hostname_generator.generate_long_name(short_hostname, @environment.domain_name)
|
218
|
+
else
|
219
|
+
long_hostname = @options.hostname
|
220
|
+
short_hostname = hostname_generator.generate_short_name(short_hostname, @environment.domain_name)
|
221
|
+
if long_hostname == short_hostname
|
222
|
+
long_hostname = hostname_generator.generate_long_name(short_hostname, @environment.domain_name)
|
223
|
+
end
|
214
224
|
end
|
225
|
+
short_hostnames << short_hostname
|
226
|
+
fqdn_names << long_hostname
|
215
227
|
end
|
216
228
|
|
217
229
|
##############################
|
218
230
|
# Block devices
|
219
231
|
##############################
|
220
|
-
|
221
|
-
|
222
|
-
block_device_mappings = builder.block_device_mappings
|
223
|
-
block_device_tags = builder.block_device_tags
|
232
|
+
block_device_builder = EC2Launcher::BlockDeviceBuilder.new(@ec2, @options.volume_size)
|
233
|
+
block_device_mappings = block_device_builder.generate_block_devices(instance_type, @environment, @application, @options.clone_host)
|
224
234
|
|
225
235
|
##############################
|
226
236
|
# ELB
|
@@ -268,54 +278,6 @@ module EC2Launcher
|
|
268
278
|
##############################
|
269
279
|
aws_keyfile = @environment.aws_keyfile
|
270
280
|
|
271
|
-
##############################
|
272
|
-
# Build JSON for setup scripts
|
273
|
-
##############################
|
274
|
-
setup_json = {
|
275
|
-
'hostname' => hostname,
|
276
|
-
'short_hostname' => short_hostname,
|
277
|
-
'roles' => roles,
|
278
|
-
'chef_server_url' => @environment.chef_server_url,
|
279
|
-
'chef_validation_pem_url' => chef_validation_pem_url,
|
280
|
-
'aws_keyfile' => aws_keyfile,
|
281
|
-
'gems' => gems,
|
282
|
-
'packages' => packages
|
283
|
-
}
|
284
|
-
unless @application.block_devices.nil? || @application.block_devices.empty?
|
285
|
-
setup_json['block_devices'] = @application.block_devices
|
286
|
-
end
|
287
|
-
unless email_notifications.nil?
|
288
|
-
setup_json['email_notifications'] = email_notifications
|
289
|
-
end
|
290
|
-
|
291
|
-
##############################
|
292
|
-
# Build launch command
|
293
|
-
user_data = "#!/bin/sh
|
294
|
-
export HOME=/root
|
295
|
-
echo '#{setup_json.to_json}' > /tmp/setup.json"
|
296
|
-
|
297
|
-
# pre-commands, if necessary
|
298
|
-
unless @environment.precommands.nil? || @environment.precommands.empty?
|
299
|
-
precommands = @environment.precommands.join("\n")
|
300
|
-
user_data += "\n" + precommands
|
301
|
-
end
|
302
|
-
|
303
|
-
# Primary setup script
|
304
|
-
user_data += "\ncurl http://bazaar.launchpad.net/~alestic/runurl/trunk/download/head:/runurl-20090817053347-o2e56z7xwq8m9tt6-1/runurl -o /tmp/runurl
|
305
|
-
chmod +x /tmp/runurl
|
306
|
-
/tmp/runurl https://raw.github.com/StudyBlue/ec2launcher/master/startup-scripts/setup.rb -e #{@environment.name} -a #{@application.name} -h #{hostname} /tmp/setup.json > /var/log/cloud-startup.log
|
307
|
-
rm -f /tmp/runurl"
|
308
|
-
user_data += " -c #{options.clone_host}" unless options.clone_host.nil?
|
309
|
-
|
310
|
-
# Add extra requested commands to the launch sequence
|
311
|
-
options.commands.each {|extra_cmd| user_data += "\n#{extra_cmd}" }
|
312
|
-
|
313
|
-
# Post commands
|
314
|
-
unless @environment.postcommands.nil? || @environment.postcommands.empty?
|
315
|
-
postcommands = @environment.postcommands.join("\n")
|
316
|
-
user_data += "\n" + postcommands
|
317
|
-
end
|
318
|
-
|
319
281
|
##############################
|
320
282
|
puts
|
321
283
|
puts "Availability zone: #{availability_zone}"
|
@@ -325,7 +287,6 @@ rm -f /tmp/runurl"
|
|
325
287
|
puts "Architecture : #{instance_architecture}"
|
326
288
|
puts "AMI name : #{ami.ami_name}"
|
327
289
|
puts "AMI id : #{ami.ami_id}"
|
328
|
-
puts "Name : #{hostname}"
|
329
290
|
puts "ELB : #{elb_name}" if elb_name
|
330
291
|
puts "Chef PEM : #{chef_validation_pem_url}"
|
331
292
|
puts "AWS key file : #{aws_keyfile}"
|
@@ -333,8 +294,14 @@ rm -f /tmp/runurl"
|
|
333
294
|
puts "Gems : #{gems.join(', ')}"
|
334
295
|
puts "Packages : #{packages.join(', ')}"
|
335
296
|
puts "VPC Subnet : #{subnet}" if subnet
|
297
|
+
puts ""
|
298
|
+
fqdn_names.each do |fqdn|
|
299
|
+
puts "Name : #{fqdn}"
|
300
|
+
end
|
336
301
|
|
337
302
|
unless block_device_mappings.empty?
|
303
|
+
puts ""
|
304
|
+
puts "Block devices :"
|
338
305
|
block_device_mappings.keys.sort.each do |key|
|
339
306
|
if block_device_mappings[key] =~ /^ephemeral/
|
340
307
|
puts " Block device : #{key}, #{block_device_mappings[key]}"
|
@@ -346,10 +313,6 @@ rm -f /tmp/runurl"
|
|
346
313
|
end
|
347
314
|
end
|
348
315
|
|
349
|
-
puts "User data:"
|
350
|
-
puts user_data
|
351
|
-
puts
|
352
|
-
|
353
316
|
if chef_validation_pem_url.nil?
|
354
317
|
puts "***ERROR*** Missing the URL For the Chef Validation PEM file."
|
355
318
|
exit 3
|
@@ -361,22 +324,24 @@ rm -f /tmp/runurl"
|
|
361
324
|
##############################
|
362
325
|
# Launch the new intance
|
363
326
|
##############################
|
364
|
-
|
327
|
+
instances = []
|
328
|
+
fqdn_names.each_index do |i|
|
329
|
+
block_device_tags = block_device_builder.generate_device_tags(fqdn[i], short_hostnames[i], @environment.name, @application.block_devices)
|
330
|
+
instances << launch_instance(fqdn[i], ami.ami_id, availability_zone, key_name, security_group_ids, instance_type, user_data, block_device_mappings, block_device_tags, subnet)
|
331
|
+
|
332
|
+
puts "Launched #{fqdn[i]} (#{instance.id}) [#{instance.public_dns_name} / #{instance.private_dns_name} / #{instance.private_ip_address} ]"
|
333
|
+
end
|
365
334
|
|
366
335
|
##############################
|
367
336
|
# ELB
|
368
337
|
##############################
|
369
|
-
|
338
|
+
unless elb_name.nil?
|
339
|
+
instances.each {|instance| attach_to_elb(instance, elb_name) }
|
340
|
+
end
|
370
341
|
|
371
342
|
##############################
|
372
343
|
# COMPLETED
|
373
344
|
##############################
|
374
|
-
puts ""
|
375
|
-
puts "Hostname : #{hostname}"
|
376
|
-
puts "Instance id: #{instance.id}"
|
377
|
-
puts "Public dns : #{instance.public_dns_name}"
|
378
|
-
puts "Private dns: #{instance.private_dns_name}"
|
379
|
-
puts "Private ip : #{instance.private_ip_address}"
|
380
345
|
puts "********************"
|
381
346
|
end
|
382
347
|
|
@@ -511,68 +476,6 @@ rm -f /tmp/runurl"
|
|
511
476
|
})
|
512
477
|
end
|
513
478
|
|
514
|
-
# Generates a new hostname based on:
|
515
|
-
# * application base name
|
516
|
-
# * application name
|
517
|
-
# * application suffix
|
518
|
-
# * environment short name
|
519
|
-
# * environment name
|
520
|
-
#
|
521
|
-
def generate_hostname()
|
522
|
-
puts "Calculating host name..."
|
523
|
-
|
524
|
-
prefix = @application.basename
|
525
|
-
prefix ||= @application.name
|
526
|
-
|
527
|
-
env_suffix = @environment.short_name
|
528
|
-
env_suffix ||= @environment.name
|
529
|
-
|
530
|
-
suffix = env_suffix
|
531
|
-
unless @application.name_suffix.nil?
|
532
|
-
suffix = "#{@application.name_suffix}.#{env_suffix}"
|
533
|
-
end
|
534
|
-
|
535
|
-
regex = Regexp.new("#{prefix}(\\d+)[.]#{suffix.gsub(/[.]/, "[.]")}.*")
|
536
|
-
|
537
|
-
server_numbers = []
|
538
|
-
|
539
|
-
highest_server_number = 0
|
540
|
-
lowest_server_number = 32768
|
541
|
-
AWS.memoize do
|
542
|
-
server_instances = @ec2.instances.filter("tag:Name", "#{prefix}*#{suffix}*")
|
543
|
-
server_instances.each do |i|
|
544
|
-
next if i.status == :terminated
|
545
|
-
server_name = i.tags[:Name]
|
546
|
-
unless regex.match(server_name).nil?
|
547
|
-
server_num = $1.to_i
|
548
|
-
server_numbers << server_num
|
549
|
-
end
|
550
|
-
end
|
551
|
-
highest_server_number = server_numbers.max
|
552
|
-
end
|
553
|
-
|
554
|
-
# If the highest number server is less than 10, just add
|
555
|
-
# 1 to it. Otherwise, find the first available
|
556
|
-
# server number starting at 1.
|
557
|
-
host_number = 0
|
558
|
-
if highest_server_number.nil?
|
559
|
-
host_number = 1
|
560
|
-
elsif highest_server_number < 10
|
561
|
-
host_number = highest_server_number + 1
|
562
|
-
else
|
563
|
-
# Try to start over with 1 and find the
|
564
|
-
# first available host number
|
565
|
-
server_number_set = Set.new(server_numbers)
|
566
|
-
host_number = 1
|
567
|
-
while server_number_set.include?(host_number) do
|
568
|
-
host_number += 1
|
569
|
-
end
|
570
|
-
end
|
571
|
-
|
572
|
-
short_hostname = "#{prefix}#{host_number}.#{suffix}"
|
573
|
-
short_hostname
|
574
|
-
end
|
575
|
-
|
576
479
|
# Launches an EC2 instance.
|
577
480
|
#
|
578
481
|
# @param [String] FQDN for the new host.
|
@@ -654,7 +557,7 @@ rm -f /tmp/runurl"
|
|
654
557
|
# Load configuration file
|
655
558
|
config_filename = File.join(@options.directory, "config.rb")
|
656
559
|
abort("Unable to find 'config.rb' in '#{@options.directory}'") unless File.exists?(config_filename)
|
657
|
-
EC2Launcher::ConfigDSL.execute(File.read(config_filename)).config
|
560
|
+
EC2Launcher::DSL::ConfigDSL.execute(File.read(config_filename)).config
|
658
561
|
end
|
659
562
|
|
660
563
|
# Load and parse an environment file
|
@@ -672,7 +575,7 @@ rm -f /tmp/runurl"
|
|
672
575
|
return nil
|
673
576
|
end
|
674
577
|
|
675
|
-
load_env = EC2Launcher::Environment.new
|
578
|
+
load_env = EC2Launcher::DSL::Environment.new
|
676
579
|
load_env.load(File.read(name))
|
677
580
|
load_env
|
678
581
|
end
|
@@ -746,7 +649,7 @@ rm -f /tmp/runurl"
|
|
746
649
|
# Validates all settings in an application file
|
747
650
|
#
|
748
651
|
# @param [String] filename name of the application file
|
749
|
-
# @param [EC2Launcher::Application] application application object to validate
|
652
|
+
# @param [EC2Launcher::DSL::Application] application application object to validate
|
750
653
|
#
|
751
654
|
def validate_application(filename, application)
|
752
655
|
unless application.availability_zone.nil? || AVAILABILITY_ZONES.include?(application.availability_zone)
|
@@ -761,12 +664,72 @@ rm -f /tmp/runurl"
|
|
761
664
|
# Validates all settings in an environment file
|
762
665
|
#
|
763
666
|
# @param [String] filename name of the environment file
|
764
|
-
# @param [EC2Launcher::Environment] environment environment object to validate
|
667
|
+
# @param [EC2Launcher::DSL::Environment] environment environment object to validate
|
765
668
|
#
|
766
669
|
def validate_environment(filename, environment)
|
767
670
|
unless environment.availability_zone.nil? || AVAILABILITY_ZONES.include?(environment.availability_zone)
|
768
671
|
abort("Invalid availability zone '#{environment.availability_zone}' in environment '#{environment.name}' (#{filename})")
|
769
672
|
end
|
770
673
|
end
|
674
|
+
|
675
|
+
# Builds the launch scripts that should run on the new instance.
|
676
|
+
#
|
677
|
+
# @param [String] fqdn Fully qualified hostname
|
678
|
+
# @param [String] short_name Short hostname without the domain
|
679
|
+
# @param [String] chef_validation_pem_url URL For the Chef validation pem file
|
680
|
+
# @param [String] aws_keyfile Name of the AWS key to use
|
681
|
+
# @param [Array<String>] gems List of gems to pre-install
|
682
|
+
# @param [Array<String>] packages List of packages to pre-install
|
683
|
+
# @param [EC2Launcher::DSL::EmailNotifications] email_notifications Email notification settings for launch updates
|
684
|
+
#
|
685
|
+
# @return [String] Launch commands to pass into new instance as userdata
|
686
|
+
def build_launch_command(fqdn, short_hostname, chef_validation_pem_url, aws_keyfile, gems, packages, email_notifications)
|
687
|
+
# Build JSON for setup scripts
|
688
|
+
setup_json = {
|
689
|
+
'hostname' => fqdn,
|
690
|
+
'short_hostname' => short_hostname,
|
691
|
+
'roles' => roles,
|
692
|
+
'chef_server_url' => @environment.chef_server_url,
|
693
|
+
'chef_validation_pem_url' => chef_validation_pem_url,
|
694
|
+
'aws_keyfile' => aws_keyfile,
|
695
|
+
'gems' => gems,
|
696
|
+
'packages' => packages
|
697
|
+
}
|
698
|
+
unless @application.block_devices.nil? || @application.block_devices.empty?
|
699
|
+
setup_json['block_devices'] = @application.block_devices
|
700
|
+
end
|
701
|
+
unless email_notifications.nil?
|
702
|
+
setup_json['email_notifications'] = email_notifications
|
703
|
+
end
|
704
|
+
|
705
|
+
##############################
|
706
|
+
# Build launch command
|
707
|
+
user_data = "#!/bin/sh
|
708
|
+
export HOME=/root
|
709
|
+
echo '#{setup_json.to_json}' > /tmp/setup.json"
|
710
|
+
|
711
|
+
# pre-commands, if necessary
|
712
|
+
unless @environment.precommands.nil? || @environment.precommands.empty?
|
713
|
+
precommands = @environment.precommands.join("\n")
|
714
|
+
user_data += "\n" + precommands
|
715
|
+
end
|
716
|
+
|
717
|
+
# Primary setup script
|
718
|
+
user_data += "\ncurl http://bazaar.launchpad.net/~alestic/runurl/trunk/download/head:/runurl-20090817053347-o2e56z7xwq8m9tt6-1/runurl -o /tmp/runurl
|
719
|
+
chmod +x /tmp/runurl
|
720
|
+
/tmp/runurl https://raw.github.com/StudyBlue/ec2launcher/master/startup-scripts/setup.rb -e #{@environment.name} -a #{@application.name} -h #{hostname} /tmp/setup.json > /var/log/cloud-startup.log
|
721
|
+
rm -f /tmp/runurl"
|
722
|
+
user_data += " -c #{options.clone_host}" unless options.clone_host.nil?
|
723
|
+
|
724
|
+
# Add extra requested commands to the launch sequence
|
725
|
+
options.commands.each {|extra_cmd| user_data += "\n#{extra_cmd}" }
|
726
|
+
|
727
|
+
# Post commands
|
728
|
+
unless @environment.postcommands.nil? || @environment.postcommands.empty?
|
729
|
+
postcommands = @environment.postcommands.join("\n")
|
730
|
+
user_data += "\n" + postcommands
|
731
|
+
end
|
732
|
+
user_data
|
733
|
+
end
|
771
734
|
end
|
772
735
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ec2launcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -44,14 +44,15 @@ files:
|
|
44
44
|
- bin/ec2launcher
|
45
45
|
- ec2launcher.gemspec
|
46
46
|
- lib/ec2launcher.rb
|
47
|
-
- lib/ec2launcher/application.rb
|
48
47
|
- lib/ec2launcher/backoff_runner.rb
|
49
|
-
- lib/ec2launcher/block_device.rb
|
50
48
|
- lib/ec2launcher/block_device_builder.rb
|
51
|
-
- lib/ec2launcher/config.rb
|
52
49
|
- lib/ec2launcher/defaults.rb
|
53
|
-
- lib/ec2launcher/
|
54
|
-
- lib/ec2launcher/
|
50
|
+
- lib/ec2launcher/dsl/application.rb
|
51
|
+
- lib/ec2launcher/dsl/block_device.rb
|
52
|
+
- lib/ec2launcher/dsl/config.rb
|
53
|
+
- lib/ec2launcher/dsl/email_notification.rb
|
54
|
+
- lib/ec2launcher/dsl/environment.rb
|
55
|
+
- lib/ec2launcher/hostname_generator.rb
|
55
56
|
- lib/ec2launcher/init_options.rb
|
56
57
|
- lib/ec2launcher/security_group_handler.rb
|
57
58
|
- lib/ec2launcher/version.rb
|
@@ -1,295 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2012 Sean Laurent
|
3
|
-
#
|
4
|
-
require 'ec2launcher/block_device'
|
5
|
-
require 'ec2launcher/email_notification'
|
6
|
-
require 'ec2launcher/security_group_handler'
|
7
|
-
|
8
|
-
module EC2Launcher
|
9
|
-
# Wrapper class to handle loading Application blocks.
|
10
|
-
class ApplicationDSL
|
11
|
-
attr_accessor :applications
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
self.applications = []
|
15
|
-
end
|
16
|
-
|
17
|
-
def application(name, &block)
|
18
|
-
application = Application.new(name)
|
19
|
-
applications << application
|
20
|
-
application.instance_eval &block
|
21
|
-
application
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.execute(dsl)
|
25
|
-
new.tap do |context|
|
26
|
-
context.instance_eval(dsl)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Represents a single application stack.
|
32
|
-
class Application
|
33
|
-
include EC2Launcher::EmailNotifications
|
34
|
-
include EC2Launcher::SecurityGroupHandler
|
35
|
-
|
36
|
-
attr_reader :name
|
37
|
-
|
38
|
-
def initialize(name)
|
39
|
-
@name = name
|
40
|
-
@email_notifications = nil
|
41
|
-
end
|
42
|
-
|
43
|
-
def application(name)
|
44
|
-
@name = name
|
45
|
-
yield self
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
# Name of the AMI to use for new instances. Optional.
|
50
|
-
# Can be either a string or a regular expression.
|
51
|
-
#
|
52
|
-
# @param [Array, nil] Either an array of parameters or nil to return the AMI name.
|
53
|
-
def ami_name(*ami_name)
|
54
|
-
if ami_name.empty?
|
55
|
-
@ami_name
|
56
|
-
else
|
57
|
-
if ami_name[0].kind_of? String
|
58
|
-
@ami_name = /#{ami_name[0]}/
|
59
|
-
else
|
60
|
-
@ami_name = ami_name[0]
|
61
|
-
end
|
62
|
-
self
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Name of the availability zone to use for new instances. Optional.
|
67
|
-
# Must be one of EC2Launcher::AVAILABILITY_ZONES.
|
68
|
-
def availability_zone(*zone)
|
69
|
-
if zone.empty?
|
70
|
-
@availability_zone
|
71
|
-
else
|
72
|
-
@availability_zone = zone[0].to_s
|
73
|
-
self
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Defines a shorter name when building a host name for new instances. Optional.
|
78
|
-
# By default, new instances are named using the full application name. If you
|
79
|
-
# specify basename, it will be used instead. Typically, this is used if you
|
80
|
-
# want a shorter version of the full application name.
|
81
|
-
def basename(*name)
|
82
|
-
if name.empty?
|
83
|
-
@basename
|
84
|
-
else
|
85
|
-
@basename = name[0]
|
86
|
-
self
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def block_devices(*block_device_data)
|
91
|
-
if block_device_data.empty?
|
92
|
-
@block_devices
|
93
|
-
else
|
94
|
-
self
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def block_device(&block)
|
99
|
-
@block_devices = [] if @block_devices.nil?
|
100
|
-
device = EC2Launcher::BlockDevice.new
|
101
|
-
device.instance_exec(&block)
|
102
|
-
@block_devices << device
|
103
|
-
end
|
104
|
-
|
105
|
-
# Indicates the Amazon Elastic Load Balancer to which new instances should be
|
106
|
-
# attached after launch. Optional.
|
107
|
-
#
|
108
|
-
# The value can be either a String, indicating the name of the ELB, or a Hash
|
109
|
-
# that maps environment names to ELB names.
|
110
|
-
def elb(*elb)
|
111
|
-
if elb.empty?
|
112
|
-
@elb
|
113
|
-
else
|
114
|
-
@elb = Hash.new if @elb.nil?
|
115
|
-
if elb[0].kind_of? Hash
|
116
|
-
elb[0].keys.each {|key| @elb[key] = elb[0][key]}
|
117
|
-
else
|
118
|
-
@elb["default"] = elb[0].to_s
|
119
|
-
end
|
120
|
-
self
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# Retrieves the ELB name for a given environment.
|
125
|
-
def elb_for_environment(environment)
|
126
|
-
elb_name = @elb[environment]
|
127
|
-
elb_name ||= @elb["default"]
|
128
|
-
elb_name
|
129
|
-
end
|
130
|
-
|
131
|
-
# Defines an Array of Chef roles that should be applied to new
|
132
|
-
# instances for a specific environment. Can be specified multiple times.
|
133
|
-
#
|
134
|
-
# Expects two parameters:
|
135
|
-
# * Name of an environment
|
136
|
-
# * Either the name of a single Chef role or an Array of Chef roles
|
137
|
-
def environment_roles(*data)
|
138
|
-
if data.empty?
|
139
|
-
@environment_roles
|
140
|
-
else
|
141
|
-
@environment_roles = Hash.new if @environment_roles.nil?
|
142
|
-
env_name = data[0]
|
143
|
-
env_roles = data[1]
|
144
|
-
|
145
|
-
environment_data = @environment_roles[env_name]
|
146
|
-
environment_data ||= []
|
147
|
-
|
148
|
-
if env_roles.kind_of? Array
|
149
|
-
environment_data += env_roles
|
150
|
-
else
|
151
|
-
environment_data << env_roles
|
152
|
-
end
|
153
|
-
@environment_roles[env_name] = environment_data
|
154
|
-
|
155
|
-
self
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
# Gems to install. Optional.
|
160
|
-
#
|
161
|
-
# Expects either a single String naming a gem to install or
|
162
|
-
# an Array of gems.
|
163
|
-
#
|
164
|
-
# Can be specified multiple times.
|
165
|
-
def gems(*gems)
|
166
|
-
if gems.empty?
|
167
|
-
@gems
|
168
|
-
else
|
169
|
-
@gems = [] if @gems.nil?
|
170
|
-
if gems[0].kind_of? Array
|
171
|
-
@gems += gems[0]
|
172
|
-
else
|
173
|
-
@gems << gems[0]
|
174
|
-
end
|
175
|
-
self
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
# Indicates that this application should inherit all of its settings from another named application.
|
180
|
-
# Optional.
|
181
|
-
def inherit(*inherit_type)
|
182
|
-
if inherit_type.empty?
|
183
|
-
@inherit_type
|
184
|
-
else
|
185
|
-
@inherit_type = inherit_type[0]
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
# The Amazon EC2 instance type that should be used for new instances.
|
190
|
-
# Must be one of EC2Launcher::INSTANCE_TYPES.
|
191
|
-
def instance_type(*type_name)
|
192
|
-
if type_name.empty?
|
193
|
-
@instance_type
|
194
|
-
else
|
195
|
-
@instance_type = type_name[0]
|
196
|
-
self
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# Takes values from the other server type and merges them into this one
|
201
|
-
def merge(other_server)
|
202
|
-
@name = other_server.name
|
203
|
-
@ami_name = other_server.ami_name unless other_server.ami_name.nil?
|
204
|
-
@availability_zone = other_server.availability_zone unless other_server.availability_zone.nil?
|
205
|
-
@basename = other_server.basename unless other_server.basename.nil?
|
206
|
-
other_server.block_devices.each {|bd| @block_devices << bd } unless other_server.block_devices.nil?
|
207
|
-
other_server.elb.keys.each {|env_name| @elb[env_name] = other_server.elb[env_name] } unless other_server.elb.nil?
|
208
|
-
@instance_type = other_server.instance_type unless other_server.instance_type.nil?
|
209
|
-
@name_suffix = other_server.name_suffix unless other_server.name_suffix.nil?
|
210
|
-
other_server.roles.each {|role| @roles << role } unless other_server.roles.nil?
|
211
|
-
unless other_server.security_groups.nil?
|
212
|
-
other_server.security_groups.keys.each do |env_name|
|
213
|
-
unless @security_groups.has_key? env_name
|
214
|
-
@security_groups[env_name] = []
|
215
|
-
end
|
216
|
-
other_server.security_groups[env_name].each {|sg| @security_groups[env_name] << sg }
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def name_suffix(*suffix)
|
222
|
-
if suffix.empty?
|
223
|
-
@name_suffix
|
224
|
-
else
|
225
|
-
@name_suffix = suffix[0]
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
def packages(*packages)
|
230
|
-
if packages.empty?
|
231
|
-
@packages
|
232
|
-
else
|
233
|
-
@packages = packages[0]
|
234
|
-
self
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
def roles(*roles)
|
239
|
-
if roles.empty?
|
240
|
-
@roles
|
241
|
-
else
|
242
|
-
@roles = [] if @roles.nil?
|
243
|
-
if roles[0].kind_of? Array
|
244
|
-
@roles += roles[0]
|
245
|
-
else
|
246
|
-
@roles = []
|
247
|
-
@roles << roles[0]
|
248
|
-
end
|
249
|
-
self
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
def roles_for_environment(environment)
|
254
|
-
roles = []
|
255
|
-
roles += @roles unless @roles.nil?
|
256
|
-
|
257
|
-
unless @environment_roles.nil? || @environment_roles[environment].nil?
|
258
|
-
roles += @environment_roles[environment]
|
259
|
-
end
|
260
|
-
roles
|
261
|
-
end
|
262
|
-
|
263
|
-
# Retrieves the list of Security Group names for the specified environment.
|
264
|
-
#
|
265
|
-
# @return [Array] Returns the list of security groups for the environment. Returns
|
266
|
-
# the security groups for the "defaukt" environment if the requested
|
267
|
-
# environment is undefined. Returns an empty Array if both the
|
268
|
-
# requested environment and "default" environment are undefined.
|
269
|
-
def security_groups_for_environment(environment)
|
270
|
-
groups = @security_groups[environment]
|
271
|
-
groups ||= @security_groups["default"]
|
272
|
-
groups ||= []
|
273
|
-
groups
|
274
|
-
end
|
275
|
-
|
276
|
-
def subnet(*subnet)
|
277
|
-
if subnet.empty?
|
278
|
-
@subnet
|
279
|
-
else
|
280
|
-
@subnet = subnet[0]
|
281
|
-
self
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
def load(dsl)
|
286
|
-
self.instance_eval(dsl)
|
287
|
-
self
|
288
|
-
end
|
289
|
-
|
290
|
-
def self.load(dsl)
|
291
|
-
env = Application.new.instance_eval(dsl)
|
292
|
-
env
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|