smart_proxy_dhcp_infoblox 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 386bb53985d3965e87d2ed0b4928858efe542d1a6bc28e1147795aae21871691
4
- data.tar.gz: fffe1218aacbb214c899c01f72900756d3c92d13ec64b019e75fdc1307df0712
3
+ metadata.gz: 8270d920065fc68c07721637c04e6a5160540ad55299b02396db1485dfe2e497
4
+ data.tar.gz: b12bb3bb5530f560c0d9b98690bd8f202be137a53cb5a2d598dab847c6d1cf05
5
5
  SHA512:
6
- metadata.gz: 9e6e8069b8151c468aa55e93aacb28bb657ce7b08a5b8ad2fb3a487b016672fb96dcf4c5c32be628d2a2500d890ab498be486c00aad4a94e3a08dac6e918041c
7
- data.tar.gz: a63c13ca94c2e74a5fc7ffc0819d2df23a087c8650e817df7d303a695e56140f605a426108982be65fab94b5c3aa6547c578be701cb602c51cb009a9812052cf
6
+ metadata.gz: 6161907b7c06cf812682b6b7b886522104a79733dd2a14f6b0d2f99b2ba1ffb0abd34d6ca614ff7e07427aa1281d00f2f8841bdcef6fbc863ba099618d62b7fa
7
+ data.tar.gz: '097863ad2d3322617c153644dcab13217fae52d4fbb7906bbd30b9b0b1ce19cfb4cfc86b28b0247a7cc41097c063922eec60cb3a81ead07289ee0f987a99d73a'
data/README.md CHANGED
@@ -39,12 +39,18 @@ Configuration options for this plugin are in `/etc/foreman-proxy/settings.d/dhcp
39
39
  * username: API Username
40
40
  * password: API Password
41
41
  * record_type: host / fixedaddress (see different record types chapter)
42
+ * used_ips_search_type: record_type / used
42
43
 
43
44
  ## Different record types
44
45
  The main difference between host and fixedaddress is that a host record already includes the dns records. It's an infoblox object that includes dhcp/a record/ptr records. If you use the host objects there is no need to use a dns smart proxy. Everything gets handled inside the dhcp smart proxy. This does however limit functionality. You can't delete conflicting records or you can't change dns names using foreman gui. Beware when editing host objects manually in infoblox, once you delete a host in foreman all associated host objects get deleted.
45
46
 
46
47
  If you chose to use fixedaddress you'll need to use the infoblox dns smart proxy (https://github.com/theforeman/smart_proxy_dns_infoblox) if you want to manage dns records.
47
48
 
49
+ ## Used IP search type
50
+ When using "record_type" here, used IPs will be looked up among the record type you select on the record_type setting (host or fixedaddress). So everything which is not a host or a fixedaddress (depending on the setting), will be defined as free and can be selected as an IP to provision a host.
51
+ If the IP is used by just a DNS A entry for example, this can lead to conflicts. If "used" is set here, any usage of an IP will mark it as used and the IP will not be selected as free ip to provision a host.
52
+ Usages without a mac address will get a dummy mac address ("00:00:00:00:00:00"), when Foreman looks for "all_hosts".
53
+
48
54
  ## SSL
49
55
 
50
56
  The plugin enforces HTTPS server certificate verification. Follow a standard CA cert installation procedure for your operating system. It's possible to either download the server certificate from Infoblox web UI or use openssl command to extract it from server response. Here are example steps for Red Hat compatible systems:
@@ -13,6 +13,11 @@
13
13
  # using "host" setting make sure domain exists in Infoblox.
14
14
  :record_type: 'fixedaddress'
15
15
 
16
+ # Search type used when looking for used IPs: can be "record_type" or "used". The latter can be used when you want to include all "USED"
17
+ # IPs in the search for used IPs, so that only really "UNUSED" (no Host, no DNS object, no DHCP Range, not unmanaged, etc.) are used, when
18
+ # searching for a unused IP. Defaults to "record_type", which uses the record_type selected above to look for used IPs.
19
+ #:used_ips_search_type: 'record_type'
20
+
16
21
  # View used for fixedaddress record type.
17
22
  #:network_view: 'default'
18
23
 
@@ -10,8 +10,9 @@ module ::Proxy::DHCP::Infoblox
10
10
 
11
11
  attr_reader :connection
12
12
 
13
- def initialize(connection)
13
+ def initialize(connection, used_ips_search_type)
14
14
  @connection = connection
15
+ @used_ips_search_type = used_ips_search_type
15
16
  end
16
17
 
17
18
  def all_leases(network_address, subnet)
@@ -19,6 +20,7 @@ module ::Proxy::DHCP::Infoblox
19
20
  ::Infoblox::Lease.find(@connection, 'address~' => address_range_regex).map do |lease|
20
21
  # Infoblox can return MAC address set to nil
21
22
  next unless lease.hardware
23
+
22
24
  Proxy::DHCP::Lease.new(
23
25
  lease.client_hostname,
24
26
  lease.address,
@@ -34,6 +36,7 @@ module ::Proxy::DHCP::Infoblox
34
36
 
35
37
  def find_record(subnet_address, an_address)
36
38
  return find_record_by_ip(subnet_address, an_address) if Resolv::IPv4::Regex =~ an_address
39
+
37
40
  find_record_by_mac(subnet_address, an_address)
38
41
  end
39
42
 
@@ -58,19 +61,23 @@ module ::Proxy::DHCP::Infoblox
58
61
  if options[:mac] != existing_host.mac || options[:hostname] != existing_name
59
62
  raise Proxy::DHCP::Collision, "Record #{options[:ip]} conflicts with an existing record."
60
63
  end
64
+
61
65
  raise Proxy::DHCP::AlreadyExists, "Record #{options[:ip]} already exists."
62
66
  end
63
67
 
64
68
  def del_record(_, record)
65
69
  raise InvalidRecord, "#{record} is static - unable to delete" unless record.deleteable?
70
+
66
71
  found = find_hosts('ipv4addr' => record.ip).first
67
72
  return if found.nil?
73
+
68
74
  found.delete
69
75
  end
70
76
 
71
77
  def del_records_by_ip(ip_address)
72
78
  found = find_hosts({ 'ipv4addr' => ip_address }, 2147483646)
73
79
  return if found.empty?
80
+
74
81
  found.each { |record| record.delete }
75
82
  nil
76
83
  end
@@ -78,6 +85,7 @@ module ::Proxy::DHCP::Infoblox
78
85
  def del_record_by_mac(mac_address)
79
86
  found = find_hosts('mac' => mac_address).first
80
87
  return if found.nil?
88
+
81
89
  found.delete
82
90
  nil
83
91
  end
@@ -90,11 +98,13 @@ module ::Proxy::DHCP::Infoblox
90
98
 
91
99
  opts = { :hostname => name }
92
100
  opts[:deleteable] = true
93
- # TODO: nextserver, use_nextserver, bootfile, and use_bootfile attrs exist but are not available in the Fixedaddress model
101
+ # TODO: nextserver, use_nextserver, bootfile, and use_bootfile attrs exist
102
+ # but are not available in the Fixedaddress model
94
103
  # Might be useful to extend the model to include these
95
104
  opts[:nextServer] = host.nextserver if (host.respond_to?(:use_nextserver) && host.use_nextserver)
96
105
  opts[:filename] = host.bootfile if (host.respond_to?(:use_bootfile) && host.use_bootfile)
97
- subnet = ::Proxy::DHCP::Subnet.new(full_subnet_address.split('/').first, cidr_to_ip_mask(cidr_to_i(full_subnet_address.split('/').last)))
106
+ subnet = ::Proxy::DHCP::Subnet.new(full_subnet_address.split('/').first,
107
+ cidr_to_ip_mask(cidr_to_i(full_subnet_address.split('/').last)))
98
108
 
99
109
  Proxy::DHCP::Reservation.new(name, host.ipv4addr, host.mac, subnet, opts)
100
110
  end
@@ -93,6 +93,7 @@ module Proxy::DHCP::Infoblox
93
93
  network = ::Infoblox::Network.find(connection, 'network' => network_address, 'network_view' => network_view,
94
94
  '_max_results' => 1).first
95
95
  raise "Subnet #{network_address} not found in network view #{network_view}" if network.nil?
96
+
96
97
  network
97
98
  end
98
99
 
@@ -3,20 +3,21 @@ module Proxy::DHCP::Infoblox
3
3
  plugin :dhcp_infoblox, ::Proxy::DHCP::Infoblox::VERSION
4
4
 
5
5
  default_settings :record_type => 'fixedaddress',
6
- :dns_view => "default",
7
- :network_view => "default",
8
- :blacklist_duration_minutes => 30 * 60,
9
- :wait_after_restart => 10,
10
- :options => []
6
+ :used_ips_search_type => "record_type",
7
+ :dns_view => "default",
8
+ :network_view => "default",
9
+ :blacklist_duration_minutes => 30 * 60,
10
+ :wait_after_restart => 10,
11
+ :options => []
11
12
 
12
13
  validate_presence :username, :password
13
14
 
14
- requires :dhcp, '>= 1.13'
15
+ requires :dhcp, '>= 3.2'
15
16
 
16
17
  load_classes ::Proxy::DHCP::Infoblox::PluginConfiguration
17
- load_validators :record_type_validator => ::Proxy::DHCP::Infoblox::RecordTypeValidator
18
18
  load_dependency_injection_wirings ::Proxy::DHCP::Infoblox::PluginConfiguration
19
19
 
20
- validate :record_type, :record_type_validator => true
20
+ validate :record_type, enum: %w[host fixedaddress]
21
+ validate :used_ips_search_type, enum: %w[record_type used]
21
22
  end
22
23
  end
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module DHCP
3
3
  module Infoblox
4
- VERSION = '0.0.16'.freeze
4
+ VERSION = '0.0.17'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -5,28 +5,54 @@ module ::Proxy::DHCP::Infoblox
5
5
  class FixedAddressCRUD < CommonCRUD
6
6
  attr_reader :network_view
7
7
 
8
- def initialize(connection, network_view)
8
+ def initialize(connection, network_view, used_ips_search_type)
9
9
  @memoized_hosts = []
10
10
  @memoized_condition = nil
11
11
  @network_view = network_view
12
- super(connection)
12
+ super(connection, used_ips_search_type)
13
13
  end
14
14
 
15
15
  def all_hosts(subnet_address)
16
- network = ::Infoblox::Fixedaddress.find(@connection, 'network' => subnet_address, 'network_view' => network_view,
17
- '_max_results' => 2147483646) #2**(32-cidr_to_i(subnet_address)))
16
+ if @used_ips_search_type == 'used'
17
+ addresses = ::Infoblox::Ipv4address.find(
18
+ @connection,
19
+ 'network' => subnet_address,
20
+ 'status' => 'USED',
21
+ '_max_results' => 2147483646)
22
+ network = addresses.map do |address|
23
+ if address.mac_address.nil? || address.mac_address.empty?
24
+ checked_mac = '00:00:00:00:00:00'
25
+ else
26
+ checked_mac = address.mac_address
27
+ end
28
+ ::Infoblox::Fixedaddress.new(
29
+ :name => address.names[0],
30
+ :ipv4addr => address.ip_address,
31
+ :mac => checked_mac
32
+ )
33
+ end
34
+ else
35
+ network = ::Infoblox::Fixedaddress.find(
36
+ @connection,
37
+ 'network' => subnet_address,
38
+ 'network_view' => network_view,
39
+ '_max_results' => 2147483646) #2**(32-cidr_to_i(subnet_address)))
40
+ end
41
+
18
42
  network.map { |h| build_reservation(h.name, h, subnet_address) }.compact
19
43
  end
20
44
 
21
45
  def find_record_by_ip(subnet_address, ip_address)
22
46
  found = find_hosts('ipv4addr' => ip_address).first
23
47
  return nil if found.nil?
48
+
24
49
  build_reservation(found.name, found, subnet_address)
25
50
  end
26
51
 
27
52
  def find_records_by_ip(subnet_address, ip_address)
28
53
  found = find_hosts({ 'ipv4addr' => ip_address }, 2147483646)
29
54
  return [] if found.empty?
55
+
30
56
  to_return = found.map { |record| build_reservation(record.name, record, subnet_address) }
31
57
  to_return.compact
32
58
  end
@@ -34,11 +60,13 @@ module ::Proxy::DHCP::Infoblox
34
60
  def find_record_by_mac(subnet_address, mac_address)
35
61
  found = find_hosts('mac' => mac_address).first
36
62
  return nil if found.nil?
63
+
37
64
  build_reservation(found.name, found, subnet_address)
38
65
  end
39
66
 
40
67
  def find_hosts(condition, max_results = 1)
41
68
  return @memoized_hosts if (!@memoized_hosts.empty? && @memoized_condition = condition)
69
+
42
70
  @memoized_condition = condition
43
71
  @memoized_hosts = ::Infoblox::Fixedaddress.find(@connection, condition.merge('_max_results' => max_results,
44
72
  'network_view' => network_view))
@@ -5,42 +5,70 @@ module ::Proxy::DHCP::Infoblox
5
5
  class HostIpv4AddressCRUD < CommonCRUD
6
6
  attr_reader :dns_view
7
7
 
8
- def initialize(connection, dns_view)
8
+ def initialize(connection, dns_view, used_ips_search_type)
9
9
  @memoized_hosts = []
10
10
  @memoized_condition = nil
11
11
  @dns_view = dns_view
12
- super(connection)
12
+ super(connection, used_ips_search_type)
13
13
  end
14
14
 
15
15
  def all_hosts(subnet_address)
16
16
  address_range_regex = NetworkAddressesRegularExpressionGenerator.new.generate_regex(subnet_address)
17
17
 
18
- hosts = ::Infoblox::Host.find(
19
- @connection,
18
+ if @used_ips_search_type == 'used'
19
+ addresses = ::Infoblox::Ipv4address.find(
20
+ @connection,
21
+ 'network' => subnet_address,
22
+ 'status' => 'USED',
23
+ '_max_results' => 2147483646
24
+ )
25
+ hosts = addresses.map do |address|
26
+ if address.mac_address.nil? || address.mac_address.empty?
27
+ checked_mac = '00:00:00:00:00:00'
28
+ else
29
+ checked_mac = address.mac_address
30
+ end
31
+ ::Infoblox::Host.new(
32
+ :name => address.names[0],
33
+ :ipv4addrs => [{ :name => address.names[0], :ipv4addr => address.ip_address, :mac => checked_mac,
34
+ :configure_for_dhcp => true }]
35
+ )
36
+ end
37
+ else
38
+ hosts = ::Infoblox::Host.find(
39
+ @connection,
20
40
  'ipv4addr~' => address_range_regex,
21
41
  'view' => dns_view,
22
- '_max_results' => 2147483646)
42
+ '_max_results' => 2147483646
43
+ )
44
+ end
23
45
 
24
46
  ip_addr_matcher = Regexp.new(address_range_regex) # pre-compile the regex
25
- hosts.map { |host| build_reservation(host.name, host.ipv4addrs.find { |ip| ip_addr_matcher =~ ip.ipv4addr }, subnet_address) }.compact
47
+ hosts.map do |host|
48
+ build_reservation(host.name, host.ipv4addrs.find { |ip| ip_addr_matcher =~ ip.ipv4addr }, subnet_address)
49
+ end.compact
26
50
  end
27
51
 
28
52
  def find_record_by_ip(subnet_address, ip_address)
29
53
  found = find_hosts('ipv4addr' => ip_address).first
30
54
  return nil if found.nil?
55
+
31
56
  build_reservation(found.name, found.ipv4addrs.find { |ip| ip.ipv4addr == ip_address }, subnet_address)
32
57
  end
33
58
 
34
59
  def find_records_by_ip(subnet_address, ip_address)
35
60
  found = find_hosts({ 'ipv4addr' => ip_address }, 2147483646)
36
61
  return [] if found.empty?
37
- to_return = found.map { |record| build_reservation(record.name, record.ipv4addrs.find { |ip| ip.ipv4addr == ip_address }, subnet_address) }
38
- to_return.compact
62
+
63
+ found.map do |record|
64
+ build_reservation(record.name, record.ipv4addrs.find { |ip| ip.ipv4addr == ip_address }, subnet_address)
65
+ end.compact
39
66
  end
40
67
 
41
68
  def find_record_by_mac(subnet_address, mac_address)
42
69
  found = find_hosts('mac' => mac_address).first
43
70
  return nil if found.nil?
71
+
44
72
  build_reservation(found.name, found.ipv4addrs.find { |ip| ip.mac == mac_address }, subnet_address)
45
73
  end
46
74
 
@@ -51,6 +79,7 @@ module ::Proxy::DHCP::Infoblox
51
79
 
52
80
  def find_hosts(condition, max_results = 1)
53
81
  return @memoized_hosts if (!@memoized_hosts.empty? && @memoized_condition == condition)
82
+
54
83
  @memoized_condition = condition
55
84
  @memoized_hosts = ::Infoblox::Host.find(@connection, condition.merge('view' => dns_view,
56
85
  '_max_results' => max_results))
@@ -1,20 +1,20 @@
1
1
  module ::Proxy::DHCP::Infoblox
2
2
  module IpAddressArithmetic
3
3
  def cidr_to_ip_mask(prefix_length)
4
- bitmask = 0xFFFFFFFF ^ (2**(32 - prefix_length) - 1)
5
- (0..3).map { |i| (bitmask >> i * 8) & 0xFF }.reverse.join('.')
4
+ bitmask = 0xFFFFFFFF ^ ((2**(32 - prefix_length)) - 1)
5
+ (0..3).map { |i| (bitmask >> (i * 8)) & 0xFF }.reverse.join('.')
6
6
  end
7
7
 
8
8
  def ipv4_to_i(an_address)
9
9
  an_address.split('.').inject(0) { |a, c| (a << 8) + c.to_i }
10
10
  end
11
11
 
12
- def i_to_ipv4(i)
12
+ def i_to_ipv4(i) # rubocop:todo Naming/MethodParameterName
13
13
  (0..3).inject([]) { |a, c| a.push((i >> (c * 8)) & 0xFF) }.reverse.join('.')
14
14
  end
15
15
 
16
16
  def cidr_to_bitmask(prefix_length)
17
- 0xFFFFFFFF ^ (2**(32 - prefix_length) - 1)
17
+ 0xFFFFFFFF ^ ((2**(32 - prefix_length)) - 1)
18
18
  end
19
19
 
20
20
  def cidr_to_i(an_address_with_cidr)
@@ -12,6 +12,7 @@ module ::Proxy::DHCP::Infoblox
12
12
 
13
13
  def add_children(values)
14
14
  return if values.empty?
15
+
15
16
  node = (found = children.find { |n| n.value == values.first }).nil? ? add_child(Node.new(values.first)) : found
16
17
  node.add_children(values[1..-1])
17
18
  end
@@ -21,6 +22,7 @@ module ::Proxy::DHCP::Infoblox
21
22
  return 1 if other.value.to_s == '0?'
22
23
  return 0 if value == other.value
23
24
  return -1 if value < other.value
25
+
24
26
  1
25
27
  end
26
28
 
@@ -33,9 +35,13 @@ module ::Proxy::DHCP::Infoblox
33
35
  def group_children
34
36
  children.each { |n| n.group_children }
35
37
  return if children.size < 2
38
+
36
39
  @children = children[1..-1].each_with_object([MergedNode.new(children.first)]) do |to_group, grouped|
37
40
  current = MergedNode.new(to_group)
38
- found = grouped.find { |g| ((g.value != ['0?'] && current.value != ['0?']) || (current.value == ['0?'] && g.value == ['0?'])) && (g.children == current.children) }
41
+ found = grouped.find do |g|
42
+ ((g.value != ['0?'] && current.value != ['0?']) || (current.value == ['0?'] && g.value == ['0?'])) && \
43
+ (g.children == current.children)
44
+ end
39
45
  found.nil? ? grouped.push(current) : found.merge(current)
40
46
  end
41
47
  end
@@ -47,6 +53,7 @@ module ::Proxy::DHCP::Infoblox
47
53
 
48
54
  class MergedNode
49
55
  attr_accessor :value, :children
56
+
50
57
  def initialize(a_node)
51
58
  @value = [a_node.value].flatten
52
59
  @children = a_node.children
@@ -62,11 +69,12 @@ module ::Proxy::DHCP::Infoblox
62
69
  end
63
70
 
64
71
  def value_as_regex
65
- (value.size < 2) ? value.first.to_s : "[#{value.join('')}]"
72
+ (value.size < 2) ? value.first.to_s : "[#{value.join}]"
66
73
  end
67
74
 
68
75
  def ==(other)
69
76
  return false if self.class != other.class
77
+
70
78
  value == other.value
71
79
  end
72
80
  end
@@ -10,27 +10,34 @@ module Proxy::DHCP::Infoblox
10
10
  require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_main'
11
11
  end
12
12
 
13
- def load_dependency_injection_wirings(c, settings)
13
+ def load_dependency_injection_wirings(c, settings) # rubocop:todo Naming/MethodParameterName
14
14
  c.dependency :connection, (lambda {
15
15
  ::Infoblox.wapi_version = '2.0'
16
16
  ::Infoblox::Connection.new(:username => settings[:username], :password => settings[:password],
17
- :host => settings[:server], :ssl_opts => { :verify => !ENV['FOREMAN_INFOBLOX_NOSSLVERIFY'] },
17
+ :host => settings[:server],
18
+ :ssl_opts => { :verify => !ENV['FOREMAN_INFOBLOX_NOSSLVERIFY'] },
18
19
  :logger => ::Proxy::LogBuffer::Decorator.instance)
19
20
  })
20
21
 
21
22
  c.singleton_dependency :unused_ips, lambda { ::Proxy::DHCP::FreeIps.new(settings[:blacklist_duration_minutes]) }
22
23
 
23
24
  c.dependency :host_ipv4_crud, (lambda {
24
- ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(c.get_dependency(:connection), settings[:dns_view])
25
+ ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(
26
+ c.get_dependency(:connection),
27
+ settings[:dns_view],
28
+ settings[:used_ips_search_type])
25
29
  })
26
30
  c.dependency :fixed_address_crud, (lambda {
27
- ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(c.get_dependency(:connection), settings[:network_view])
31
+ ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(
32
+ c.get_dependency(:connection),
33
+ settings[:network_view],
34
+ settings[:used_ips_search_type])
28
35
  })
29
36
  c.dependency :grid_restart, lambda { ::Proxy::DHCP::Infoblox::GridRestart.new(c.get_dependency(:connection)) }
30
37
  c.dependency :dhcp_provider, (lambda {
31
38
  ::Proxy::DHCP::Infoblox::Provider.new(
32
39
  c.get_dependency(:connection),
33
- (settings[:record_type] == 'host') ? c.get_dependency(:host_ipv4_crud) : c.get_dependency(:fixed_address_crud),
40
+ c.get_dependency(settings[:record_type] == 'host' ? :host_ipv4_crud : :fixed_address_crud),
34
41
  c.get_dependency(:grid_restart),
35
42
  c.get_dependency(:unused_ips),
36
43
  settings[:subnets],
@@ -5,6 +5,5 @@ module Proxy
5
5
  end
6
6
 
7
7
  require 'smart_proxy_dhcp_infoblox/plugin_configuration'
8
- require 'smart_proxy_dhcp_infoblox/record_type_validator'
9
8
  require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_version'
10
9
  require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_plugin'
@@ -93,7 +93,7 @@ class HostCrudTest < Test::Unit::TestCase
93
93
  def setup
94
94
  @connection = Object.new
95
95
  @view = "something"
96
- @crud = ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(@connection, @view)
96
+ @crud = ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(@connection, @view, 'record_type')
97
97
 
98
98
  @entity = ::Infoblox::Host
99
99
 
@@ -115,17 +115,50 @@ class HostCrudTest < Test::Unit::TestCase
115
115
  :ipv4addrs => [{ :ipv4addr => @ip, :mac => '00:01:02:03:05:07', :nextserver => @nextserver, :use_nextserver => true,
116
116
  :bootfile => @filename, :use_bootfile => true, :configure_for_dhcp => true }])
117
117
 
118
+ @ipv4address = ::Infoblox::Ipv4address.new(
119
+ :names => [@hostname],
120
+ :ip_address => @ip,
121
+ :mac_address => @mac
122
+ )
123
+
124
+ @ipv4address_dnsonly = ::Infoblox::Ipv4address.new(
125
+ :names => ['dnsonly.test.com'],
126
+ :ip_address => '192.168.42.2',
127
+ :mac_address => ''
128
+ )
129
+
118
130
  @reservation = ::Proxy::DHCP::Reservation.new(@hostname, @ip, @mac, ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
119
131
  :hostname => @hostname, :nextServer => @nextserver, :filename => @filename,
120
132
  :deleteable => true)
133
+
134
+ @reservation_without_opts = ::Proxy::DHCP::Reservation.new(@hostname, @ip, @mac, ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
135
+ :hostname => @hostname, :deleteable => true)
136
+
137
+ @reservation_dnsonly = ::Proxy::DHCP::Reservation.new('dnsonly.test.com', '192.168.42.2', '00:00:00:00:00:00',
138
+ ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
139
+ :hostname => 'dnsonly.test.com', :deleteable => true)
121
140
  end
122
141
 
123
- def test_all_hosts
142
+ def test_all_hosts_with_find_by_record_type
124
143
  ::Infoblox::Host.expects(:find).with(@connection, 'ipv4addr~' => '192\.168\.42\..+', 'view' => @view,
125
144
  '_max_results' => 2147483646).returns([@host])
126
145
  assert_equal @reservation, @crud.all_hosts('192.168.42.0/24').first
127
146
  end
128
147
 
148
+ def test_all_hosts_with_find_by_used
149
+ @crud_used = ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(@connection, @view, 'used')
150
+ ::Infoblox::Ipv4address.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'status' => 'USED',
151
+ '_max_results' => 2147483646).returns([@ipv4address])
152
+ assert_equal @reservation_without_opts, @crud_used.all_hosts('192.168.42.0/24').first
153
+ end
154
+
155
+ def test_all_hosts_with_find_by_used_dns_record_creates_reservation
156
+ @crud_dnsonly = ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(@connection, @view, 'used')
157
+ ::Infoblox::Ipv4address.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'status' => 'USED',
158
+ '_max_results' => 2147483646).returns([@ipv4address_dnsonly])
159
+ assert_equal @reservation_dnsonly, @crud_dnsonly.all_hosts('192.168.42.0/24').first
160
+ end
161
+
129
162
  def test_build_host
130
163
  built = @crud.build_host(:hostname => @hostname, :mac => @mac, :ip => @ip, :nextServer => @nextserver,
131
164
  :filename => @filename, :deleteable => true)
@@ -166,7 +199,7 @@ class FixedaddressCrudTest < Test::Unit::TestCase
166
199
  def setup
167
200
  @connection = Object.new
168
201
  @network_view = "something"
169
- @crud = ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(@connection, @network_view)
202
+ @crud = ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(@connection, @network_view, 'record_type')
170
203
 
171
204
  @entity = ::Infoblox::Fixedaddress
172
205
 
@@ -184,16 +217,49 @@ class FixedaddressCrudTest < Test::Unit::TestCase
184
217
  :name => 'another.test.com',
185
218
  :ipv4addr => @ip, :mac => '00:01:02:03:05:07', :network_view => @network_view)
186
219
 
220
+ @ipv4address = ::Infoblox::Ipv4address.new(
221
+ :names => [@hostname],
222
+ :ip_address => @ip,
223
+ :mac_address => @mac
224
+ )
225
+
226
+ @ipv4address_dnsonly = ::Infoblox::Ipv4address.new(
227
+ :names => ['dnsonly.test.com'],
228
+ :ip_address => '192.168.42.2',
229
+ :mac_address => ''
230
+ )
231
+
187
232
  @reservation = ::Proxy::DHCP::Reservation.new(@hostname, @ip, @mac, ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
188
233
  :deleteable => true, :hostname => @hostname)
234
+
235
+ @reservation_without_opts = ::Proxy::DHCP::Reservation.new(@hostname, @ip, @mac, ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
236
+ :hostname => @hostname, :deleteable => true)
237
+
238
+ @reservation_dnsonly = ::Proxy::DHCP::Reservation.new('dnsonly.test.com', '192.168.42.2', '00:00:00:00:00:00',
239
+ ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
240
+ :hostname => 'dnsonly.test.com', :deleteable => true)
189
241
  end
190
242
 
191
- def test_all_hosts
243
+ def test_all_hosts_with_find_by_record_type
192
244
  ::Infoblox::Fixedaddress.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'network_view' => @network_view,
193
245
  '_max_results' => 2147483646).returns([@host])
194
246
  assert_equal @reservation, @crud.all_hosts('192.168.42.0/24').first
195
247
  end
196
248
 
249
+ def test_all_hosts_with_find_by_used
250
+ @crud_used = ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(@connection, @network_view, 'used')
251
+ ::Infoblox::Ipv4address.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'status' => 'USED',
252
+ '_max_results' => 2147483646).returns([@ipv4address])
253
+ assert_equal @reservation_without_opts, @crud_used.all_hosts('192.168.42.0/24').first
254
+ end
255
+
256
+ def test_all_hosts_with_find_by_used_dns_record_creates_reservation
257
+ @crud_dnsonly = ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(@connection, @network_view, 'used')
258
+ ::Infoblox::Ipv4address.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'status' => 'USED',
259
+ '_max_results' => 2147483646).returns([@ipv4address_dnsonly])
260
+ assert_equal @reservation_dnsonly, @crud_dnsonly.all_hosts('192.168.42.0/24').first
261
+ end
262
+
197
263
  def test_build_host
198
264
  built = @crud.build_host(:hostname => @hostname, :mac => @mac, :ip => @ip, :nextServer => @nextserver,
199
265
  :filename => @filename, :deleteable => true)
@@ -12,6 +12,7 @@ class InfobloxProviderTest < Test::Unit::TestCase
12
12
  @unused_ips = Object.new
13
13
  @managed_subnets = nil
14
14
  @network_view = "another"
15
+ @used_ips_search_type = 'record_type'
15
16
 
16
17
  @network = Infoblox::Network.new(:network => '192.168.42.0/24')
17
18
  @subnet = ::Proxy::DHCP::Subnet.new('192.168.42.0', '255.255.255.0')
@@ -42,7 +43,7 @@ class InfobloxProviderTest < Test::Unit::TestCase
42
43
  end
43
44
 
44
45
  def test_leases
45
- @crud = ::Proxy::DHCP::Infoblox::CommonCRUD.new(@connection)
46
+ @crud = ::Proxy::DHCP::Infoblox::CommonCRUD.new(@connection, @used_ips_search_type)
46
47
  @provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
47
48
  @unused_ips, @managed_subnets, @network_view)
48
49
 
@@ -52,7 +53,7 @@ class InfobloxProviderTest < Test::Unit::TestCase
52
53
  end
53
54
 
54
55
  def test_nonclass_leases
55
- @crud = ::Proxy::DHCP::Infoblox::CommonCRUD.new(@connection)
56
+ @crud = ::Proxy::DHCP::Infoblox::CommonCRUD.new(@connection,@used_ips_search_type)
56
57
  @provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
57
58
  @unused_ips, @managed_subnets, @network_view)
58
59
 
@@ -3,7 +3,6 @@ require 'infoblox'
3
3
  require 'dhcp_common/dhcp_common'
4
4
  require 'dhcp_common/free_ips'
5
5
  require 'smart_proxy_dhcp_infoblox/plugin_configuration'
6
- require 'smart_proxy_dhcp_infoblox/record_type_validator'
7
6
  require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_plugin'
8
7
  require 'smart_proxy_dhcp_infoblox/host_ipv4_address_crud'
9
8
  require 'smart_proxy_dhcp_infoblox/fixed_address_crud'
@@ -13,6 +12,7 @@ require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_main'
13
12
  class PluginDefaultConfigurationTest < Test::Unit::TestCase
14
13
  def test_default_settings
15
14
  assert_equal({ :record_type => 'fixedaddress',
15
+ :used_ips_search_type => "record_type",
16
16
  :blacklist_duration_minutes => 30 * 60,
17
17
  :wait_after_restart => 10,
18
18
  :dns_view => "default",
@@ -27,8 +27,8 @@ class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
27
27
  @network_view = "network_view"
28
28
  @dns_view = "dns_view"
29
29
  @settings = { :username => 'user', :password => 'password', :server => '127.0.0.1', :record_type => 'fixedaddress',
30
- :subnets => ['1.1.1.0/255.255.255.0'], :blacklist_duration_minutes => 300, :wait_after_restart => 1,
31
- :dns_view => @dns_view, :network_view => @network_view }
30
+ :used_ips_search_type => 'record_type', :subnets => ['1.1.1.0/255.255.255.0'], :blacklist_duration_minutes => 300,
31
+ :wait_after_restart => 1,:dns_view => @dns_view, :network_view => @network_view }
32
32
  @container = ::Proxy::DependencyInjection::Container.new
33
33
  Proxy::DHCP::Infoblox::PluginConfiguration.new.load_dependency_injection_wirings(@container, @settings)
34
34
  end
@@ -76,8 +76,8 @@ class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
76
76
 
77
77
  def test_provider_configuration_with_fixedaddress_crud
78
78
  Proxy::DHCP::Infoblox::PluginConfiguration.new.
79
- load_dependency_injection_wirings(@container, :username => 'user', :password => 'password',
80
- :server => '127.0.0.1', :record_type => 'fixed_address')
79
+ load_dependency_injection_wirings(@container, :username => 'user', :password => 'password', :server => '127.0.0.1',
80
+ :record_type => 'fixed_address', :used_ips_search_type => 'record_type')
81
81
 
82
82
  provider = @container.get_dependency(:dhcp_provider)
83
83
  assert provider.crud.instance_of?(::Proxy::DHCP::Infoblox::FixedAddressCRUD)
data/test/test_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require 'mocha/setup'
2
+ require 'mocha/test_unit'
3
3
 
4
4
  require 'smart_proxy_for_testing'
5
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_dhcp_infoblox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaas Demter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-04 00:00:00.000000000 Z
11
+ date: 2022-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: infoblox
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rubocop
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.50.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.50.0
41
27
  description: Infoblox DHCP provider plugin for Foreman's smart proxy
42
28
  email:
43
29
  - demter@atix.de
@@ -60,12 +46,10 @@ files:
60
46
  - lib/smart_proxy_dhcp_infoblox/ip_address_arithmetic.rb
61
47
  - lib/smart_proxy_dhcp_infoblox/network_address_range_regex_generator.rb
62
48
  - lib/smart_proxy_dhcp_infoblox/plugin_configuration.rb
63
- - lib/smart_proxy_dhcp_infoblox/record_type_validator.rb
64
49
  - test/host_and_fixedaddress_crud_test.rb
65
50
  - test/infoblox_provider_test.rb
66
51
  - test/integration_test.rb
67
52
  - test/plugin_configuration_test.rb
68
- - test/record_type_validator_test.rb
69
53
  - test/regex_generator_test.rb
70
54
  - test/test_helper.rb
71
55
  - test/unused_ip_test.rb
@@ -81,23 +65,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
65
  requirements:
82
66
  - - ">="
83
67
  - !ruby/object:Gem::Version
84
- version: '0'
68
+ version: '2.5'
85
69
  required_rubygems_version: !ruby/object:Gem::Requirement
86
70
  requirements:
87
71
  - - ">="
88
72
  - !ruby/object:Gem::Version
89
73
  version: '0'
90
74
  requirements: []
91
- rubygems_version: 3.0.3
75
+ rubygems_version: 3.3.7
92
76
  signing_key:
93
77
  specification_version: 4
94
78
  summary: Infoblox DHCP provider plugin for Foreman's smart proxy
95
79
  test_files:
96
- - test/test_helper.rb
80
+ - test/host_and_fixedaddress_crud_test.rb
97
81
  - test/infoblox_provider_test.rb
82
+ - test/integration_test.rb
98
83
  - test/plugin_configuration_test.rb
99
- - test/record_type_validator_test.rb
100
- - test/unused_ip_test.rb
101
- - test/host_and_fixedaddress_crud_test.rb
102
84
  - test/regex_generator_test.rb
103
- - test/integration_test.rb
85
+ - test/test_helper.rb
86
+ - test/unused_ip_test.rb
@@ -1,8 +0,0 @@
1
- module ::Proxy::DHCP::Infoblox
2
- class RecordTypeValidator < ::Proxy::PluginValidators::Base
3
- def validate!(settings)
4
- return true if ['host', 'fixedaddress'].include?(settings[:record_type])
5
- raise ::Proxy::Error::ConfigurationError, "Setting 'record_type' can be set to either 'host' or 'fixedaddress'"
6
- end
7
- end
8
- end
@@ -1,20 +0,0 @@
1
- require 'test_helper'
2
- require 'smart_proxy_dhcp_infoblox/record_type_validator'
3
-
4
- class RecordTypeValidatorTest < Test::Unit::TestCase
5
- def setup
6
- @validator = ::Proxy::DHCP::Infoblox::RecordTypeValidator.new(:dhcp_infoblox, :record_type, nil, nil)
7
- end
8
-
9
- def test_should_pass_when_record_type_is_host
10
- assert @validator.validate!(:record_type => 'host')
11
- end
12
-
13
- def test_should_pass_when_record_type_is_fixedaddress
14
- assert @validator.validate!(:record_type => 'fixedaddress')
15
- end
16
-
17
- def test_should_raise_exception_when_record_type_is_unrecognised
18
- assert_raises(::Proxy::Error::ConfigurationError) { @validator.validate!(:record_type => '') }
19
- end
20
- end