ec2launcher 1.3.5 → 1.3.7

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,11 @@
1
+ ## 1.3.7
2
+
3
+ * Added exponential back off to termination process.
4
+
5
+ ## 1.3.6
6
+
7
+ * Fixed error checking when deleting records from Route53 to be a little less aggressive.
8
+
1
9
  ## 1.3.5
2
10
 
3
11
  * Fixed typo.
@@ -8,8 +8,17 @@ require 'log4r'
8
8
  include Log4r
9
9
 
10
10
  module EC2Launcher
11
+ class Route53Record
12
+ attr_reader :name, :type, :ttl, :value
13
+ def initialize(name, type, ttl, value)
14
+ @name = name
15
+ @type = type
16
+ @ttl = ttl
17
+ @value = value
18
+ end
19
+ end
20
+
11
21
  class Route53
12
- #
13
22
  # @param [AWS::Route53] route53 Initialized Route53 object
14
23
  # @param [String] hosted_zone_id Zone ID
15
24
  # @param [Log4r::Logger]
@@ -29,7 +38,7 @@ module EC2Launcher
29
38
  # @param [Integer] ttl TTL in seconds. Defaults to 300.
30
39
  def create_record(name, value, type = "A", ttl = 300)
31
40
  # Delete existing record because you can't update records
32
- delete_record_by_name(name, type)
41
+ delete_record_by_name(name, type, false)
33
42
 
34
43
  # Create new record
35
44
  begin
@@ -61,25 +70,13 @@ module EC2Launcher
61
70
  # @param [Boolean] log_errors Log errors or not. False quietly ignores errors.
62
71
  #
63
72
  def delete_record_by_name(hostname, record_type = "A", log_errors = true)
64
- # Find the record
65
- response = @route53.client.list_resource_record_sets({
66
- :hosted_zone_id => @hosted_zone_id,
67
- :start_record_name => hostname,
68
- :start_record_type => record_type,
69
- :max_items => 1
70
- })
71
-
72
- record_found = false
73
- if response && response.data
74
- if response.data[:resource_record_sets] && response.data[:resource_record_sets].size > 0
75
- record = response.data[:resource_record_sets][0]
76
- if record[:name] == hostname && record[:type] == record_type
77
- record_found = true
78
- delete_record(record[:name], record[:type], record[:ttl], record[:resource_records][0][:value], log_errors)
79
- end
80
- end
73
+ # Search for the record
74
+ record = find_record(hostname, record_type)
75
+ if record
76
+ delete_record(record.name, record.type, record.ttl, record.value, log_errors)
77
+ else
78
+ @log.warn "Route53 '#{record_type}' record for '#{hostname}' not found!" if log_errors
81
79
  end
82
- @log.info("Route53 '#{record_type}' record for #{hostname} not found.") unless record_found
83
80
  end
84
81
 
85
82
  # Deletes a DNS record from Route53.
@@ -112,5 +109,34 @@ module EC2Launcher
112
109
  @log.error "Error deleting A record from Route53: #{bang}" if log_errors
113
110
  end
114
111
  end
112
+
113
+ # Searches for a record with the specified name and type.
114
+ #
115
+ # @param [String] name Name of the record
116
+ # @param [String] type Type of DNS record: A, CNAME, etc.
117
+ #
118
+ # @return [EC2Launcher::Route53Record] Wrapper containing all the
119
+ # required information about a Route53 entry or nil if not found.
120
+ def find_record(name, type = 'A')
121
+ # Find the record
122
+ response = @route53.client.list_resource_record_sets({
123
+ :hosted_zone_id => @hosted_zone_id,
124
+ :start_record_name => name,
125
+ :start_record_type => type,
126
+ :max_items => 1
127
+ })
128
+
129
+ record = nil
130
+ if response && response.data
131
+ if response.data[:resource_record_sets] && response.data[:resource_record_sets].size > 0
132
+ response_record = response.data[:resource_record_sets][0]
133
+ if (response_record[:name] == name || response_record[:name] == "#{name}.") && response_record[:type] == type
134
+ record = Route53Record.new(response_record[:name], response_record[:type], response_record[:ttl], response_record[:resource_records][0][:value])
135
+ end
136
+ end
137
+ end
138
+
139
+ record
140
+ end
115
141
  end
116
142
  end
@@ -68,8 +68,9 @@ module EC2Launcher
68
68
  if instance
69
69
  private_ip_address = instance.private_ip_address
70
70
 
71
- @log.info("Terminating instance: #{server_name} [#{instance.instance_id}]")
72
- instance.terminate
71
+ run_with_backoff(30, 1, "terminating instance: #{server_name} [#{instance.instance_id}]") do
72
+ instance.terminate
73
+ end
73
74
 
74
75
  if @route53
75
76
  @log.info("Deleting A record from Route53: #{server_name} => #{private_ip_address}")
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.3.5"
5
+ VERSION = "1.3.7"
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.3.5
4
+ version: 1.3.7
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-10-11 00:00:00.000000000 Z
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk