ultradns_updater 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +66 -0
- data/LICENSE +202 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/ultradns_updater +28 -0
- data/config/sample.config.yaml +24 -0
- data/lib/ultradns_updater/cli.rb +136 -0
- data/lib/ultradns_updater/ec2.rb +80 -0
- data/lib/ultradns_updater/ip_info.rb +70 -0
- data/lib/ultradns_updater/preconditions.rb +25 -0
- data/lib/ultradns_updater/strategies/configured.rb +29 -0
- data/lib/ultradns_updater/strategies/ec2.rb +38 -0
- data/lib/ultradns_updater/strategies/hostname.rb +24 -0
- data/lib/ultradns_updater/strategies/update_strategy.rb +39 -0
- data/lib/ultradns_updater/strategies.rb +39 -0
- data/lib/ultradns_updater/ultradns.rb +218 -0
- data/lib/ultradns_updater/version.rb +17 -0
- data/lib/ultradns_updater.rb +32 -0
- data/spec/lib/configured_spec.rb +38 -0
- data/spec/lib/ec2_spec.rb +74 -0
- data/spec/lib/hostname_spec.rb +39 -0
- data/spec/lib/ip_info_spec.rb +47 -0
- data/spec/lib/ultradns_spec.rb +158 -0
- data/spec/spec_helper.rb +18 -0
- data/ultradns_updater.gemspec +31 -0
- metadata +153 -0
@@ -0,0 +1,25 @@
|
|
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
|
+
|
16
|
+
module UltraDNSUpdater::Preconditions
|
17
|
+
|
18
|
+
def precondition
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def not_empty(arg, msg = "Argument may not empty")
|
23
|
+
raise msg if arg == nil || arg == ''
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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
|
+
module UltraDNSUpdater::Strategies
|
16
|
+
class Configured < UpdateStrategy
|
17
|
+
def update(strategy_config)
|
18
|
+
hostname = strategy_config[:name]
|
19
|
+
precondition.not_empty(hostname)
|
20
|
+
|
21
|
+
ip = iface_ip(strategy_config)
|
22
|
+
precondition.not_empty(ip)
|
23
|
+
|
24
|
+
strategy_config[:logger].debug("Mapping #{hostname} to #{ip}")
|
25
|
+
|
26
|
+
ultradns.create_or_update_a(hostname, ip)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
module UltraDNSUpdater::Strategies
|
16
|
+
class Ec2 < UpdateStrategy
|
17
|
+
|
18
|
+
def update(strategy_config)
|
19
|
+
ec2 = Ec2UltraDNSUpdater::Ec2.new(strategy_config)
|
20
|
+
name_tag_value = ec2.get_name_tag
|
21
|
+
|
22
|
+
result = false
|
23
|
+
if ec2.get_instance_public_hostname != ''
|
24
|
+
result = ultradns.create_or_update_cname(name_tag_value, ec2.get_instance_public_hostname)
|
25
|
+
else
|
26
|
+
ip = iface_ip(strategy_config)
|
27
|
+
|
28
|
+
unless ip.nil?
|
29
|
+
# try using an ip that reaches the internet
|
30
|
+
result = ultradns.create_or_update_a(name_tag_value, ip)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
result ? name_tag_value : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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
|
+
require 'ultradns_updater/strategies/configured'
|
17
|
+
|
18
|
+
module UltraDNSUpdater::Strategies
|
19
|
+
class Hostname < Configured
|
20
|
+
def update(strategy_config)
|
21
|
+
super(strategy_config.merge({:name => Socket::gethostname()}))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
+
class UltraDNSUpdater::Strategies::UpdateStrategy
|
16
|
+
include UltraDNSUpdater::Preconditions
|
17
|
+
|
18
|
+
def initialize(ultradns)
|
19
|
+
@ultradns = ultradns
|
20
|
+
end
|
21
|
+
|
22
|
+
# update ultradns based on the configuration provided
|
23
|
+
# returns: the hostname applied or else nil
|
24
|
+
def update(strategy_config); end
|
25
|
+
|
26
|
+
def ultradns
|
27
|
+
@ultradns
|
28
|
+
end
|
29
|
+
|
30
|
+
def iface_ip(strategy_config)
|
31
|
+
ip = nil
|
32
|
+
if strategy_config[:iface] == 'auto'
|
33
|
+
ip = UltraDNSUpdater::IpInfo.local_ipv4
|
34
|
+
else
|
35
|
+
ip = UltraDNSUpdater::IpInfo.ipv4_for_iface(strategy_config[:iface])
|
36
|
+
end
|
37
|
+
ip
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
+
#fwd decl
|
16
|
+
module UltraDNSUpdater::Strategies; end
|
17
|
+
|
18
|
+
require 'ultradns_updater/strategies/update_strategy'
|
19
|
+
require 'ultradns_updater/strategies/ec2'
|
20
|
+
require 'ultradns_updater/strategies/configured'
|
21
|
+
require 'ultradns_updater/strategies/hostname'
|
22
|
+
|
23
|
+
module UltraDNSUpdater::Strategies
|
24
|
+
|
25
|
+
def self.strategy(strategy_name)
|
26
|
+
case strategy_name
|
27
|
+
when :ec2
|
28
|
+
UltraDNSUpdater::Strategies::Ec2
|
29
|
+
when :hostname
|
30
|
+
UltraDNSUpdater::Strategies::Hostname
|
31
|
+
when :configured
|
32
|
+
UltraDNSUpdater::Strategies::Configured
|
33
|
+
else
|
34
|
+
raise "No strategy found for: #{strategy_name}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,218 @@
|
|
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
|
+
|
16
|
+
class UltraDNSUpdater::UltraDNS
|
17
|
+
include UltraDNSUpdater::Preconditions
|
18
|
+
|
19
|
+
ULTRADNS_WSDL_URL = "http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01?wsdl"
|
20
|
+
DEFAULT_TTL = 60
|
21
|
+
|
22
|
+
module TYPE
|
23
|
+
ANY = ALL = 0
|
24
|
+
A = 1
|
25
|
+
CNAME = 5
|
26
|
+
AAAA = 28
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(opts = {})
|
30
|
+
@logger = opts[:logger] || Logger.new(STDOUT)
|
31
|
+
|
32
|
+
Savon.configure do |config|
|
33
|
+
config.logger = @logger
|
34
|
+
config.raise_errors = false
|
35
|
+
end
|
36
|
+
# also configure HTTPI
|
37
|
+
HTTPI.logger = @logger
|
38
|
+
|
39
|
+
@username = opts[:username]
|
40
|
+
@password = opts[:password]
|
41
|
+
@zone = fix_zone_name(opts[:zone] || '')
|
42
|
+
|
43
|
+
precondition.not_empty(@username)
|
44
|
+
precondition.not_empty(@password)
|
45
|
+
precondition.not_empty(@zone)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def get_cname_guid(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
|
64
|
+
|
65
|
+
def network_status?
|
66
|
+
resp = client.request(: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(:delete_resource_record) {
|
74
|
+
soap.body do |xml|
|
75
|
+
xml.transactionID()
|
76
|
+
xml.guid(guid)
|
77
|
+
end
|
78
|
+
}
|
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 == ''
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
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.not_empty(label)
|
111
|
+
precondition.not_empty(to_value)
|
112
|
+
|
113
|
+
zone = @zone
|
114
|
+
fixed_label = fix_zone_name(label)
|
115
|
+
|
116
|
+
guid = get_guid_by_label_and_type(label, type) || ''
|
117
|
+
|
118
|
+
change_method = :create_resource_record
|
119
|
+
record_opts = {'Type' => type, 'DName' => fixed_label, 'TTL' => DEFAULT_TTL}
|
120
|
+
|
121
|
+
if guid != ''
|
122
|
+
@logger.info "Updating Record Mapping: #{fixed_label} => #{to_value}"
|
123
|
+
change_method = :update_resource_record # update it
|
124
|
+
record_opts['Guid'] = guid;
|
125
|
+
else
|
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}"
|
129
|
+
record_opts['ZoneName'] = zone;
|
130
|
+
end
|
131
|
+
|
132
|
+
begin
|
133
|
+
resp = client.request(change_method) {
|
134
|
+
ns = ''
|
135
|
+
soap.namespaces.each do |k, v|
|
136
|
+
ns = k.gsub(/xmlns:/,'') if v =~ /schema\.ultraservice\.neustar\.com/
|
137
|
+
end
|
138
|
+
soap.body do |xml|
|
139
|
+
xml.transactionID()
|
140
|
+
xml.resourceRecord(record_opts) {
|
141
|
+
xml.tag!("#{ns}:InfoValues", {"Info1Value" => to_value})
|
142
|
+
}
|
143
|
+
end
|
144
|
+
}
|
145
|
+
|
146
|
+
log_error(resp)
|
147
|
+
resp.success?
|
148
|
+
rescue
|
149
|
+
false
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def get_guid_by_label_and_type(label, type)
|
154
|
+
zone = @zone
|
155
|
+
fixed_label = fix_zone_name(label)
|
156
|
+
|
157
|
+
guids_resp = client.request(:get_resource_record_guid_list) {
|
158
|
+
soap.body do |xml|
|
159
|
+
xml.resourceRecord({
|
160
|
+
"ZoneName" => zone, 'Type' => type, 'DName' => fixed_label
|
161
|
+
})
|
162
|
+
end
|
163
|
+
}
|
164
|
+
|
165
|
+
log_error(guids_resp)
|
166
|
+
|
167
|
+
begin
|
168
|
+
guid = guids_resp[:get_resource_record_guid_list_response][:resource_record_guid_list][:guid]
|
169
|
+
@logger.debug("guid found: #{guid}")
|
170
|
+
rescue
|
171
|
+
@logger.debug("guid not found")
|
172
|
+
end
|
173
|
+
guid
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
def get_record_by_label_and_type(label, type)
|
178
|
+
zone = @zone
|
179
|
+
fixed_label = fix_zone_name(label)
|
180
|
+
|
181
|
+
begin
|
182
|
+
records_resp = client.request('getResourceRecordsOfDNameByType'.snakecase.to_sym) {
|
183
|
+
soap.body do |xml|
|
184
|
+
xml.zoneName(zone)
|
185
|
+
xml.rrType(type)
|
186
|
+
xml.hostName(fixed_label)
|
187
|
+
end
|
188
|
+
}
|
189
|
+
log_error(records_resp)
|
190
|
+
|
191
|
+
records_resp.to_hash[:get_resource_records_of_d_name_by_type_response][:resource_record_list]
|
192
|
+
rescue
|
193
|
+
@logger.debug("Resource Record list is empty")
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
def client
|
199
|
+
soap_username = @username
|
200
|
+
soap_password = @password
|
201
|
+
|
202
|
+
@client ||= Savon::Client.new do
|
203
|
+
wsdl.document = ULTRADNS_WSDL_URL
|
204
|
+
wsse.credentials soap_username, soap_password
|
205
|
+
end
|
206
|
+
|
207
|
+
@client
|
208
|
+
end
|
209
|
+
|
210
|
+
def log_error(response)
|
211
|
+
@logger.error {response.to_xml} unless response.success?
|
212
|
+
end
|
213
|
+
|
214
|
+
# ..Must end with a '.'
|
215
|
+
def fix_zone_name(name)
|
216
|
+
(name != nil && name.strip != '' && name[-1] != '.') ? "#{name}." : name
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
+
module UltraDNSUpdater
|
16
|
+
VERSION = "0.0.15"
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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 'rubygems'
|
16
|
+
|
17
|
+
require 'aws-sdk'
|
18
|
+
require 'savon'
|
19
|
+
require 'net/http'
|
20
|
+
|
21
|
+
|
22
|
+
module UltraDNSUpdater
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
require "ultradns_updater/preconditions"
|
27
|
+
require "ultradns_updater/strategies"
|
28
|
+
require "ultradns_updater/cli"
|
29
|
+
require "ultradns_updater/ec2"
|
30
|
+
require "ultradns_updater/ip_info"
|
31
|
+
require "ultradns_updater/ultradns"
|
32
|
+
require "ultradns_updater/version"
|
@@ -0,0 +1,38 @@
|
|
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 'ostruct'
|
18
|
+
|
19
|
+
|
20
|
+
describe UltraDNSUpdater::Strategies::Configured do
|
21
|
+
it "should update ultradns with the configure name and ip address" do
|
22
|
+
begin
|
23
|
+
name = 'test.biz'
|
24
|
+
ip_addr = '192.168.1.1'
|
25
|
+
|
26
|
+
ultradns = Object.new
|
27
|
+
ultradns.should_receive(:create_or_update_a).with(name, ip_addr)
|
28
|
+
configured_strategy = UltraDNSUpdater::Strategies::Configured.new(ultradns)
|
29
|
+
configured_strategy.stub(:iface_ip).and_return(ip_addr)
|
30
|
+
|
31
|
+
configured_strategy.update({:iface => 'eth0', :name => name})
|
32
|
+
|
33
|
+
ensure
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,74 @@
|
|
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 'ostruct'
|
18
|
+
|
19
|
+
describe UltraDNSUpdater::Ec2 do
|
20
|
+
|
21
|
+
it "should return the instance id" do
|
22
|
+
begin
|
23
|
+
fake_id = "i-ffffffff"
|
24
|
+
FakeWeb.register_uri(:get, UltraDNSUpdater::Ec2::EC2_META_DATA_URL + "/instance-id", :body => fake_id)
|
25
|
+
ec2 = UltraDNSUpdater::Ec2.new
|
26
|
+
ec2.get_instance_id.should == fake_id
|
27
|
+
ec2.get_instance_id.should == fake_id # check memoize
|
28
|
+
ensure
|
29
|
+
FakeWeb.clean_registry
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the public hostname" do
|
34
|
+
begin
|
35
|
+
fake_name = "ec2-111-111-111-111.compute-1.amazonaws.com"
|
36
|
+
FakeWeb.register_uri(:get, UltraDNSUpdater::Ec2::EC2_META_DATA_URL + "/public-hostname", :body => fake_name)
|
37
|
+
ec2 = UltraDNSUpdater::Ec2.new
|
38
|
+
ec2.get_instance_public_hostname.should == fake_name
|
39
|
+
ec2.get_instance_public_hostname.should == fake_name # check memoize
|
40
|
+
ensure
|
41
|
+
FakeWeb.clean_registry
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return the dns tag name" do
|
46
|
+
begin
|
47
|
+
tag = OpenStruct.new
|
48
|
+
tag.name = "Testname" # it expects "Name", but we configure it explictly below as an example
|
49
|
+
tag.value = "tag.test.biz"
|
50
|
+
tag.resource = 'i-eeeeee'
|
51
|
+
|
52
|
+
tags = Object.new
|
53
|
+
tags.stub(:filter).and_return([tag])
|
54
|
+
|
55
|
+
# AWS::EC2.any_instance.stub(:tags).and_return(tags)
|
56
|
+
|
57
|
+
|
58
|
+
fake_name = "ec2-111-111-111-111.compute-1.amazonaws.com"
|
59
|
+
FakeWeb.register_uri(:get, UltraDNSUpdater::Ec2::EC2_META_DATA_URL + "/public-hostname", :body => fake_name)
|
60
|
+
FakeWeb.register_uri(:get, UltraDNSUpdater::Ec2::EC2_META_DATA_URL + "/instance-id", :body => tag.resource)
|
61
|
+
|
62
|
+
ec2 = UltraDNSUpdater::Ec2.new({:access_key_id => 123, :secret_access_key => 'abc', :name_tag => 'Testname'})
|
63
|
+
ec2_stub = Object.new
|
64
|
+
ec2_stub.stub(:tags).and_return(tags)
|
65
|
+
ec2.stub(:ec2).and_return(ec2_stub)
|
66
|
+
ec2.get_name_tag.should == tag.value
|
67
|
+
|
68
|
+
ensure
|
69
|
+
#AWS::EC2.any_instance.unstub(:tags)
|
70
|
+
FakeWeb.clean_registry
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,39 @@
|
|
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 'ostruct'
|
18
|
+
|
19
|
+
|
20
|
+
describe UltraDNSUpdater::Strategies::Hostname do
|
21
|
+
it "should return the hostname and ip address" do
|
22
|
+
begin
|
23
|
+
hostname = 'test.biz'
|
24
|
+
ip_addr = '192.168.1.1'
|
25
|
+
|
26
|
+
ultradns = Object.new
|
27
|
+
ultradns.should_receive(:create_or_update_a).with(hostname, ip_addr)
|
28
|
+
hostname_strategy = UltraDNSUpdater::Strategies::Hostname.new(ultradns)
|
29
|
+
hostname_strategy.stub(:iface_ip).and_return(ip_addr)
|
30
|
+
Socket.stub(:gethostname).and_return(hostname)
|
31
|
+
Socket.gethostname.should == hostname
|
32
|
+
hostname_strategy.update({:iface => 'eth0'})
|
33
|
+
|
34
|
+
ensure
|
35
|
+
Socket.unstub(:gethostname)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,47 @@
|
|
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 UltraDNSUpdater::IpInfo do
|
20
|
+
|
21
|
+
it "should get an ipv4 address" do
|
22
|
+
UltraDNSUpdater::IpInfo.local_ipv4().should_not == ''
|
23
|
+
UltraDNSUpdater::IpInfo.local_ipv4().should match(/\d+\.\d+\.\d+\.\d+/)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get an ipv4 address from ifconfig" do
|
27
|
+
|
28
|
+
iface = "eth0"
|
29
|
+
if RUBY_PLATFORM =~ /darwin/
|
30
|
+
iface = "en1"
|
31
|
+
end
|
32
|
+
|
33
|
+
UltraDNSUpdater::IpInfo.ipv4_for_iface(iface).should_not == ''
|
34
|
+
UltraDNSUpdater::IpInfo.ipv4_for_iface(iface).should match(/\d+\.\d+\.\d+\.\d+/)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should get an ipv6 address from ifconfig" do
|
38
|
+
|
39
|
+
iface = "eth0" # probably have eth0 on linux..
|
40
|
+
if RUBY_PLATFORM =~ /darwin/
|
41
|
+
iface = "en1"
|
42
|
+
end
|
43
|
+
|
44
|
+
UltraDNSUpdater::IpInfo.ipv6_for_iface(iface).should_not == ''
|
45
|
+
UltraDNSUpdater::IpInfo.ipv6_for_iface(iface).should match(/.*:.*:.*:.*:.*:/)
|
46
|
+
end
|
47
|
+
end
|