ec2launcher 1.5.0 → 1.5.1

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 CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.5.1
2
+
3
+ * Change order for processing environment aliases.
4
+
1
5
  ## 1.5.0
2
6
 
3
7
  * Initial support for Provisioned IOPS for EBS volumes.
@@ -28,7 +28,6 @@ module EC2Launcher
28
28
  validate_environment(filename, new_env)
29
29
 
30
30
  @environments[new_env.name] = new_env
31
- new_env.aliases.each {|env_alias| @environments[env_alias] = new_env }
32
31
  end
33
32
  end
34
33
 
@@ -37,6 +36,11 @@ module EC2Launcher
37
36
  new_env = process_environment_inheritance(env)
38
37
  @environments[new_env.name] = new_env
39
38
  end
39
+
40
+ # Process aliases
41
+ @environments.values.each do |env|
42
+ env.aliases.each {|env_alias| @environments[env_alias] = env }
43
+ end
40
44
  end
41
45
 
42
46
  private
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.5.0"
5
+ VERSION = "1.5.1"
6
6
  end
@@ -113,17 +113,18 @@ class InstanceSetup
113
113
  ##############################
114
114
  # EBS VOLUMES
115
115
  ##############################
116
- # Create and setup EBS volumes =
116
+ @system_arch = `uname -p`.strip
117
+ @default_fs_type = @system_arch == "x86_64" ? "xfs" : "ext4"
118
+
119
+ # Create and setup EBS volumes
117
120
  setup_ebs_volumes(instance_data) unless instance_data["block_devices"].nil?
118
121
 
119
122
  ##############################
120
123
  # EPHEMERAL VOLUMES
121
124
  ##############################
122
- system_arch = `uname -p`.strip
123
- default_fs_type = system_arch == "x86_64" ? "xfs" : "ext4"
124
125
 
125
126
  # Process ephemeral devices first
126
- ephemeral_drive_count = case EC2_INSTANCE_TYPE
127
+ ephemeral_drive_count = case @EC2_INSTANCE_TYPE
127
128
  when "m1.small" then 1
128
129
  when "m1.medium" then 1
129
130
  when "m2.xlarge" then 1
@@ -148,13 +149,13 @@ class InstanceSetup
148
149
 
149
150
  # Format and mount the ephemeral drives
150
151
  build_block_devices(ephemeral_drive_count, "xvdf") do |device_name, index|
151
- format_filesystem(system_arch, "/dev/#{device_name}1")
152
+ format_filesystem(@system_arch, "/dev/#{device_name}1")
152
153
 
153
154
  mount_point = case index
154
155
  when 0 then "/mnt"
155
156
  else "/mnt/extra#{index - 1}"
156
157
  end
157
- mount_device("/dev/#{device_name}1", mount_point, "root", "root", default_fs_type)
158
+ mount_device("/dev/#{device_name}1", mount_point, "root", "root", @default_fs_type)
158
159
  end
159
160
 
160
161
  ##############################
@@ -170,7 +171,7 @@ class InstanceSetup
170
171
  knife_config = <<EOF
171
172
  log_level :info
172
173
  log_location STDOUT
173
- node_name '#{options.hostname}'
174
+ node_name '#{@options.hostname}'
174
175
  client_key '/etc/chef/client.pem'
175
176
  validation_client_name 'chef-validator'
176
177
  validation_key '/etc/chef/validation.pem'
@@ -186,7 +187,7 @@ EOF
186
187
  ##############################
187
188
  # Add roles
188
189
  instance_data["roles"].each do |role|
189
- cmd = "#{knife_path} node run_list add #{options.hostname} \"role[#{role}]\""
190
+ cmd = "#{knife_path} node run_list add #{@options.hostname} \"role[#{role}]\""
190
191
  puts cmd
191
192
  puts `#{cmd}`
192
193
  end
@@ -217,9 +218,9 @@ EOF
217
218
  ses.send_email(
218
219
  :from => instance_data["email_notifications"]["from"],
219
220
  :to => instance_data["email_notifications"]["to"],
220
- :subject => "Server setup complete: #{options.hostname}",
221
- :body_text => "Server setup is complete for Host: #{options.hostname}, Environment: #{options.environ}, Application: #{options.application}",
222
- :body_html => "<div>Server setup is complete for:</div><div><strong>Host:</strong> #{options.hostname}</div><div><strong>Environment:</strong> #{options.environ}</div><div><strong>Application:</strong> #{options.application}</div>"
221
+ :subject => "Server setup complete: #{@options.hostname}",
222
+ :body_text => "Server setup is complete for Host: #{@options.hostname}, Environment: #{@options.environ}, Application: #{@options.application}",
223
+ :body_html => "<div>Server setup is complete for:</div><div><strong>Host:</strong> #{@options.hostname}</div><div><strong>Environment:</strong> #{@options.environ}</div><div><strong>Application:</strong> #{@options.application}</div>"
223
224
  )
224
225
  else
225
226
  puts "Skipping email notification."
@@ -270,8 +271,15 @@ EOF
270
271
  run_with_backoff(60, 1, "attaching volume #{volume.id} to #{device_name}") do
271
272
  attachment = volume.attach_to(instance, device_name)
272
273
  end
274
+
273
275
  volume_attached = test_with_backoff(60, 1, "check EBS volume attached #{device_name} (#{volume.id})") do
274
- attachment.status == :attached
276
+ attatched = false
277
+ begin
278
+ attached = attachment.status == :attached
279
+ rescue AWS::Core::Resource::NotFound
280
+ # This can occur when trying to access the attachment. Not sure how or why. Best to retry.
281
+ end
282
+ attached
275
283
  end
276
284
 
277
285
  # TODO: Handle when volume fails to attach
@@ -360,24 +368,24 @@ EOF
360
368
 
361
369
  raid_array_count = 0
362
370
  next_device_name = "xvdj"
363
- instance_data["block_devices"].each do |block_device_json|
364
- if block_device_json["raid_level"].nil?
371
+ instance_data["block_devices"].each do |block_device|
372
+ if block_device.raid_level.nil?
365
373
  # If we're not cloning an existing snapshot, then we need to partition and format the drive.
366
- if options.clone_host.nil?
374
+ if @options.clone_host.nil?
367
375
  partition_devices([ "/dev/#{next_device_name}" ])
368
- format_filesystem(system_arch, "/dev/#{next_device_name}1")
376
+ format_filesystem(@system_arch, "/dev/#{next_device_name}1")
369
377
  end
370
- mount_device("/dev/#{next_device_name}1", block_device_json["mount_point"], block_device_json["owner"], block_device_json["group"], default_fs_type)
378
+ mount_device("/dev/#{next_device_name}1", block_device.mount, block_device.owner, block_device.group, @default_fs_type)
371
379
  next_device_name.next!
372
380
  else
373
381
  raid_devices = []
374
- build_block_devices(block_device_json["count"], next_device_name) do |device_name, index|
382
+ build_block_devices(block_device.count, next_device_name) do |device_name, index|
375
383
  raid_devices << "/dev/#{device_name}"
376
384
  next_device_name = device_name
377
385
  end
378
- puts "Setting up attached raid array... system_arch = #{system_arch}, raid_devices = #{raid_devices}, device = /dev/md#{(127 - raid_array_count).to_s}"
379
- raid_device_name = setup_attached_raid_array(system_arch, raid_devices, "/dev/md#{(127 - raid_array_count).to_s}", block_device_json["raid_level"].to_i, ! options.clone_host.nil?)
380
- mount_device(raid_device_name, block_device_json["mount_point"], block_device_json["owner"], block_device_json["group"], default_fs_type)
386
+ puts "Setting up attached raid array... system_arch = #{@system_arch}, raid_devices = #{raid_devices}, device = /dev/md#{(127 - raid_array_count).to_s}"
387
+ raid_device_name = setup_attached_raid_array(@system_arch, raid_devices, "/dev/md#{(127 - raid_array_count).to_s}", block_device.raid_level.to_i, ! @options.clone_host.nil?)
388
+ mount_device(raid_device_name, block_device.mount, block_device.owner, block_device.group, @default_fs_type)
381
389
  raid_array_count += 1
382
390
  end
383
391
  end
@@ -423,8 +431,14 @@ EOF
423
431
  end
424
432
 
425
433
  # Partitions a list of mounted EBS volumes
426
- def partition_devices(device_list)
427
- puts "Partioning devices ..."
434
+ def partition_devices(device_list, attempt = 0, max_attempts = 3)
435
+ return false if attempt >= max_attempts
436
+
437
+ puts case attempt
438
+ when 0 then "Partioning devices ..."
439
+ else "Retrying device partitioning (attempt #{attempt + 1}) ..."
440
+ end
441
+
428
442
  device_list.each do |device|
429
443
  puts " * #{device}"
430
444
  `echo 0|sfdisk #{device}`
@@ -432,6 +446,19 @@ EOF
432
446
 
433
447
  puts "Sleeping 10 seconds to reload partition tables ..."
434
448
  sleep 10
449
+
450
+ # Verify all volumes were properly partitioned
451
+ missing_devices = []
452
+ device_list.each do |device|
453
+ missing_devices << device unless File.exists?("#{device}1")
454
+ end
455
+
456
+ # Retry partitioning for failed volumes
457
+ response = true
458
+ if missing_devices.size > 0
459
+ response = partition_devices(missing_devices, attempt + 1, max_attempts)
460
+ end
461
+ response
435
462
  end
436
463
 
437
464
  ##############################
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.5.0
4
+ version: 1.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk