Class: Proxy::DHCP::Infoblox::FixedAddressCRUD

Inherits:
CommonCRUD
  • Object
show all
Defined in:
lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb

Instance Attribute Summary collapse

Attributes inherited from CommonCRUD

#connection

Instance Method Summary collapse

Methods inherited from CommonCRUD

#add_record, #all_leases, #build_reservation, #del_record, #del_record_by_mac, #del_records_by_ip, #find_record

Methods included from IpAddressArithmetic

#cidr_to_bitmask, #cidr_to_i, #cidr_to_ip_mask, #i_to_ipv4, #ipv4_to_i, #network_cidr_to_range

Constructor Details

#initialize(connection, network_view) ⇒ FixedAddressCRUD

Returns a new instance of FixedAddressCRUD.



7
8
9
10
11
12
# File 'lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb', line 7

def initialize(connection, network_view)
  @memoized_hosts = []
  @memoized_condition = nil
  @network_view = network_view
  super(connection)
end

Instance Attribute Details

#network_viewObject (readonly)

Returns the value of attribute network_view.



5
6
7
# File 'lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb', line 5

def network_view
  @network_view
end

Instance Method Details

#all_hosts(subnet_address) ⇒ Object



14
15
16
17
18
# File 'lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb', line 14

def all_hosts(subnet_address)
  network = ::Infoblox::Fixedaddress.find(@connection, 'network' => subnet_address, 'network_view' => network_view,
                                          '_max_results' => 2147483646) #2**(32-cidr_to_i(subnet_address)))
  network.map {|h| build_reservation(h.name, h, subnet_address)}.compact
end

#build_host(options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb', line 51

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
end

#find_host_and_name_by_ip(ip_address) ⇒ Object



46
47
48
49
# File 'lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb', line 46

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) ⇒ Object



39
40
41
42
43
44
# File 'lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb', line 39

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) ⇒ Object



20
21
22
23
24
# File 'lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb', line 20

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) ⇒ Object



33
34
35
36
37
# File 'lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb', line 33

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) ⇒ Object



26
27
28
29
30
31
# File 'lib/smart_proxy_dhcp_infoblox/fixed_address_crud.rb', line 26

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