class Proxy::Dns::Infoblox::Record

Attributes

connection[R]
dns_view[R]

Public Class Methods

new(host, connection, ttl, dns_view) click to toggle source
Calls superclass method
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 5
def initialize(host, connection, ttl, dns_view)
  @connection = connection
  @dns_view = dns_view
  super(host, ttl)
end

Public Instance Methods

do_create(name, value, type) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 11
def do_create(name, value, type)
  method = "ib_create_#{type.downcase}_record".to_sym
  raise(Proxy::Dns::Error, "Creation of #{type} records not implemented") unless respond_to?(method, true)
  send(method, name, value)
end
do_remove(name, type) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 17
def do_remove(name, type)
  method = "ib_remove_#{type.downcase}_record".to_sym
  raise(Proxy::Dns::Error, "Deletion of #{type} records not implemented") unless respond_to?(method, true)
  send(method, name)
end

Private Instance Methods

ib_clear_dns_cache(record) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 85
def ib_clear_dns_cache(record)
  # Created in WAPI version 2.6
  return if Gem::Version.new(Infoblox.wapi_version) < Gem::Version.new('2.6')

  MemberDns.all(connection).each do |member|
    member.clear_dns_cache(view: record.view, domain: record.name)
  end
rescue StandardError => ex
  # Failing to clear the DNS cache should never be an error
  logger.warn("Exception #{ex} was raised when clearing DNS cache")
end
ib_create(clazz, params) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 70
def ib_create(clazz, params)
  clazz.new({ connection: connection, view: dns_view }.merge(params)).post
end
ib_create_a_record(fqdn, address) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 25
def ib_create_a_record(fqdn, address)
  ib_create(Infoblox::Arecord, :name => fqdn, :ipv4addr => address)
end
ib_create_aaaa_record(fqdn, address) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 33
def ib_create_aaaa_record(fqdn, address)
  ib_create(Infoblox::AAAArecord, :name => fqdn, :ipv6addr => address)
end
ib_create_cname_record(fqdn, target) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 41
def ib_create_cname_record(fqdn, target)
  ib_create(Infoblox::Cname, :name => fqdn, :canonical => target)
end
ib_create_ptr_record(ptr, fqdn) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 49
def ib_create_ptr_record(ptr, fqdn)
  ip = IPAddr.new(ptr_to_ip(ptr))

  params = {
    :ptrdname => fqdn,
    :name => ptr
  }
  params["ipv#{ip.ipv4? ? 4 : 6}addr".to_sym] = ip.to_s

  ib_create(Infoblox::Ptr, params)
end
ib_delete(clazz, params) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 74
def ib_delete(clazz, params)
  record = clazz.find(connection, params.merge(_max_results: 1, view: dns_view)).first

  raise Proxy::Dns::NotFound, "Cannot find #{clazz.class.name} entry for #{params}" if record.nil?
  ret_value = record.delete || (raise Proxy::Dns::NotFound, "Cannot find #{clazz.class.name} entry for #{params}")

  ib_clear_dns_cache(record)

  ret_value
end
ib_remove_a_record(fqdn) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 29
def ib_remove_a_record(fqdn)
  ib_delete(Infoblox::Arecord, :name => fqdn)
end
ib_remove_aaaa_record(fqdn) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 37
def ib_remove_aaaa_record(fqdn)
  ib_delete(Infoblox::AAAArecord, :name => fqdn)
end
ib_remove_cname_record(fqdn) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 45
def ib_remove_cname_record(fqdn)
  ib_delete(Infoblox::Cname, :name => fqdn)
end
ib_remove_ptr_record(ptr) click to toggle source
# File lib/smart_proxy_dns_infoblox/dns_infoblox_main.rb, line 61
def ib_remove_ptr_record(ptr)
  ip = IPAddr.new(ptr_to_ip(ptr))

  params = {}
  params["ipv#{ip.ipv4? ? 4 : 6}addr".to_sym] = ip.to_s

  ib_delete(Infoblox::Ptr, params)
end