ec2_ultradns_updater 0.0.5 → 0.0.6

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.
@@ -1,17 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ec2_ultradns_updater (0.0.3)
4
+ ec2_ultradns_updater (0.0.6)
5
5
  aws-sdk
6
- savon
6
+ savon (= 0.9.9)
7
+ wasabi (= 2.1.0)
7
8
 
8
9
  GEM
9
10
  remote: http://rubygems.org/
10
11
  remote: http://gems.github.com/
11
12
  specs:
12
- akami (1.0.0)
13
+ akami (1.1.0)
13
14
  gyoku (>= 0.4.0)
14
- aws-sdk (1.5.2)
15
+ nokogiri (>= 1.5.2)
16
+ aws-sdk (1.5.3)
15
17
  httparty (~> 0.7)
16
18
  json (~> 1.4)
17
19
  nokogiri (>= 1.4.4)
@@ -29,7 +31,7 @@ GEM
29
31
  json (1.7.3)
30
32
  multi_json (1.3.6)
31
33
  multi_xml (0.5.1)
32
- nokogiri (1.5.3)
34
+ nokogiri (1.5.4)
33
35
  nori (1.1.0)
34
36
  rack (1.4.1)
35
37
  rake (0.9.2.2)
@@ -50,7 +52,7 @@ GEM
50
52
  nori (~> 1.1)
51
53
  wasabi (~> 2.1)
52
54
  uuidtools (2.1.2)
53
- wasabi (2.1.1)
55
+ wasabi (2.1.0)
54
56
  nokogiri (>= 1.4.0)
55
57
 
56
58
  PLATFORMS
@@ -22,7 +22,9 @@ Gem::Specification.new do |s|
22
22
 
23
23
 
24
24
  s.add_runtime_dependency "aws-sdk"
25
- s.add_runtime_dependency "savon" # http://savonrb.com/
25
+ #s.add_runtime_dependency "wasabi", "2.2.0"
26
+ s.add_runtime_dependency "wasabi", "2.1.0"
27
+ s.add_runtime_dependency "savon", "0.9.9" # http://savonrb.com/
26
28
 
27
29
  s.add_development_dependency "rake"
28
30
  s.add_development_dependency "rspec"
@@ -26,6 +26,7 @@ end
26
26
 
27
27
  require "ec2_ultradns_updater/cli"
28
28
  require "ec2_ultradns_updater/ec2"
29
+ require "ec2_ultradns_updater/ip_info"
29
30
  require "ec2_ultradns_updater/preconditions"
30
31
  require "ec2_ultradns_updater/ultradns"
31
32
  require "ec2_ultradns_updater/version"
@@ -22,17 +22,24 @@ class Ec2UltraDNSUpdater::CLI
22
22
  def self.run
23
23
  opts = parse(ARGV)
24
24
 
25
- ec2 = Ec2UltraDNSUpdater::Ec2.new(opts['aws'])
26
- ultradns = Ec2UltraDNSUpdater::UltraDNS.new(opts['ultradns'])
25
+ ec2 = Ec2UltraDNSUpdater::Ec2.new(opts[:aws])
26
+ ultradns = Ec2UltraDNSUpdater::UltraDNS.new(opts[:ultradns])
27
27
  name_tag_value = ec2.get_name_tag
28
28
 
29
- result = ultradns.create_or_update_cname(name_tag_value, ec2.get_instance_public_hostname)
29
+ result = false
30
+ if ec2.get_instance_public_hostname != ''
31
+ result = ultradns.create_or_update_cname(name_tag_value, ec2.get_instance_public_hostname)
32
+ else
33
+ # try using an ip that reaches the internet
34
+ result = ultradns.create_or_update_a(name_tag_value, Ec2UltraDNSUpdater::IpInfo.local_ipv4)
35
+ end
36
+
30
37
  if !result
31
38
  error_text = "Error Creating or Updating CNAME for #{ec2.get_instance_public_hostname} to #{name_tag_value}"
32
39
  @logger.error error_text
33
40
  ::Logger.new(STDERR).error error_text
34
- elsif !opts['out'].empty?
35
- write_hostname(opts['out'], name_tag_value)
41
+ elsif !opts[:out].empty?
42
+ write_hostname(opts[:out], name_tag_value)
36
43
  end
37
44
  end
38
45
 
@@ -42,32 +49,35 @@ class Ec2UltraDNSUpdater::CLI
42
49
  end
43
50
  end
44
51
 
45
- def self.load_config(filename)
46
- config = configure_logger(YAML.load_file(filename))
52
+ def self.load_config(opts, filename)
53
+ config = symbolize_keys(YAML.load_file(filename))
54
+ # merge the new file config & update the logger config
55
+ configure_logger(opts.merge!(config))
47
56
  end
48
57
 
49
58
  def self.configure_logger(opts)
50
- if opts['log_to']
51
- @logger = ::Logger.new(opts['log_to'])
59
+ if opts[:log_to]
60
+ @logger = ::Logger.new(opts[:log_to])
52
61
  end
53
62
  @logger ||= ::Logger.new(STDOUT)
54
63
 
55
- @logger.level = opts['verbose'] ? Logger::DEBUG : Logger::INFO
64
+ @logger.level = opts[:verbose] ? Logger::DEBUG : Logger::INFO
56
65
 
57
- opts['aws']['logger'] = @logger if opts['aws']
58
- opts['ultradns']['logger'] = @logger if opts['ultradns']
66
+ opts[:aws][:logger] = @logger if opts[:aws]
67
+ opts[:ultradns][:logger] = @logger if opts[:ultradns]
59
68
 
60
69
  opts
61
70
  end
62
71
 
63
72
  def self.parse(args)
64
73
  options = {}
65
- options['aws'] = {}
66
- options['ultradns'] = {}
67
- options['log_to'] = ::Logger.new(STDOUT)
68
- options['verbose'] = false
69
- options['out'] = ''
70
-
74
+ options[:aws] = {}
75
+ options[:ultradns] = {}
76
+ options[:log_to] = ::Logger.new(STDOUT)
77
+ options[:verbose] = false
78
+ options[:out] = ''
79
+ options[:config] = nil
80
+
71
81
  opts = OptionParser.new do |opts|
72
82
  opts.banner = "Usage: ec2_ultradns_updater [options]"
73
83
 
@@ -76,17 +86,17 @@ class Ec2UltraDNSUpdater::CLI
76
86
 
77
87
  opts.on("-c", "--config config.yaml",
78
88
  "Configuration for the updater") do |config|
79
- options.merge!(load_config(config))
89
+ options[:config] = config
80
90
  end
81
91
 
82
92
  opts.on("-o", "--out filename", "Write out the name assigned") do |out|
83
- options['out'] = out
93
+ options[:out] = out
84
94
  end
85
95
 
86
96
  opts.separator ""
87
97
 
88
98
  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
89
- options['verbose'] = v
99
+ options[:verbose] = v
90
100
  end
91
101
 
92
102
  opts.on_tail("-h", "--help", "Show this message") do
@@ -101,7 +111,26 @@ class Ec2UltraDNSUpdater::CLI
101
111
  end
102
112
 
103
113
  opts.parse!(args)
104
- options
114
+ # load the config
115
+ load_config(options, options[:config])
116
+ end
117
+
118
+ def self.symbolize_keys(hash)
119
+ unless hash.nil?
120
+ hash.replace(
121
+ hash.each_key.inject({}) do |h, k|
122
+ v = hash.delete(k)
123
+ key = k.to_sym rescue k
124
+ if v.is_a? (Hash)
125
+ h[key] = symbolize_keys(v)
126
+ else
127
+ h[key] = v
128
+ end
129
+ h
130
+ end
131
+ )
132
+ end
133
+ hash
105
134
  end
106
135
  end
107
136
 
@@ -18,27 +18,36 @@ class Ec2UltraDNSUpdater::Ec2
18
18
 
19
19
  def initialize(opts = {})
20
20
  AWS.config(
21
- :access_key_id => opts['access_key_id'],
22
- :secret_access_key => opts['secret_access_key'])
21
+ :access_key_id => opts[:access_key_id],
22
+ :secret_access_key => opts[:secret_access_key])
23
23
 
24
- @logger = opts['logger'] || Logger.new(STDOUT)
25
- @tag_name = opts['name_tag'] || 'Name' # default to Name
24
+ @logger = opts[:logger] || Logger.new(STDOUT)
25
+
26
+ # also configure HTTPI
27
+ HTTPI.logger = @logger
28
+ HTTPI.log_level = :debug
29
+ @tag_name = opts[:name_tag] || 'Name' # default to Name
26
30
  end
27
31
 
28
32
  def get_instance_id
29
- @instance_id ||= Net::HTTP.get(URI("#{EC2_META_DATA_URL}/instance-id"))
33
+ @instance_id ||= begin
34
+ response = HTTPI.get(URI("#{EC2_META_DATA_URL}/instance-id").to_s)
35
+ response.code == 200 ? response.body : ''
36
+ end
30
37
  @logger.debug("Instance ID = #{@instance_id}")
31
38
  @instance_id
32
39
  end
33
40
 
34
41
  def get_instance_public_hostname
35
- @public_hostname ||= Net::HTTP.get(URI("#{EC2_META_DATA_URL}/public-hostname"))
42
+ @public_hostname ||= begin
43
+ response = HTTPI.get(URI("#{EC2_META_DATA_URL}/public-hostname").to_s)
44
+ response.code == 200 ? response.body : ''
45
+ end
36
46
  @logger.debug("Public Hostname = #{@public_hostname}")
37
47
  @public_hostname
38
48
  end
39
49
 
40
50
  def get_name_tag
41
- ec2 = AWS::EC2.new
42
51
  dns_cname = ''
43
52
  ec2.tags.filter('resource-id', get_instance_id()).each do |tag|
44
53
  @logger.debug { tag.resource.inspect } # resource is an EC2 object, e.g. AWS::EC2::VPC
@@ -49,6 +58,20 @@ class Ec2UltraDNSUpdater::Ec2
49
58
  @logger.debug("Tagged DNS CNAME = #{dns_cname} for #{get_instance_id()}")
50
59
  dns_cname
51
60
  end
61
+
62
+ def ec2
63
+ @ec2_region ||= begin
64
+ ec2 = AWS::EC2.new
65
+ region = nil
66
+ ec2.regions.each do |r|
67
+ if r.instances.map(&:id).include?(get_instance_id())
68
+ region = r
69
+ break
70
+ end
71
+ end
72
+ region
73
+ end
74
+ end
52
75
  end
53
76
 
54
77
 
@@ -0,0 +1,42 @@
1
+ # Copyright 2012 NeuStar, Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'socket'
16
+
17
+ class Ec2UltraDNSUpdater::IpInfo
18
+
19
+ def self.local_ipv4
20
+ # pdns1.ultradns.net. IN A 204.74.108.1
21
+ local_ip('204.74.108.1')
22
+ end
23
+
24
+ def self.local_ipv6
25
+ # pdns1.ultradns.net. IN AAAA 2001:502:f3ff::1
26
+ # 2001:502:f3ff:0:0:0:0:1
27
+ local_ip('2001:502:f3ff::1')
28
+ end
29
+
30
+ # nice trick from: http://coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/
31
+ def self.local_ip(host)
32
+ socket_type = (host =~ /\:/) ? Socket::AF_INET6 : Socket::AF_INET
33
+ orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
34
+ UDPSocket.open(socket_type) do |s|
35
+ s.connect host, 1
36
+ s.addr.last
37
+ end
38
+ ensure
39
+ Socket.do_not_reverse_lookup = orig
40
+ end
41
+
42
+ end
@@ -17,11 +17,17 @@ class Ec2UltraDNSUpdater::UltraDNS
17
17
  include Ec2UltraDNSUpdater::Preconditions
18
18
 
19
19
  ULTRADNS_WSDL_URL = "http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01?wsdl"
20
- CNAME_TYPE = 5
21
20
  DEFAULT_TTL = 60
22
21
 
22
+ module TYPE
23
+ ANY = ALL = 0
24
+ A = 1
25
+ CNAME = 5
26
+ AAAA = 28
27
+ end
28
+
23
29
  def initialize(opts = {})
24
- @logger = opts['logger'] || Logger.new(STDOUT)
30
+ @logger = opts[:logger] || Logger.new(STDOUT)
25
31
 
26
32
  Savon.configure do |config|
27
33
  config.logger = @logger
@@ -30,56 +36,96 @@ class Ec2UltraDNSUpdater::UltraDNS
30
36
  # also configure HTTPI
31
37
  HTTPI.logger = @logger
32
38
 
33
- @username = opts['username']
34
- @password = opts['password']
35
- @zone = fix_zone_name(opts['zone'] || '')
39
+ @username = opts[:username]
40
+ @password = opts[:password]
41
+ @zone = fix_zone_name(opts[:zone] || '')
36
42
 
37
43
  precondition.str_not_empty(@username)
38
44
  precondition.str_not_empty(@password)
39
45
  precondition.str_not_empty(@zone)
40
46
  end
41
47
 
48
+
42
49
  def get_cname_guid(cname)
43
- zone = @zone
44
- fixed_cname = fix_zone_name(cname)
50
+ get_guid_by_label_and_type(cname, TYPE::CNAME)
51
+ end
52
+
53
+ def create_or_update_cname(cname, to_hostname)
54
+ create_or_update_info1(TYPE::CNAME, cname, fix_zone_name(to_hostname))
55
+ end
56
+
57
+ def get_a_guid(node_label)
58
+ get_guid_by_label_and_type(node_label, TYPE::A)
59
+ end
60
+
61
+ def create_or_update_a(node_label, to_ip)
62
+ create_or_update_info1(TYPE::A, node_label, to_ip)
63
+ end
45
64
 
46
- guids_resp = client.request(:v01, 'getResourceRecordGUIDList') {
65
+ def network_status?
66
+ resp = client.request(:v01, 'getNeustarNetworkStatus') #:get_neustar_network_status)
67
+ @logger.debug(resp)
68
+ log_error(resp)
69
+ resp.success?
70
+ end
71
+
72
+ def delete_record_by_guid(guid)
73
+ resp = client.request(:v01, 'deleteResourceRecord') {
47
74
  soap.body do |xml|
48
- xml.resourceRecord({
49
- "ZoneName" => zone, 'Type' => CNAME_TYPE, 'DName' => fixed_cname
50
- })
75
+ xml.transactionID()
76
+ xml.guid(guid)
51
77
  end
52
78
  }
53
- log_error(guids_resp)
54
-
55
- begin
56
- guid = guids_resp[:get_resource_record_guid_list_response][:resource_record_guid_list][:guid]
57
- @logger.debug("guid found: #{guid}")
58
- rescue
59
- @logger.debug("guid not found")
79
+ log_error(resp)
80
+ resp.success?
81
+ end
82
+
83
+
84
+ def get_records_by_label(label)
85
+ get_record_by_label_and_type(label, TYPE::ALL)
86
+ end
87
+
88
+ def delete_record_by_label(label)
89
+ recs = get_records_by_label(label)
90
+ unless recs.nil?
91
+ guid = (recs[:resource_record][:@guid] rescue '') || ''
92
+ delete_record_by_guid(guid) unless guid == ''
60
93
  end
61
- guid
62
94
  end
63
95
 
64
- def create_or_update_cname(cname, to_hostname)
65
- precondition.str_not_empty(cname)
66
- precondition.str_not_empty(to_hostname)
96
+ def delete_record_by_label_not_matching_type(label, type)
97
+ recs = get_records_by_label(label)
98
+ unless recs.nil?
99
+ guid = (recs[:resource_record][:@guid] rescue '') || ''
100
+ rec_type = (recs[:resource_record][:@type] rescue '') || ''
101
+ if guid != '' && rec_type != type
102
+ delete_record_by_guid(guid)
103
+ end
104
+ end
105
+ end
106
+
107
+ #############
108
+
109
+ def create_or_update_info1(type, label, to_value)
110
+ precondition.str_not_empty(label)
111
+ precondition.str_not_empty(to_value)
67
112
 
68
113
  zone = @zone
69
- fixed_cname = fix_zone_name(cname)
70
- fixed_to_hostname = fix_zone_name(to_hostname)
114
+ fixed_label = fix_zone_name(label)
71
115
 
72
- guid = get_cname_guid(cname)
116
+ guid = get_guid_by_label_and_type(label, type) || ''
73
117
 
74
118
  change_method = 'createResourceRecord'
75
- record_opts = {'Type' => CNAME_TYPE, 'DName' => fixed_cname, 'TTL' => DEFAULT_TTL}
119
+ record_opts = {'Type' => type, 'DName' => fixed_label, 'TTL' => DEFAULT_TTL}
76
120
 
77
- if guid != nil && guid != ''
78
- @logger.info "Updating Record Mapping: #{fixed_cname} => #{fixed_to_hostname}"
121
+ if guid != ''
122
+ @logger.info "Updating Record Mapping: #{fixed_label} => #{to_value}"
79
123
  change_method = 'updateResourceRecord' # update it
80
124
  record_opts['Guid'] = guid;
81
125
  else
82
- @logger.info "Creating Record Mapping: #{fixed_cname} => #{fixed_to_hostname}"
126
+ # make sure there isn't another record at this label of a different type
127
+ delete_record_by_label_not_matching_type(label, type)
128
+ @logger.info "Creating Record Mapping: #{fixed_label} => #{to_value}"
83
129
  record_opts['ZoneName'] = zone;
84
130
  end
85
131
 
@@ -91,7 +137,7 @@ class Ec2UltraDNSUpdater::UltraDNS
91
137
  soap.body do |xml|
92
138
  xml.transactionID()
93
139
  xml.resourceRecord(record_opts) {
94
- xml.tag!("#{ns}:InfoValues", {"Info1Value" => fixed_to_hostname})
140
+ xml.tag!("#{ns}:InfoValues", {"Info1Value" => to_value})
95
141
  }
96
142
  end
97
143
  }
@@ -100,24 +146,50 @@ class Ec2UltraDNSUpdater::UltraDNS
100
146
  resp.success?
101
147
  end
102
148
 
103
- def network_status?
104
- resp = client.request :v01, :get_neustar_network_status
105
- @logger.debug(resp)
106
- log_error(resp)
107
- resp.success?
149
+ def get_guid_by_label_and_type(label, type)
150
+ zone = @zone
151
+ fixed_label = fix_zone_name(label)
152
+
153
+ guids_resp = client.request(:v01, 'getResourceRecordGUIDList') {
154
+ soap.body do |xml|
155
+ xml.resourceRecord({
156
+ "ZoneName" => zone, 'Type' => type, 'DName' => fixed_label
157
+ })
158
+ end
159
+ }
160
+ log_error(guids_resp)
161
+
162
+ begin
163
+ guid = guids_resp[:get_resource_record_guid_list_response][:resource_record_guid_list][:guid]
164
+ @logger.debug("guid found: #{guid}")
165
+ rescue
166
+ @logger.debug("guid not found")
167
+ end
168
+ guid
108
169
  end
109
170
 
110
- def delete_record_by_guid(guid)
111
- resp = client.request(:v01, 'deleteResourceRecord') {
171
+
172
+ def get_record_by_label_and_type(label, type)
173
+ zone = @zone
174
+ fixed_label = fix_zone_name(label)
175
+
176
+ records_resp = client.request(:v01, 'getResourceRecordsOfDNameByType') {
112
177
  soap.body do |xml|
113
- xml.transactionID()
114
- xml.guid(guid)
178
+ xml.zoneName(zone)
179
+ xml.rrType(type)
180
+ xml.hostName(fixed_label)
115
181
  end
116
182
  }
117
- log_error(resp)
118
- resp.success?
183
+ log_error(records_resp)
184
+
185
+ begin
186
+ records_resp.to_hash[:get_resource_records_of_d_name_by_type_response][:resource_record_list]
187
+ rescue
188
+ @logger.debug("Resource Record list is empty")
189
+ end
119
190
  end
120
191
 
192
+
121
193
  def client
122
194
  soap_username = @username
123
195
  soap_password = @password
@@ -135,6 +207,6 @@ class Ec2UltraDNSUpdater::UltraDNS
135
207
 
136
208
  # ..Must end with a '.'
137
209
  def fix_zone_name(name)
138
- name[-1] != '.' ? "#{name}." : name
210
+ (name != nil && name.strip != '' && name[-1] != '.') ? "#{name}." : name
139
211
  end
140
212
  end
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module Ec2UltraDNSUpdater
16
- VERSION = "0.0.5"
16
+ VERSION = "0.0.6"
17
17
  end
@@ -52,16 +52,22 @@ describe Ec2UltraDNSUpdater::Ec2 do
52
52
  tags = Object.new
53
53
  tags.stub(:filter).and_return([tag])
54
54
 
55
- AWS::EC2.any_instance.stub(:tags).and_return(tags)
55
+ # AWS::EC2.any_instance.stub(:tags).and_return(tags)
56
+
57
+
58
+
56
59
  fake_name = "ec2-111-111-111-111.compute-1.amazonaws.com"
57
60
  FakeWeb.register_uri(:get, Ec2UltraDNSUpdater::Ec2::EC2_META_DATA_URL + "/public-hostname", :body => fake_name)
58
61
  FakeWeb.register_uri(:get, Ec2UltraDNSUpdater::Ec2::EC2_META_DATA_URL + "/instance-id", :body => tag.resource)
59
62
 
60
- ec2 = Ec2UltraDNSUpdater::Ec2.new({'access_key_id' => 123, 'secret_access_key' => 'abc', 'name_tag' => 'Testname'})
63
+ ec2 = Ec2UltraDNSUpdater::Ec2.new({:access_key_id => 123, :secret_access_key => 'abc', :name_tag => 'Testname'})
64
+ ec2_stub = Object.new
65
+ ec2_stub.stub(:tags).and_return(tags)
66
+ ec2.stub(:ec2).and_return(ec2_stub)
61
67
  ec2.get_name_tag.should == tag.value
62
68
 
63
69
  ensure
64
- AWS::EC2.any_instance.unstub(:tags)
70
+ #AWS::EC2.any_instance.unstub(:tags)
65
71
  FakeWeb.clean_registry
66
72
  end
67
73
  end
@@ -0,0 +1,26 @@
1
+ # Copyright 2012 NeuStar, Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'spec_helper'
16
+ require 'fakeweb'
17
+ require 'yaml'
18
+
19
+ describe Ec2UltraDNSUpdater::IpInfo do
20
+
21
+ it "should get an ipv4 address" do
22
+ Ec2UltraDNSUpdater::IpInfo.local_ipv4().should_not == ''
23
+ Ec2UltraDNSUpdater::IpInfo.local_ipv4().should match(/\d+\.\d+\.\d+\.\d+/)
24
+ end
25
+
26
+ end
@@ -19,22 +19,22 @@ require 'yaml'
19
19
  describe Ec2UltraDNSUpdater::UltraDNS do
20
20
 
21
21
  it "should raise if cname is empty" do
22
- ultra = Ec2UltraDNSUpdater::UltraDNS.new({'username' => 'blah', 'password' => 'blah', 'zone' => 'ultrandns.com.'})
22
+ ultra = Ec2UltraDNSUpdater::UltraDNS.new({:username => 'blah', :password => 'blah', :zone => 'ultrandns.com.'})
23
23
  expect { ultra.create_or_update_cname }.to raise_error
24
24
  end
25
25
 
26
26
  it "should raise if to_hostname is empty" do
27
- ultra = Ec2UltraDNSUpdater::UltraDNS.new({'username' => 'blah', 'password' => 'blah', 'zone' => 'ultrandns.com.'})
27
+ ultra = Ec2UltraDNSUpdater::UltraDNS.new({:username => 'blah', :password => 'blah', :zone => 'ultrandns.com.'})
28
28
  expect { ultra.create_or_update_cname("adsf", '') }.to raise_error
29
29
  end
30
30
 
31
31
  it "should fix a zone name without a trailing dot" do
32
- ultra = Ec2UltraDNSUpdater::UltraDNS.new({'username' => 'blah', 'password' => 'blah', 'zone' => 'ultrandns.com.'})
32
+ ultra = Ec2UltraDNSUpdater::UltraDNS.new({:username => 'blah', :password => 'blah', :zone => 'ultrandns.com.'})
33
33
  ultra.fix_zone_name("a.b.com").should == "a.b.com."
34
34
  end
35
35
 
36
36
  it "should not change a zone name with a trailing dot" do
37
- ultra = Ec2UltraDNSUpdater::UltraDNS.new({'username' => 'blah', 'password' => 'blah', 'zone' => 'ultrandns.com.'})
37
+ ultra = Ec2UltraDNSUpdater::UltraDNS.new({:username => 'blah', :password => 'blah', :zone => 'ultrandns.com.'})
38
38
  name = "a.b.biz."
39
39
  ultra.fix_zone_name(name).should == name
40
40
  end
@@ -43,34 +43,115 @@ describe Ec2UltraDNSUpdater::UltraDNS do
43
43
  LIVE_CONFIG = File.join(File.dirname(__FILE__), '..', '..', 'config', 'live.config.yaml')
44
44
 
45
45
  it "should check network status" do
46
- config = Ec2UltraDNSUpdater::CLI.load_config(LIVE_CONFIG)
46
+ config = Ec2UltraDNSUpdater::CLI.load_config({}, LIVE_CONFIG)
47
47
  config.should_not eq(nil)
48
48
 
49
- ultra = Ec2UltraDNSUpdater::UltraDNS.new(config['ultradns'])
49
+ ultra = Ec2UltraDNSUpdater::UltraDNS.new(config[:ultradns])
50
50
  (ultra.network_status?).should eq(true)
51
51
  end
52
52
 
53
53
  it "should create a new record and then update the record" do
54
- config = Ec2UltraDNSUpdater::CLI.load_config(LIVE_CONFIG)
54
+ config = Ec2UltraDNSUpdater::CLI.load_config({}, LIVE_CONFIG)
55
55
  config.should_not eq(nil)
56
56
 
57
- ultra = Ec2UltraDNSUpdater::UltraDNS.new(config['ultradns'])
58
- guid = ultra.get_cname_guid(config['test_cname'])
57
+ ultra = Ec2UltraDNSUpdater::UltraDNS.new(config[:ultradns])
58
+ guid = ultra.get_cname_guid(config[:test_cname])
59
59
  if guid != nil && guid != ''
60
60
  ultra.delete_record_by_guid(guid).should eq(true)
61
61
  end
62
62
 
63
- result = ultra.create_or_update_cname(config['test_cname'], config['test_public_hostname'][0])
63
+ # create cname
64
+
65
+ result = ultra.create_or_update_cname(config[:test_cname], config[:test_public_hostname][0])
64
66
  result.should eq(true)
65
- guid_0 = ultra.get_cname_guid(config['test_cname'])
67
+ guid_0 = ultra.get_cname_guid(config[:test_cname])
66
68
  guid_0.should_not be_empty
69
+
70
+ recs = ultra.get_record_by_label_and_type(config[:test_cname],
71
+ Ec2UltraDNSUpdater::UltraDNS::TYPE::CNAME)
72
+ cname = recs[:resource_record][:info_values][:@info1_value]
73
+ cname.should == config[:test_public_hostname][0] + '.' # no trailing . in config
74
+
75
+
76
+ # update cname
67
77
 
68
- result = ultra.create_or_update_cname(config['test_cname'], config['test_public_hostname'][1])
78
+ result = ultra.create_or_update_cname(config[:test_cname], config[:test_public_hostname][1])
69
79
  result.should eq(true)
70
- guid_1 = ultra.get_cname_guid(config['test_cname'])
80
+ guid_1 = ultra.get_cname_guid(config[:test_cname])
71
81
  guid_1.should_not be_empty
72
82
  guid_0.should == guid_1
73
- #TODO, check the value
83
+
84
+ recs = ultra.get_record_by_label_and_type(config[:test_cname],
85
+ Ec2UltraDNSUpdater::UltraDNS::TYPE::CNAME)
86
+ cname = recs[:resource_record][:info_values][:@info1_value]
87
+ cname.should == config[:test_public_hostname][1] + '.' # no trailing . in config
88
+
89
+
90
+ # remove the CNAME record
91
+ if guid_0 != nil && guid_0 != ''
92
+ ultra.delete_record_by_guid(guid_0).should eq(true)
93
+ end
94
+
95
+ # create A record
96
+ IP = '1.2.3.4'
97
+ result = ultra.create_or_update_a(config[:test_cname], IP)
98
+ result.should eq(true)
99
+ guid_2 = ultra.get_a_guid(config[:test_cname])
100
+ recs = ultra.get_record_by_label_and_type(config[:test_cname],
101
+ Ec2UltraDNSUpdater::UltraDNS::TYPE::A)
102
+
103
+ ip = recs[:resource_record][:info_values][:@info1_value]
104
+ ip.should == IP
105
+
106
+ guid_2.should_not be_empty
107
+ guid_0.should_not == guid_2
108
+
109
+ # remove the A record
110
+ ultra.delete_record_by_label(config[:test_cname])
111
+
112
+ guid_3 = ultra.get_a_guid(config[:test_cname])
113
+ guid_3.should == nil
114
+ end
115
+
116
+ it "should create a new record and then create a record of a different type" do
117
+ config = Ec2UltraDNSUpdater::CLI.load_config({}, LIVE_CONFIG)
118
+ config.should_not eq(nil)
119
+
120
+ ultra = Ec2UltraDNSUpdater::UltraDNS.new(config[:ultradns])
121
+
122
+
123
+ # create cname
124
+
125
+ result = ultra.create_or_update_cname(config[:test_cname], config[:test_public_hostname][0])
126
+ result.should eq(true)
127
+ guid_0 = ultra.get_cname_guid(config[:test_cname])
128
+ guid_0.should_not be_empty
129
+
130
+ recs = ultra.get_record_by_label_and_type(config[:test_cname],
131
+ Ec2UltraDNSUpdater::UltraDNS::TYPE::CNAME)
132
+ cname = recs[:resource_record][:info_values][:@info1_value]
133
+ cname.should == config[:test_public_hostname][0] + '.' # no trailing . in config
134
+
135
+
136
+ # create A record
137
+ ip_value = '1.2.3.4'
138
+ result = ultra.create_or_update_a(config[:test_cname], ip_value)
139
+ result.should eq(true)
140
+ guid_2 = ultra.get_a_guid(config[:test_cname])
141
+ recs = ultra.get_record_by_label_and_type(config[:test_cname],
142
+ Ec2UltraDNSUpdater::UltraDNS::TYPE::A)
143
+
144
+ ip = recs[:resource_record][:info_values][:@info1_value]
145
+ ip.should == ip_value
146
+
147
+ guid_2.should_not be_empty
148
+ guid_0.should_not == guid_2
149
+
150
+ # remove the A record
151
+ ultra.delete_record_by_label(config[:test_cname])
152
+
153
+ guid_3 = ultra.get_a_guid(config[:test_cname])
154
+ guid_3.should == nil
74
155
  end
75
156
 
76
157
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2_ultradns_updater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-05 00:00:00.000000000Z
12
+ date: 2012-06-12 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
16
- requirement: &2153547120 !ruby/object:Gem::Requirement
16
+ requirement: &2157349700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,32 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153547120
24
+ version_requirements: *2157349700
25
+ - !ruby/object:Gem::Dependency
26
+ name: wasabi
27
+ requirement: &2157349200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2157349200
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: savon
27
- requirement: &2153546700 !ruby/object:Gem::Requirement
38
+ requirement: &2157348700 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
- - - ! '>='
41
+ - - =
31
42
  - !ruby/object:Gem::Version
32
- version: '0'
43
+ version: 0.9.9
33
44
  type: :runtime
34
45
  prerelease: false
35
- version_requirements: *2153546700
46
+ version_requirements: *2157348700
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: rake
38
- requirement: &2153546280 !ruby/object:Gem::Requirement
49
+ requirement: &2157348320 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *2153546280
57
+ version_requirements: *2157348320
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rspec
49
- requirement: &2153545860 !ruby/object:Gem::Requirement
60
+ requirement: &2157347860 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *2153545860
68
+ version_requirements: *2157347860
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: fakeweb
60
- requirement: &2153545440 !ruby/object:Gem::Requirement
71
+ requirement: &2157347440 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,7 +76,7 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *2153545440
79
+ version_requirements: *2157347440
69
80
  description: Update your UltraDNS configured CNAMEs to point to EC2 instance public
70
81
  hostnames
71
82
  email:
@@ -87,10 +98,12 @@ files:
87
98
  - lib/ec2_ultradns_updater.rb
88
99
  - lib/ec2_ultradns_updater/cli.rb
89
100
  - lib/ec2_ultradns_updater/ec2.rb
101
+ - lib/ec2_ultradns_updater/ip_info.rb
90
102
  - lib/ec2_ultradns_updater/preconditions.rb
91
103
  - lib/ec2_ultradns_updater/ultradns.rb
92
104
  - lib/ec2_ultradns_updater/version.rb
93
105
  - spec/lib/ec2_spec.rb
106
+ - spec/lib/ip_info_spec.rb
94
107
  - spec/lib/ultradns_spec.rb
95
108
  - spec/spec_helper.rb
96
109
  homepage: https://github.com/ultradns/ec2_ultradns_updater
@@ -120,5 +133,6 @@ specification_version: 3
120
133
  summary: Update UltraDNS for EC2 instances
121
134
  test_files:
122
135
  - spec/lib/ec2_spec.rb
136
+ - spec/lib/ip_info_spec.rb
123
137
  - spec/lib/ultradns_spec.rb
124
138
  - spec/spec_helper.rb