class Proxy::DHCP::Infoblox::FixedAddressCRUD

Attributes

network_view[R]

Public Class Methods

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

Public Instance Methods

all_hosts(subnet_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb, line 15
def all_hosts(subnet_address)
  if @used_ips_search_type == 'used'
    addresses = ::Infoblox::Ipv4address.find(
      @connection,
      'network' => subnet_address,
      'status' => 'USED',
      '_max_results' => 2147483646)
    network = addresses.map do |address|
      if address.mac_address.nil? || address.mac_address.empty?
        checked_mac = '00:00:00:00:00:00'
      else
        checked_mac = address.mac_address
      end
      ::Infoblox::Fixedaddress.new(
        :name => address.names[0],
        :ipv4addr => address.ip_address,
        :mac => checked_mac
      )
    end
  else
    network = ::Infoblox::Fixedaddress.find(
      @connection,
      'network' => subnet_address,
      'network_view' => network_view,
      '_max_results' => 2147483646) #2**(32-cidr_to_i(subnet_address)))
  end

  network.map { |h| build_reservation(h.name, h, subnet_address) }.compact
end
build_host(options) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb, line 80
def build_host(options)
  host = ::Infoblox::Fixedaddress.new(:connection => @connection)
  host.name = options[:hostname]
  host.ipv4addr = options[:ip]
  host.mac = options[:mac]
  host.nextserver = options[:nextServer]
  host.use_nextserver = true
  host.bootfile = options[:filename]
  host.use_bootfile = true
  host.network_view = network_view
  host.options = Proxy::DHCP::Infoblox::Plugin.settings.options
  host
end
find_host_and_name_by_ip(ip_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb, line 75
def find_host_and_name_by_ip(ip_address)
  h = find_hosts('ipv4addr' => ip_address).first
  h.nil? ? [nil, nil] : [h.name, h]
end
find_hosts(condition, max_results = 1) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb, line 67
def find_hosts(condition, max_results = 1)
  return @memoized_hosts if (!@memoized_hosts.empty? && @memoized_condition = condition)

  @memoized_condition = condition
  @memoized_hosts = ::Infoblox::Fixedaddress.find(@connection, condition.merge('_max_results' => max_results,
                                                                               'network_view' => network_view))
end
find_record_by_ip(subnet_address, ip_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb, line 45
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, subnet_address)
end
find_record_by_mac(subnet_address, mac_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb, line 60
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, subnet_address)
end
find_records_by_ip(subnet_address, ip_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb, line 52
def find_records_by_ip(subnet_address, ip_address)
  found = find_hosts({ 'ipv4addr' => ip_address }, 2147483646)
  return [] if found.empty?

  to_return = found.map { |record| build_reservation(record.name, record, subnet_address) }
  to_return.compact
end