class Proxy::DHCP::Infoblox::UnusedIps

Attributes

connection[R]
network_view[R]
use_ranges[R]

Public Class Methods

new(connection, use_ranges, network_view) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/unused_ips.rb, line 9
def initialize(connection, use_ranges, network_view)
  @connection = connection
  @use_ranges = use_ranges
  @memoized_network = nil
  @network_view = network_view
end

Public Instance Methods

excluded_ips(subnet_address, from, to) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/unused_ips.rb, line 28
def excluded_ips(subnet_address, from, to)
  return [] if from.nil? || to.nil?
  (IPAddr.new(network_cidr_to_range(subnet_address).first)..IPAddr.new(network_cidr_to_range(subnet_address).last)).to_a.map(&:to_s) -
      (IPAddr.new(from)..IPAddr.new(to)).to_a.map(&:to_s)
end
find_network(network_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/unused_ips.rb, line 41
def find_network(network_address)
  return @memoized_network if !@memoized_network.nil? && @memoized_address == network_address
  @memoized_address = network_address
  @memoized_network = ::Infoblox::Network.find(@connection, 'network' => network_address, 'network_view' => network_view,
                                               '_max_results' => 1).first
  raise "Subnet #{network_address} not found" if @memoized_network.nil?
  @memoized_network
end
find_range(network_address, from, to) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/unused_ips.rb, line 34
def find_range(network_address, from, to)
  ranges = ::Infoblox::Range.find(@connection, 'network' => network_address, 'network_view' => network_view)
  range = (from.nil? || to.nil?) ? ranges.first : ranges.find {|r| r.start_addr == from && r.end_addr == to}
  raise "No Ranges found for #{network_address} network" if range.nil?
  range
end
unused_ip(network_address, from_ip_address, to_ip_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/unused_ips.rb, line 16
def unused_ip(network_address, from_ip_address, to_ip_address)
  @use_ranges ? unused_range_ip(network_address, from_ip_address, to_ip_address) : unused_network_ip(network_address, from_ip_address, to_ip_address)
end
unused_network_ip(network_address, from_ip_address, to_ip_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/unused_ips.rb, line 20
def unused_network_ip(network_address, from_ip_address, to_ip_address)
  find_network(network_address).next_available_ip(1, excluded_ips(find_network(network_address).network, from_ip_address, to_ip_address)).first
end
unused_range_ip(network_address, from_ip_address, to_ip_address) click to toggle source
# File lib/smart_proxy_dhcp_infoblox/unused_ips.rb, line 24
def unused_range_ip(network_address, from_ip_address, to_ip_address)
  find_range(network_address, from_ip_address, to_ip_address).next_available_ip(1).first
end