class Dozens::Alias
Constants
- VERSION
Public Class Methods
new(zone, hostname, target)
click to toggle source
# 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
Public Instance Methods
update!()
click to toggle source
# 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
Private Instance Methods
target_ips()
click to toggle source
# File lib/dozens/alias.rb, line 48 def target_ips @target_resolv.getaddresses(@target).map { |e| e.to_s } end