ec2launcher 1.6.15 → 1.7.0

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmNiNzZlYTgxNDRhZmY1YWYwYjE0NTdjMDZhNzMxYWJiMjI4NjNhMQ==
4
+ MWIwYTY3YTRlYTllOTUxN2E2MTI2NmI2MDdkNGY4YjZkZDRiYzZjZA==
5
5
  data.tar.gz: !binary |-
6
- MWQ2OWQ5NGU1NDdlNTFlMTM3NGY3YmYyMDI1M2ViN2M2NDViYjMyNQ==
6
+ NGNkMzJjMjIyODE5ZWQxYTk5MGEwM2UwMTRiNDY1ZTNiNDBhNmUwNQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDY5M2MwMTNlNjE4NGMxZGViZWNlZmRhMWY2ZjIwNDM1NmZhMWJhMmJmYjU0
10
- OTIwZjhlNzMzMTQwOGY3ZmM4Y2VkOTQzZDRlNDNjNGYwNjgyNWM5ZjM5OTk4
11
- ZTU5ZDE4MzdiZjU4M2Q5YmFmOTZkZWFiNDJlNmViMjkzNTZlNGQ=
9
+ OTAwNWFhYjAwZWFlYTVhMjdiMzkxODUzY2Y1YmY4MDlkZjI3ZDQ5YjBjOTc0
10
+ MmUwM2UxMmVkMjE5MDA5NmY0ODI1ZDlmMDIxZGZhODU1NDgxODgyOGFhMDEw
11
+ ODQ4YTQ3YmJmYjNlZTBmYzA5NTIwMzZjOTBjNTBiMDg3NGMwZGE=
12
12
  data.tar.gz: !binary |-
13
- YmJlMWViMGQ3NGRiNTllY2UwODQ2NGExOWQxNGRmOTVhZTI0ZDRmNjI2MWQw
14
- N2E0OTE0MDg1YWRmNzQzMWZlMDU3N2ZhNjk0YWExN2JhMTBkYzFjZDY4NTY4
15
- MTJjODE2ZWFmYWY3Nzg2YjZmMTY3MTc4MDE3MTRmNTFiN2E1NTI=
13
+ MGQwYmU3NDNlMTQ5ZjQ0MTdjYjI0OTQwNDZhMWExZmQyN2IwMjYyZDc2NTE5
14
+ MGE2YWVjZGMwNWVhODQ2YjQwZmJkZjhmY2VmNmM2Y2VkMDEwNjAzZDczYWI1
15
+ YjBiNDFiZTBiMmU5Mjk1ZDEwMTI0MzIxZTRiNjMxNzdkNWM0NzE=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 1.7.0
2
+
3
+ * New optional "dynamic" naming convention that leverages the instance id instead of a sequential number. Useful for ASGs.
4
+ * New command line option "--dynamic-name" that forces use of new naming convention.
5
+
6
+ ## 1.6.15
7
+
8
+ * Fixed a problem parsing the setup JSON on MRI rubies later than 1.9.3-p194, which was the root cause of the block device handling issues.
9
+
1
10
  ## 1.6.14
2
11
 
3
12
  * Undo block device changes.
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ec2launcher (1.7.0)
5
+ aws-sdk (>= 1.8.0)
6
+ log4r
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ aws-sdk (1.9.5)
12
+ json (~> 1.4)
13
+ nokogiri (>= 1.4.4)
14
+ uuidtools (~> 2.1)
15
+ json (1.7.7)
16
+ log4r (1.1.10)
17
+ minitest (4.1.0)
18
+ nokogiri (1.5.9)
19
+ rake (0.9.2.2)
20
+ uuidtools (2.1.4)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ ec2launcher!
27
+ minitest
28
+ rake
data/Rakefile CHANGED
@@ -1,9 +1,18 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
3
  require 'rake/testtask'
4
+
4
5
  Rake::TestTask.new do |t|
6
+ t.name = "testspec"
5
7
  t.libs << 'lib/ec2launcher'
6
- t.test_files = FileList['test/ec2launcher/*_test.rb', "test/ec2launcher/dsl/*_test.rb"]
8
+ t.pattern = "test/spec/**/*_spec.rb"
7
9
  t.verbose = true
8
10
  end
9
- task :default => :test
11
+
12
+ Rake::TestTask.new do |t|
13
+ t.libs << 'lib/ec2launcher'
14
+ t.pattern = "test/unit/**/*_test.rb"
15
+ t.verbose = true
16
+ end
17
+
18
+ task :default => [:test, :testspec]
@@ -14,10 +14,11 @@ module EC2Launcher
14
14
  attr_reader :block_device_mappings
15
15
  attr_reader :block_device_tags
16
16
 
17
- # @param [AWS::EC2] ec2 interface to ec2
18
- # @param [Integer, nil] volume_size size of new EBS volumes. If set to nil, uses EC2Launcher::Defaults::DEFAULT_VOLUME_SIZE.
17
+ # @param [AWS::EC2] ec2 Interface to ec2
18
+ # @param [Integer, nil] volume_size Size of new EBS volumes. If set to nil, uses EC2Launcher::Defaults::DEFAULT_VOLUME_SIZE.
19
+ # @param [Log4r, nil] logger Optional logger.
19
20
  #
20
- def initialize(ec2, volume_size = nil)
21
+ def initialize(ec2, volume_size = nil, logger = nil)
21
22
  @ec2 = ec2
22
23
  @block_size = volume_size
23
24
  @volume_size ||= EC2Launcher::DEFAULT_VOLUME_SIZE
@@ -26,7 +27,8 @@ module EC2Launcher
26
27
  @block_device_tags = {}
27
28
 
28
29
  begin
29
- @log = Log4r::Logger['ec2launcher']
30
+ @log = logger
31
+ @log ||= Log4r::Logger['ec2launcher']
30
32
  rescue
31
33
  end
32
34
 
@@ -0,0 +1,56 @@
1
+ #
2
+ # Copyright (c) 2012-2013 Sean Laurent
3
+ #
4
+ require 'rubygems'
5
+ require 'aws-sdk'
6
+
7
+ require 'ec2launcher/hostnames/host_name_generation'
8
+
9
+ module EC2Launcher
10
+ # Helper class to generate unique host names
11
+ class DynamicHostnameGenerator
12
+ include HostNames::HostNameGeneration
13
+
14
+ # Creates a new generator for dynamic host names.
15
+ #
16
+ # @param [String] prefix Optional prefix for the hostname.
17
+ # @param [String] suffix Optional suffix for the hostname.
18
+ def initialize(prefix = nil, suffix = nil)
19
+ @prefix = prefix
20
+ @suffix = suffix
21
+
22
+ if prefix
23
+ @prefix = prefix.slice(0, prefix.length - 1) if prefix =~ /[.]$/
24
+ end
25
+
26
+ if suffix
27
+ @suffix = suffix.slice(1, suffix.length) if suffix =~ /^[.]/
28
+ @suffix = @suffix.slice(0, @suffix.length - 1) if @suffix =~ /[.]$/
29
+ end
30
+
31
+ @prefix = nil if @prefix && @prefix.size < 1
32
+ @suffix = nil if @suffix && @suffix.size < 1
33
+ end
34
+
35
+ # Given an instance id, generates a dynamic short hostname typically in the form:
36
+ #
37
+ # prefix + INSTANCE ID + application + environment
38
+ #
39
+ # Examples:
40
+ # 9803da2.web.prod (no prefix)
41
+ # app-d709aa2ab.server.dev (prefix = "app-")
42
+ #
43
+ # @param [String] instance_id AWS EC2 instance id
44
+ #
45
+ def generate_dynamic_hostname(instance_id)
46
+ instance_id_name = (instance_id =~ /^i-/ ? instance_id.gsub(/^i-/, '') : instance_id)
47
+
48
+ short_name = @prefix
49
+ short_name ||= ""
50
+ short_name += instance_id_name
51
+ short_name += ".#{@suffix}" if @suffix
52
+
53
+ short_name
54
+ end
55
+ end
56
+ end
@@ -5,26 +5,32 @@ require 'rubygems'
5
5
  require 'aws-sdk'
6
6
 
7
7
  require 'ec2launcher/backoff_runner'
8
+ require 'ec2launcher/dynamic_hostname_generator'
9
+ require 'ec2launcher/hostnames/host_name_generation'
8
10
 
9
11
  module EC2Launcher
10
12
  # Helper class to generate sequential, numbered host names
11
13
  class HostnameGenerator
12
14
  include BackoffRunner
15
+ include HostNames::HostNameGeneration
16
+
17
+ attr_reader :prefix
18
+ attr_reader :suffix
13
19
 
14
20
  #
15
21
  # @param [AWS::EC2] ec2 EC2 object used to query for existing instances
16
22
  # @param [EC2Launcher::Environment] environment Environment to use for generating host names
17
- # @param [EC2Launcher::Application] application Application to use for generating hostn ames
23
+ # @param [EC2Launcher::Application] application Application to use for generating host names
18
24
  def initialize(ec2, environment, application)
19
25
  @ec2 = ec2
20
- @server_name_cache = nil
26
+ @server_name_cache = nil
21
27
 
22
28
  @prefix = application.basename
23
29
  @prefix ||= application.name
24
30
 
25
31
  @env_suffix = environment.short_name
26
32
  @env_suffix ||= environment.name
27
-
33
+
28
34
  @suffix = @env_suffix
29
35
  unless application.name_suffix.nil?
30
36
  @suffix = "#{application.name_suffix}.#{@env_suffix}"
@@ -34,6 +40,27 @@ module EC2Launcher
34
40
 
35
41
  # Load and cache instance names
36
42
  load_instances(@prefix, @suffix)
43
+
44
+ @dynamic_generator = EC2Launcher::DynamicHostnameGenerator.new(nil, "#{@prefix}.#{@suffix}")
45
+ end
46
+
47
+ # Given an instance id, generates a dynamic short hostname typically in the form:
48
+ #
49
+ # prefix + INSTANCE ID + application + environment
50
+ #
51
+ # Examples:
52
+ # 9803da2.web.prod (no prefix)
53
+ # app-d709aa2ab.server.dev (prefix = "app-")
54
+ #
55
+ # @param [String] instance_id AWS EC2 instance id
56
+ #
57
+ def generate_dynamic_hostname(instance_id)
58
+ short_name = @dynamic_generator.generate_dynamic_hostname(instance_id)
59
+
60
+ # Cache the new hostname
61
+ @server_name_cache << short_name
62
+
63
+ short_name
37
64
  end
38
65
 
39
66
  # Generates a new host name and automatically caches it
@@ -51,23 +78,6 @@ module EC2Launcher
51
78
  short_name
52
79
  end
53
80
 
54
- def generate_long_name(short_hostname, domain_name = nil)
55
- hostname = short_hostname
56
- unless domain_name.nil?
57
- hostname += ".#{domain_name}"
58
- end
59
-
60
- hostname
61
- end
62
-
63
- def generate_short_name(long_name, domain_name = nil)
64
- short_hostname = long_name
65
- unless domain_name.nil?
66
- short_hostname = long_name.gsub(/.#{domain_name}/, '')
67
- end
68
- short_hostname
69
- end
70
-
71
81
  private
72
82
 
73
83
  # Loads and caches instance host names
@@ -0,0 +1,42 @@
1
+ #
2
+ # Copyright (c) 2012-2013 Sean Laurent
3
+ #
4
+ module EC2Launcher
5
+ module HostNames
6
+ module HostNameGeneration
7
+ # Given a short host name and domain name, generate a Fully Qualified Domain Name.
8
+ #
9
+ # @param [String] short_hostname Shortened host name.
10
+ # @param [String] domain_name Optional domain name ie 'example.com'
11
+ def generate_fqdn(short_hostname, domain_name = nil)
12
+ raise ArgumentError, 'short_hostname is invalid' if short_hostname.nil?
13
+
14
+ hostname = short_hostname
15
+ unless domain_name.nil?
16
+ unless hostname =~ /[.]$/ || domain_name =~ /^[.]/
17
+ hostname += "."
18
+ end
19
+ hostname += domain_name
20
+ end
21
+
22
+ hostname
23
+ end
24
+
25
+ # Given a FQDN and a domain name, produce a shortened version of the host name
26
+ # without the domain.
27
+ #
28
+ # @param [String] long_name FQDN ie 'foo1.prod.example.com'
29
+ # @param [String] domain_name Optional domain name ie 'example.com'
30
+ def generate_short_name(long_name, domain_name = nil)
31
+ raise ArgumentError, 'long_name is invalid' if long_name.nil?
32
+
33
+ short_hostname = long_name
34
+ unless domain_name.nil?
35
+ short_hostname = long_name.gsub(/#{domain_name}/, '')
36
+ short_hostname = short_hostname.slice(0, short_hostname.length - 1) if short_hostname =~ /[.]$/
37
+ end
38
+ short_hostname
39
+ end
40
+ end
41
+ end
42
+ end
@@ -108,9 +108,17 @@ EOH
108
108
  @options.skip_setup = true
109
109
  end
110
110
 
111
+ opts.on("--pretty-print", "Use pretty format for JSON user-data. Defaults to off. Only recommended for testing.") do
112
+ @options.pretty_print = true
113
+ end
114
+
111
115
  opts.separator ""
112
116
  opts.separator "Launch overrides:"
113
117
 
118
+ opts.on("-d", "--dynamic-name", "Dynamically set the host name based on instance id.") do |dynamic_name|
119
+ @options.dynamic_name = dynamic_name
120
+ end
121
+
114
122
  opts.on("-h", "--hostname NAME", String, "The name for the new server.") do |hostname|
115
123
  @options.hostname = hostname
116
124
  end
@@ -192,6 +200,7 @@ EOH
192
200
  @options.skip_setup = false
193
201
 
194
202
  @options.ami_id = nil
203
+ @options.dynamic_name = false
195
204
  @options.hostname = nil
196
205
  @options.zone = nil
197
206
  @options.instance_type = nil
@@ -200,6 +209,7 @@ EOH
200
209
  @options.snapshot_removal = true
201
210
  @options.force = false
202
211
 
212
+ @options.pretty_print = false
203
213
  @options.verbosity = :normal
204
214
 
205
215
  @options.directory = "./"
@@ -71,12 +71,15 @@ module EC2Launcher
71
71
  #
72
72
  def delete_record_by_name(hostname, record_type = "A", log_errors = true)
73
73
  # Search for the record
74
+ delete_result = true
74
75
  record = find_record(hostname, record_type)
75
76
  if record
76
77
  delete_record(record.name, record.type, record.ttl, record.value, log_errors)
77
78
  else
79
+ delete_result = false
78
80
  @log.warn "Route53 '#{record_type}' record for '#{hostname}' not found!" if log_errors
79
81
  end
82
+ delete_result
80
83
  end
81
84
 
82
85
  # Deletes a DNS record from Route53.
@@ -88,6 +91,7 @@ module EC2Launcher
88
91
  # @param [Boolean] log_errors Log errors or not. False quietly ignores errors.
89
92
  #
90
93
  def delete_record(name, type, ttl, value, log_errors = true)
94
+ delete_result = true
91
95
  begin
92
96
  @route53.client.change_resource_record_sets({
93
97
  :hosted_zone_id => @hosted_zone_id,
@@ -107,7 +111,9 @@ module EC2Launcher
107
111
  })
108
112
  rescue StandardError => bang
109
113
  @log.error "Error deleting A record from Route53: #{bang}" if log_errors
114
+ delete_result = false
110
115
  end
116
+ delete_result
111
117
  end
112
118
 
113
119
  # Searches for a record with the specified name and type.
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.6.15"
5
+ VERSION = "1.7.0"
6
6
  end
data/lib/ec2launcher.rb CHANGED
@@ -241,36 +241,38 @@ module EC2Launcher
241
241
  ##############################
242
242
  # HOSTNAME
243
243
  ##############################
244
- hostname_generator = EC2Launcher::HostnameGenerator.new(@ec2, @environment, @application)
244
+ @hostname_generator = EC2Launcher::HostnameGenerator.new(@ec2, @environment, @application)
245
245
  short_hostnames = []
246
246
  fqdn_names = []
247
- if @options.count > 1
248
- 1.upto(@options.count).each do |i|
249
- short_hostname = hostname_generator.generate_hostname()
250
- long_hostname = hostname_generator.generate_long_name(short_hostname, @domain_name)
251
- short_hostnames << short_hostname
252
- fqdn_names << long_hostname
253
- end
254
- else
255
- if @options.hostname.nil?
256
- short_hostname = hostname_generator.generate_hostname()
257
- long_hostname = hostname_generator.generate_long_name(short_hostname, @domain_name)
247
+ unless @options.dynamic_name
248
+ if @options.count > 1
249
+ 1.upto(@options.count).each do |i|
250
+ short_hostname = @hostname_generator.generate_hostname()
251
+ long_hostname = @hostname_generator.generate_fqdn(short_hostname, @domain_name)
252
+ short_hostnames << short_hostname
253
+ fqdn_names << long_hostname
254
+ end
258
255
  else
259
- long_hostname = @options.hostname
260
- short_hostname = hostname_generator.generate_short_name(long_hostname, @environment.domain_name)
261
- if long_hostname == short_hostname
262
- long_hostname = hostname_generator.generate_long_name(short_hostname, @environment.domain_name)
256
+ if @options.hostname.nil?
257
+ short_hostname = @hostname_generator.generate_hostname()
258
+ long_hostname = @hostname_generator.generate_fqdn(short_hostname, @domain_name)
259
+ else
260
+ long_hostname = @options.hostname
261
+ short_hostname = @hostname_generator.generate_short_name(long_hostname, @environment.domain_name)
262
+ if long_hostname == short_hostname
263
+ long_hostname = @hostname_generator.generate_fqdn(short_hostname, @environment.domain_name)
264
+ end
263
265
  end
266
+ short_hostnames << short_hostname
267
+ fqdn_names << long_hostname
264
268
  end
265
- short_hostnames << short_hostname
266
- fqdn_names << long_hostname
267
269
  end
268
270
 
269
271
  ##############################
270
272
  # Block devices
271
273
  ##############################
272
- block_device_builder = EC2Launcher::BlockDeviceBuilder.new(@ec2, @options.volume_size)
273
- block_device_mappings = block_device_builder.generate_block_devices(instance_type, @environment, @application, @options.clone_host)
274
+ @block_device_builder = EC2Launcher::BlockDeviceBuilder.new(@ec2, @options.volume_size)
275
+ block_device_mappings = @block_device_builder.generate_block_devices(instance_type, @environment, @application, @options.clone_host)
274
276
 
275
277
  ##############################
276
278
  # ELB
@@ -341,8 +343,12 @@ module EC2Launcher
341
343
  @log.info "VPC Subnet : #{subnet} (#{cidr_block})"
342
344
  end
343
345
  @log.info ""
344
- fqdn_names.each do |fqdn|
345
- @log.info "Name : #{fqdn}"
346
+ if @options.dynamic_name
347
+ @log.info "Name : **dynamic**"
348
+ else
349
+ fqdn_names.each do |fqdn|
350
+ @log.info "Name : #{fqdn}"
351
+ end
346
352
  end
347
353
 
348
354
  unless block_device_mappings.empty?
@@ -387,19 +393,24 @@ module EC2Launcher
387
393
  }
388
394
 
389
395
  # Quit if we're only displaying the defaults
390
- if @options.show_defaults || @options.show_user_data
391
- if @options.show_user_data
392
- user_data = build_launch_command(
393
- launch_options.merge({
394
- :fqdn => fqdn_names[0],
395
- :short_name => short_hostnames[0]
396
- })
397
- )
398
- @log.info ""
399
- @log.info "---user-data---"
400
- @log.info user_data
401
- @log.info "---user-data---"
396
+ exit 0 if @options.show_defaults
397
+
398
+ if @options.show_user_data
399
+ custom_launch_options = launch_options
400
+ unless @options.dynamic_name
401
+ custom_launch_options = launch_options.merge({
402
+ :fqdn => fqdn_names[0],
403
+ :short_name => short_hostnames[0]
404
+ })
402
405
  end
406
+
407
+ user_data = build_launch_command(custom_launch_options)
408
+
409
+ @log.info ""
410
+ @log.info "---user-data---"
411
+ @log.info user_data
412
+ @log.info "---user-data---"
413
+
403
414
  exit 0
404
415
  end
405
416
 
@@ -408,11 +419,20 @@ module EC2Launcher
408
419
  ##############################
409
420
  @log.warn ""
410
421
  instances = []
411
- fqdn_names.each_index do |i|
412
- block_device_tags = block_device_builder.generate_device_tags(fqdn_names[i], short_hostnames[i], @environment.name, @application.block_devices)
422
+ new_instance_names = []
423
+ 0.upto(@options.count - 1).each do |i|
424
+ fqdn = nil
425
+ short_hostname = nil
426
+
427
+ unless @options.dynamic_name
428
+ fqdn = fqdn_names[i]
429
+ short_hostname = short_hostnames[i]
430
+ end
431
+
432
+ block_device_tags = @block_device_builder.generate_device_tags(fqdn, short_hostname, @environment.name, @application.block_devices)
413
433
  launch_options.merge!({
414
- :fqdn => fqdn_names[i],
415
- :short_name => short_hostnames[i],
434
+ :fqdn => fqdn,
435
+ :short_name => short_hostname,
416
436
  :block_device_tags => block_device_tags,
417
437
  })
418
438
  user_data = build_launch_command(launch_options)
@@ -420,16 +440,23 @@ module EC2Launcher
420
440
  instance = launch_instance(launch_options, user_data)
421
441
  instances << instance
422
442
 
443
+ if @options.dynamic_name
444
+ short_hostname = @hostname_generator.generate_dynamic_hostname(instance.id)
445
+ fqdn = @hostname_generator.generate_fqdn(short_hostname, @environment.domain_name)
446
+ end
447
+
423
448
  public_dns_name = get_instance_dns(instance, true)
424
449
  private_dns_name = get_instance_dns(instance, false)
425
- @log.info "Launched #{fqdn_names[i]} (#{instance.id}) [#{public_dns_name} / #{private_dns_name} / #{instance.private_ip_address} ]"
450
+ @log.info "Launched #{fqdn} (#{instance.id}) [#{public_dns_name} / #{private_dns_name} / #{instance.private_ip_address} ]"
451
+
452
+ new_instance_names << fqdn
426
453
  end
427
454
 
428
455
  @log.info "********************"
429
- fqdn_names.each_index do |i|
456
+ new_instance_names.each_index do |i|
430
457
  public_dns_name = get_instance_dns(instances[i], true)
431
458
  private_dns_name = get_instance_dns(instances[i], false)
432
- @log.warn "** New instance: #{fqdn_names[i]} | #{instances[i].id} | #{public_dns_name} | #{private_dns_name} | #{instances[i].private_ip_address}"
459
+ @log.warn "** New instance: #{new_instance_names[i]} | #{instances[i].id} | #{public_dns_name} | #{private_dns_name} | #{instances[i].private_ip_address}"
433
460
  end
434
461
 
435
462
  ##############################
@@ -633,6 +660,12 @@ module EC2Launcher
633
660
  exit 5
634
661
  end
635
662
 
663
+ if @options.dynamic_name
664
+ launch_options[:short_name] = @hostname_generator.generate_dynamic_hostname(new_instance.id)
665
+ launch_options[:fqdn] = @hostname_generator.generate_fqdn(launch_options[:short_name], @environment.domain_name)
666
+ launch_options[:block_device_tags] = @block_device_builder.generate_device_tags(launch_options[:fqdn], launch_options[:short_name], @environment.name, @application.block_devices)
667
+ end
668
+
636
669
  ##############################
637
670
  # Tag instance
638
671
  @log.info "Tagging instance..."
@@ -697,11 +730,15 @@ module EC2Launcher
697
730
  cmd
698
731
  end
699
732
 
700
- def load_and_encode_file(base_path, filename)
701
- pathname = File.join(base_path, filename)
733
+ def load_and_encode_file(pathname)
702
734
  `cat #{pathname} |gzip -f |base64`
703
735
  end
704
736
 
737
+ def load_and_encode_file_with_path(base_path, filename)
738
+ pathname = File.join(base_path, filename)
739
+ load_and_encode_file(pathname)
740
+ end
741
+
705
742
  # Builds the launch scripts that should run on the new instance.
706
743
  #
707
744
  # launch_options = {
@@ -739,8 +776,16 @@ module EC2Launcher
739
776
  'aws_keyfile' => launch_options[:aws_keyfile],
740
777
  'gems' => launch_options[:gems],
741
778
  'packages' => launch_options[:packages],
742
- 'provisioned_iops' => false
779
+ 'provisioned_iops' => false,
780
+ 'dynamic_name' => @options.dynamic_name,
781
+ 'domain_name' => @environment.domain_name
743
782
  }
783
+ if @options.dynamic_name
784
+ # setup_json['dynamic_name_prefix'] = @hostname_generator.prefix
785
+ setup_json['dynamic_name_suffix'] = "#{@hostname_generator.prefix}.#{@hostname_generator.suffix}"
786
+ setup_json['route53_zone_id'] = @route53_zone_id
787
+ end
788
+
744
789
  setup_json["gem_path"] = @instance_paths.gem_path
745
790
  setup_json["ruby_path"] = @instance_paths.ruby_path
746
791
  setup_json["chef_path"] = @instance_paths.chef_path
@@ -762,10 +807,11 @@ module EC2Launcher
762
807
 
763
808
  ##############################
764
809
  # Build launch command
810
+ json_text = @options.pretty_print ? JSON.pretty_generate(setup_json) : setup_json.to_json
765
811
  user_data = <<EOF
766
812
  #!/bin/bash
767
813
  cat > /tmp/setup.json <<End-Of-Message-JSON
768
- #{setup_json.to_json}
814
+ #{json_text}
769
815
  End-Of-Message-JSON
770
816
  EOF
771
817
  if @environment.use_rvm or @application.use_rvm
@@ -783,15 +829,15 @@ EOF
783
829
 
784
830
  unless @options.skip_setup
785
831
  if @run_url_script_cache.nil?
786
- @run_url_script_cache = load_and_encode_file(@startup_scripts_dir, "runurl")
832
+ @run_url_script_cache = load_and_encode_file_with_path(@startup_scripts_dir, "runurl")
787
833
  end
788
834
 
789
835
  if @setup_script_cache.nil?
790
- @setup_script_cache = load_and_encode_file(@startup_scripts_dir, "setup.rb")
836
+ @setup_script_cache = load_and_encode_file_with_path(@startup_scripts_dir, "setup.rb")
791
837
  end
792
838
 
793
839
  if @setup_instance_script_cache.nil?
794
- @setup_instance_script_cache = load_and_encode_file(@startup_scripts_dir, "setup_instance.rb")
840
+ @setup_instance_script_cache = load_and_encode_file_with_path(@startup_scripts_dir, "setup_instance.rb")
795
841
  end
796
842
 
797
843
  # runurl script
@@ -822,9 +868,11 @@ EOF
822
868
 
823
869
  user_data += "\ngem install ec2launcher --no-ri --no-rdoc"
824
870
 
825
- user_data += "\n#{setup_json['ruby_path']} /tmp/setup.rb -e #{@environment.name} -a #{@application.name} -h #{launch_options[:fqdn]} /tmp/setup.json"
871
+ user_data += "\n#{setup_json['ruby_path']} /tmp/setup.rb -e #{@environment.name} -a #{@application.name}"
872
+ user_data += " -h #{launch_options[:fqdn]}" if launch_options[:fqdn]
873
+ user_data += " /tmp/setup.json"
826
874
  user_data += " -c #{@options.clone_host}" unless @options.clone_host.nil?
827
- user_data += " 2>&1 > /var/log/cloud-startup.log"
875
+ user_data += " &> /var/log/cloud-startup.log"
828
876
  end
829
877
 
830
878
  # Add extra requested commands to the launch sequence