Class: Proxy::DHCP::Infoblox::HostIpv4AddressCRUD
- Inherits:
-
CommonCRUD
- Object
- CommonCRUD
- Proxy::DHCP::Infoblox::HostIpv4AddressCRUD
show all
- Defined in:
- lib/smart_proxy_dhcp_infoblox/host_ipv4_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
#cidr_to_bitmask, #cidr_to_i, #cidr_to_ip_mask, #i_to_ipv4, #ipv4_to_i, #network_cidr_to_range
Constructor Details
Returns a new instance of HostIpv4AddressCRUD.
8
9
10
11
12
13
|
# File 'lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb', line 8
def initialize(connection, dns_view)
@memoized_hosts = []
@memoized_condition = nil
@dns_view = dns_view
super(connection)
end
|
Instance Attribute Details
#dns_view ⇒ Object
Returns the value of attribute dns_view.
6
7
8
|
# File 'lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb', line 6
def dns_view
@dns_view
end
|
Instance Method Details
#all_hosts(subnet_address) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb', line 15
def all_hosts(subnet_address)
address_range_regex = NetworkAddressesRegularExpressionGenerator.new.generate_regex(subnet_address)
hosts = ::Infoblox::Host.find(
@connection,
'ipv4addr~' => address_range_regex,
'view' => dns_view,
'_max_results' => 2147483646)
ip_addr_matcher = Regexp.new(address_range_regex) hosts.map { |host| build_reservation(host.name, host.ipv4addrs.find { |ip| ip_addr_matcher =~ ip.ipv4addr }, subnet_address) }.compact
end
|
#build_host(options) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb', line 59
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.view = dns_view
host
end
|
#find_host_and_name_by_ip(ip_address) ⇒ Object
47
48
49
50
|
# File 'lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb', line 47
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) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb', line 52
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('view' => dns_view,
'_max_results' => max_results))
end
|
#find_record_by_ip(subnet_address, ip_address) ⇒ Object
28
29
30
31
32
|
# File 'lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb', line 28
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) ⇒ Object
41
42
43
44
45
|
# File 'lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb', line 41
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) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/smart_proxy_dhcp_infoblox/host_ipv4_address_crud.rb', line 34
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.ipv4addrs.find { |ip| ip.ipv4addr == ip_address }, subnet_address) }
to_return.compact
end
|