hostnamer 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -3
- data/lib/hostnamer/hostnamer.rb +22 -20
- metadata +4 -4
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Usage: hostnamer [options]
|
|
16
16
|
-j, --json-attributes [PATH] Chef json attributes file. Defaults to /etc/chef/node.json
|
17
17
|
-t, --tags [TAG,TAG] Tags to postpend, eg: --tags production,california
|
18
18
|
-p, --profile [PROFILE] AWS user profile. Uses the current IAM or the default profile located under ~/.aws
|
19
|
-
-r, --retries [RETRIES] Number of times to retry before failing. Defaults to
|
19
|
+
-r, --retries [RETRIES] Number of times to retry before failing. Defaults to 5``:wq
|
20
20
|
-w, --retry-wait SECONDS Retry wait time. Defaults to 10s
|
21
21
|
-v, --[no-]verbose Run verbosely
|
22
22
|
--version Show version
|
@@ -27,8 +27,9 @@ Usage: hostnamer [options]
|
|
27
27
|
### Ubuntu/Debian
|
28
28
|
|
29
29
|
```
|
30
|
-
|
31
|
-
|
30
|
+
version=1.0.2
|
31
|
+
wget https://s3.amazonaws.com/demandbase-pkgs-public/hostnamer_${version}_all.deb
|
32
|
+
sudo dpkg --install hostnamer_${version}_all.deb
|
32
33
|
sudo apt-get update -y && apt-get -f install # install any missing dependencies
|
33
34
|
```
|
34
35
|
|
data/lib/hostnamer/hostnamer.rb
CHANGED
@@ -6,7 +6,7 @@ require 'optparse'
|
|
6
6
|
|
7
7
|
module Hostnamer
|
8
8
|
module_function
|
9
|
-
VERSION = "1.0.
|
9
|
+
VERSION = "1.0.2"
|
10
10
|
class DNSInsertFailed < RuntimeError; end
|
11
11
|
class DNSQueryFailed < RuntimeError; end
|
12
12
|
|
@@ -15,7 +15,7 @@ module Hostnamer
|
|
15
15
|
zoneid = opts[:zone_id] or raise "zone id must be present, specify using --zone-id ZONEID"
|
16
16
|
tags = opts[:tags] || []
|
17
17
|
name = opts[:cluster_name] || detect_first_chef_role(opts[:json_attrs]) || 'instance'
|
18
|
-
retries = opts[:retries] ||
|
18
|
+
retries = opts[:retries] || 5
|
19
19
|
retrywait = opts[:retry_wait] || 10
|
20
20
|
profile = opts[:profile]
|
21
21
|
ip = detect_ip
|
@@ -26,8 +26,8 @@ module Hostnamer
|
|
26
26
|
host, domain = determine_available_host(tags, zoneid, profile)
|
27
27
|
add_host_record("#{host}.#{domain}", ip, zoneid, profile)
|
28
28
|
return host
|
29
|
-
rescue
|
30
|
-
log "
|
29
|
+
rescue DNSInsertFailed => e
|
30
|
+
log "Route53 update failed.. retrying in #{retrywait}s"
|
31
31
|
sleep retrywait
|
32
32
|
raise e
|
33
33
|
end
|
@@ -50,7 +50,7 @@ module Hostnamer
|
|
50
50
|
end
|
51
51
|
rescue Exception => e
|
52
52
|
raise "#{nodefile} is not found or invalid. Specify a cluster name using --cluster-name"
|
53
|
-
end
|
53
|
+
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -72,9 +72,10 @@ module Hostnamer
|
|
72
72
|
log "determining_available_host" do
|
73
73
|
n = 0
|
74
74
|
domain = detect_domain(zoneid, profile)
|
75
|
-
records = list_record_sets(zoneid, profile)
|
76
75
|
host = (tags + ["%02d" % n]).join('-')
|
76
|
+
records = list_record_sets(zoneid, "#{host}.#{domain}", profile)
|
77
77
|
while records.include?("#{host}.#{domain}") do
|
78
|
+
records = list_record_sets(zoneid, "#{host}.#{domain}", profile)
|
78
79
|
log "checking availability for #{host}.#{domain}"
|
79
80
|
host = (tags + ["%02d" % n+=1]).join('-')
|
80
81
|
end
|
@@ -95,9 +96,9 @@ module Hostnamer
|
|
95
96
|
end
|
96
97
|
end
|
97
98
|
|
98
|
-
def list_record_sets(zoneid, profile=nil)
|
99
|
+
def list_record_sets(zoneid, hostname, profile=nil)
|
99
100
|
log "list_record_sets" do
|
100
|
-
cmd = "aws route53 list-resource-record-sets --hosted-zone-id #{zoneid} --output text"
|
101
|
+
cmd = "aws route53 list-resource-record-sets --hosted-zone-id #{zoneid} --output text --start-record-name #{hostname}"
|
101
102
|
cmd = "#{cmd} --profile #{profile}" if profile
|
102
103
|
debug "exec: #{cmd}"
|
103
104
|
records = `#{cmd} | grep RESOURCERECORDSETS | awk '{print $2}'`.strip
|
@@ -107,12 +108,12 @@ module Hostnamer
|
|
107
108
|
end
|
108
109
|
|
109
110
|
def record_unavailable?(record)
|
110
|
-
`dig #{record} +short`.strip != ''
|
111
|
+
`dig #{record} +short`.strip != ''
|
111
112
|
end
|
112
113
|
|
113
114
|
def add_host_record(host, ip, zoneid, profile = nil)
|
114
115
|
log "add_host_record: #{host}" do
|
115
|
-
payload = Tempfile.new('payload')
|
116
|
+
payload = Tempfile.new('payload')
|
116
117
|
payload.write %Q(
|
117
118
|
{
|
118
119
|
"Comment": "Added by hostnamer during instance bootstrap",
|
@@ -146,8 +147,7 @@ module Hostnamer
|
|
146
147
|
yield
|
147
148
|
rescue => e
|
148
149
|
n = n - 1
|
149
|
-
|
150
|
-
raise e
|
150
|
+
retry if n > 0
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
@@ -155,9 +155,9 @@ module Hostnamer
|
|
155
155
|
msg = "hostnamer: #{msg}"
|
156
156
|
if ENV['HOSTNAMER_VERBOSE']
|
157
157
|
if doprint
|
158
|
-
$
|
158
|
+
$stderr.print(msg)
|
159
159
|
else
|
160
|
-
$
|
160
|
+
$stderr.puts(msg)
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
@@ -193,6 +193,8 @@ module Hostnamer
|
|
193
193
|
def parse_options(argv)
|
194
194
|
options = {}
|
195
195
|
options[:json_attrs] = "/etc/chef/node.json"
|
196
|
+
options[:retry_wait] = 10
|
197
|
+
options[:retries] = 5
|
196
198
|
parser = OptionParser.new do |opts|
|
197
199
|
opts.banner = "Usage: hostnamer [options]"
|
198
200
|
opts.on "-Z", "--zone-id ZONEID", "Route 53 zone id" do |z|
|
@@ -209,12 +211,12 @@ module Hostnamer
|
|
209
211
|
end
|
210
212
|
opts.on "-p", "--profile [PROFILE]", "AWS user profile. Uses the current IAM or the default profile located under ~/.aws" do |p|
|
211
213
|
options[:profile] = p
|
212
|
-
end
|
213
|
-
opts.on "-r", "--retries [RETRIES]", "Number of times to retry before failing. Defaults to
|
214
|
+
end
|
215
|
+
opts.on "-r", "--retries [RETRIES]", "Number of times to retry before failing. Defaults to #{options[:retries]}" do |r|
|
214
216
|
options[:retries] = r
|
215
217
|
end
|
216
|
-
opts.on "-w", "--retry-wait SECONDS", "Retry wait time. Defaults to
|
217
|
-
|
218
|
+
opts.on "-w", "--retry-wait SECONDS", "Retry wait time. Defaults to #{options[:retry_wait]}s" do |w|
|
219
|
+
options[:retry_wait] = w
|
218
220
|
end
|
219
221
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
220
222
|
options[:verbose] = v
|
@@ -241,13 +243,13 @@ module Hostnamer
|
|
241
243
|
log "detected zone id: #{zid}"
|
242
244
|
zid.strip
|
243
245
|
else
|
244
|
-
raise "could not detect zone_id from #{domain} because \"zone_id\" TXT record is missing. Either insert a TXT record in the DNS or specify --zone-id ZONEID"
|
246
|
+
raise "could not detect zone_id from #{domain} because \"zone_id\" TXT record is missing. Either insert a TXT record in the DNS or specify --zone-id ZONEID"
|
245
247
|
nil
|
246
248
|
end
|
247
249
|
end
|
248
250
|
end
|
249
251
|
end
|
250
|
-
|
252
|
+
|
251
253
|
def detect_soa_ttl(domain)
|
252
254
|
log "detect_soa_ttl" do
|
253
255
|
if answer = `dig +nocmd +noall +answer soa #{domain}`
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hostnamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
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: 2014-
|
12
|
+
date: 2014-12-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -71,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
71
|
version: '0'
|
72
72
|
segments:
|
73
73
|
- 0
|
74
|
-
hash: -
|
74
|
+
hash: -1545043648711111311
|
75
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
76
|
none: false
|
77
77
|
requirements:
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: '0'
|
81
81
|
segments:
|
82
82
|
- 0
|
83
|
-
hash: -
|
83
|
+
hash: -1545043648711111311
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
86
|
rubygems_version: 1.8.23
|