Class: Dozens::Alias

Inherits:
Object
  • Object
show all
Defined in:
lib/dozens/alias.rb,
lib/dozens/alias/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Constructor Details

#initialize(zone, hostname, target) ⇒ Alias

Returns a new instance of Alias.



8
9
10
11
12
13
14
15
# File 'lib/dozens/alias.rb', line 8

def initialize zone, hostname, target
  @zone = zone
  @hostname = hostname
  @target = target

  @general_resolv = Resolv::DNS.new
  @target_resolv = Resolv::DNS.new nameserver: authoritative_nameservers
end

Instance Method Details

#update!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dozens/alias.rb', line 17

def update!
  correct_ips = target_ips.sort_by { |x| x }

  api = API.new ENV['DOZENS_USER'], ENV['DOZENS_KEY']

  record_list = api \
    .get_record_list(@zone)['record'] \
    .select { |x| x['type'] == 'A' and x['name'] == @hostname } \
    .sort_by { |x| x['content'] }

  record_list.each_with_index do |r, i|
    if r['content'] != correct_ips[i]
      api.update_record r['id'], correct_ips[i]
      print "=> Updated #{r['content']} to #{correct_ips[i]}\n"
    end
  end
end