class Proxy::DHCP::Infoblox::HostIpv4AddressCRUD

Public Class Methods

new(connection) click to toggle source
Calls superclass method Proxy::DHCP::Infoblox::CommonCRUD.new
# File lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb, line 6
def initialize(connection)
  @memoized_hosts = []
  @memoized_condition = nil
  super
end

Public Instance Methods

all_hosts(subnet_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb, line 12
def all_hosts(subnet_address)
  address_range_regex = NetworkAddressesRegularExpressionGenerator.new.generate_regex(subnet_address)

  hosts = ::Infoblox::Host.find(
      @connection,
      'ipv4addr~' => address_range_regex,
      '_max_results' => 2147483646)

  ip_addr_matcher = Regexp.new(address_range_regex) # pre-compile the regex
  hosts.map {|host| build_reservation(host.name, host.ipv4addrs.find {|ip| ip_addr_matcher =~ ip.ipv4addr}, subnet_address)}.compact
end
build_host(options) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb, line 53
def build_host(options)
  host = ::Infoblox::Host.new(:connection => @connection)
  host.name = options[:hostname]
  host_addr = host.add_ipv4addr(options[:ip]).last
  host_addr.mac = options[:mac]
  host_addr.configure_for_dhcp = true
  host_addr.nextserver = options[:nextServer]
  host_addr.use_nextserver = true
  host_addr.bootfile = options[:filename]
  host_addr.use_bootfile = true
  host
end
find_host_and_name_by_ip(ip_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb, line 42
def find_host_and_name_by_ip(ip_address)
  h = find_hosts('ipv4addr' => ip_address).first
  h.nil? ? [nil, nil] : [h.name, h.ipv4addrs.find {|ip| ip.ipv4addr == ip_address}]
end
find_hosts(condition, max_results = 1) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb, line 47
def find_hosts(condition, max_results = 1)
  return @memoized_hosts if (!@memoized_hosts.empty? && @memoized_condition == condition)
  @memoized_condition = condition
  @memoized_hosts = ::Infoblox::Host.find(@connection, condition.merge('_max_results' => max_results))
end
find_record_by_ip(subnet_address, ip_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb, line 24
def find_record_by_ip(subnet_address, ip_address)
  found = find_hosts('ipv4addr' => ip_address).first
  return nil if found.nil?
  build_reservation(found.name, found.ipv4addrs.find {|ip| ip.ipv4addr == ip_address}, subnet_address)
end
find_record_by_mac(subnet_address, mac_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb, line 36
def find_record_by_mac(subnet_address, mac_address)
  found = find_hosts('mac' => mac_address).first
  return nil if found.nil?
  build_reservation(found.name, found.ipv4addrs.find {|ip| ip.mac == mac_address}, subnet_address)
end
find_records_by_ip(subnet_address, ip_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb, line 30
def find_records_by_ip(subnet_address, ip_address)
  found = find_hosts({'ipv4addr' => ip_address}, 2147483646)
  return [] if found.empty?
  found.map {|record| build_reservation(record.name, record.ipv4addrs.find {|ip| ip.ipv4addr == ip_address}, subnet_address)}
end