ec2launcher 1.0.3 → 1.0.4

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.
@@ -115,10 +115,14 @@ module EC2Launcher
115
115
  base_device_name = "sdf"
116
116
  application.block_devices.each do |block_device|
117
117
  if block_device.raid_level.nil?
118
- @block_device_mappings["/dev/#{base_device_name}"][:snapshot_id] = get_latest_snapshot(clone_short_hostname, clone_host, block_device.name).id
118
+ latest_snapshot = get_latest_snapshot_by_purpose(clone_host, block_device.name)
119
+ abort("Unable to find snapshot for #{clone_host} [#{block_device.name}]") if latest_snapshot.nil?
120
+ @block_device_mappings["/dev/#{base_device_name}"][:snapshot_id] = latest_snapshot.id
119
121
  base_device_name.next!
120
122
  else
121
123
  snapshots = get_latest_raid_snapshot_mapping(clone_host, block_device.name, block_device.count)
124
+ abort("Unable to find snapshot for #{clone_host} [#{block_device.name}]") if snapshots.nil?
125
+ abort("Incorrect snapshot count for #{clone_host} [#{block_device.name}]. Expected: #{block_device.count}, Found: #{snapshots.length}") if snapshots.length != block_device.count
122
126
  build_block_devices(block_device.count, base_device_name) do |device_name, index|
123
127
  @block_device_mappings["/dev/#{device_name}"][:snapshot_id] = snapshots[(index + 1).to_s].id
124
128
  end
@@ -134,7 +138,7 @@ module EC2Launcher
134
138
  # @param [String] instance_type type of instance. See EC2Launcher::Defaults::INSTANCE_TYPES.
135
139
  # @param [EC2Launcher::Environment] environment current environment
136
140
  # @param [EC2Launcher::Application] application current application
137
- # @param [String, nil] clone_host FQDN of host to clone or nill to skip cloning.
141
+ # @param [String, nil] clone_host FQDN of host to clone or nil to skip cloning.
138
142
  #
139
143
  def generate_block_devices(hostname, short_hostname, instance_type, environment, application, clone_host = nil)
140
144
  build_ephemeral_drives(instance_type)
@@ -236,32 +240,20 @@ module EC2Launcher
236
240
  snapshot_mapping
237
241
  end
238
242
 
239
- # Retrieves the most recent snapshot with a specific name AND one or more other filters
243
+ # Retrieves the most recent snapshot from a specific host that also has
244
+ # tag called "purpose" with the specified value.
240
245
  #
241
- # @param [String] server_name name of server with the volume to clone.
242
- # @param [String, nil] extra additional AWS compatible filters for searching.
246
+ # @param [String] clone_host FQDN name of server with the volume to clone.
247
+ # @param [String] purpose Value of the purpose tag.
243
248
  #
244
249
  # @return [AWS::EC2::Snapshot, nil] matching snapshot or nil if no matching snapshot
245
250
  #
246
- def get_latest_snapshot(server_name, extra = nil)
247
- puts " Retrieving snapshot for #{server_name} #{extra}"
248
-
249
- filter = server_name
250
- filter += " (#{server_name} #{extra})" unless extra.nil? || extra.empty?
251
- get_latest_snapshot_by_name(filter)
252
- end
253
-
254
- # Retrieves the most recent snapshot for a volume with a specific name
255
- #
256
- # @param [String] name_filter AWS compatible filter for the Name tag on a snapshot
257
- #
258
- # @return [AWS::EC2::Snapshot, nil] matching snapshot or nil if no matching snapshot
259
- #
260
- def get_latest_snapshot_by_name(name_filter)
261
- puts " Retrieving snapshot with filter tag:Name='#{name_filter}'"
262
-
251
+ def get_latest_snapshot_by_purpose(clone_host, purpose)
252
+ puts " Retrieving snapshtos for #{clone_host} [#{purpose}]"
253
+ results = @ec2.snapshots.tagged("host").tagged_values(clone_host).tagged("purpose").tagged_values(purpose)
254
+
263
255
  snapshot = nil
264
- @ec2.snapshots.filter("tag:Name", name_filter).each do |s|
256
+ results.each do |s|
265
257
  next unless s.status == :completed
266
258
  snapshot = s if snapshot.nil? || snapshot.start_time < s.start_time
267
259
  end
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module Ec2launcher
5
- VERSION = "1.0.3"
5
+ VERSION = "1.0.4"
6
6
  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.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: