smart_proxy_dhcp_infoblox 0.0.7 → 0.0.8

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
  SHA1:
3
- metadata.gz: d3ff6b849368389cef25d7fbcc8b3f4072f29451
4
- data.tar.gz: 11cb8b354e2917816c4bd4ca957d93f664ee2309
3
+ metadata.gz: 1a07a8c599733c506c451ce081884584dc9501eb
4
+ data.tar.gz: a07bed8a8a3b384a5670cff0c0c0f72005ebbc17
5
5
  SHA512:
6
- metadata.gz: 985763eae34749aa8f78529476bee93b1ae55008d5f814184785b6365be50d00311e2bb16e214cd29977ea34c7517cb0a416d5d2cbc510f56916c396d62586b9
7
- data.tar.gz: f7c85f678518194b307880a62eba5a0305a56467f784ada42822f398315df744fe300aaa8d50f5cfd53cdfa71ceebed1cf296c52689ed551d897fa201867cbe0
6
+ metadata.gz: b3156dbd4113a50c8c48a5305813ddd290336478ab5ab64dccc94b084a9972bd11e403e4c064970f11196400bedb1b2569856f9ae284defecd840173cad5db62
7
+ data.tar.gz: 99715f24471a04a0d0126e1f750ea23d66e88dbef2d5d956e5ca1cb2574ee34673fdbc636aa784fdcd83e05d35805bb852ada89b813dcf69f45b307dbfd15855
data/README.md CHANGED
@@ -24,9 +24,9 @@ To enable this DHCP provider, edit `/etc/foreman-proxy/settings.d/dhcp.yml` and
24
24
  Configuration options for this plugin are in `/etc/foreman-proxy/settings.d/dhcp_infoblox.yml` and include:
25
25
 
26
26
  * username: API Username
27
- * passowrd: API Password
27
+ * password: API Password
28
28
  * record_type: host / fixedaddress (see different record types chapter)
29
- * use_range: use infoblox ranges (true) or infoblox networks (false) to find the next free ip in your infoblox
29
+ * use_ranges: use infoblox ranges (true) or infoblox networks (false) to find the next free ip in your infoblox
30
30
 
31
31
  ## Different record types
32
32
  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.
@@ -8,10 +8,13 @@
8
8
  :username: "infoblox"
9
9
  :password: "infoblox"
10
10
  #
11
- # Record type to manage: can be "host" or "fixed_address"
11
+ # Record type to manage: can be "host" or "fixedaddress"
12
12
  #
13
13
  :record_type: 'host'
14
14
  #
15
15
  # Use pre-definded ranges in networks to find available IP's
16
16
  #
17
17
  :use_ranges: false
18
+
19
+ #:dns_view: 'non-default'
20
+ #:network_view: 'another-non-default'
@@ -7,13 +7,14 @@ module Proxy::DHCP::Infoblox
7
7
  include Proxy::Util
8
8
  include IpAddressArithmetic
9
9
 
10
- attr_reader :connection, :crud, :restart_grid, :unused_ips
10
+ attr_reader :connection, :crud, :restart_grid, :unused_ips, :network_view
11
11
 
12
- def initialize(connection, crud, restart_grid, unused_ips, managed_subnets)
12
+ def initialize(connection, crud, restart_grid, unused_ips, managed_subnets, network_view)
13
13
  @connection = connection
14
14
  @crud = crud
15
15
  @restart_grid = restart_grid
16
16
  @unused_ips = unused_ips
17
+ @network_view = network_view
17
18
  super('infoblox', managed_subnets, nil)
18
19
  end
19
20
 
@@ -76,7 +77,8 @@ module Proxy::DHCP::Infoblox
76
77
  end
77
78
 
78
79
  def find_network(network_address)
79
- network = ::Infoblox::Network.find(connection, 'network~' => network_address, '_max_results' => 1).first
80
+ network = ::Infoblox::Network.find(connection, 'network' => network_address, 'network_view' => network_view,
81
+ '_max_results' => 1).first
80
82
  raise "Subnet #{network_address} not found" if network.nil?
81
83
  network
82
84
  end
@@ -2,7 +2,7 @@ module Proxy::DHCP::Infoblox
2
2
  class Plugin < ::Proxy::Provider
3
3
  plugin :dhcp_infoblox, ::Proxy::DHCP::Infoblox::VERSION
4
4
 
5
- default_settings :record_type => 'host', :range => false
5
+ default_settings :record_type => 'host', :range => false, :dns_view => "default", :network_view => "default"
6
6
  validate_presence :username, :password
7
7
 
8
8
  requires :dhcp, '>= 1.13'
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module DHCP
3
3
  module Infoblox
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
6
6
  end
7
7
  end
@@ -2,14 +2,18 @@ require 'smart_proxy_dhcp_infoblox/common_crud'
2
2
 
3
3
  module ::Proxy::DHCP::Infoblox
4
4
  class FixedAddressCRUD < CommonCRUD
5
- def initialize(connection)
5
+ attr_reader :network_view
6
+
7
+ def initialize(connection, network_view)
6
8
  @memoized_hosts = []
7
9
  @memoized_condition = nil
8
- super
10
+ @network_view = network_view
11
+ super(connection)
9
12
  end
10
13
 
11
14
  def all_hosts(subnet_address)
12
- network = ::Infoblox::Fixedaddress.find(@connection, 'network' => subnet_address, '_max_results' => 2147483646) #2**(32-cidr_to_i(subnet_address)))
15
+ network = ::Infoblox::Fixedaddress.find(@connection, 'network' => subnet_address, 'network_view' => network_view,
16
+ '_max_results' => 2147483646) #2**(32-cidr_to_i(subnet_address)))
13
17
  network.map {|h| build_reservation(h.name, h, subnet_address)}.compact
14
18
  end
15
19
 
@@ -32,9 +36,10 @@ module ::Proxy::DHCP::Infoblox
32
36
  end
33
37
 
34
38
  def find_hosts(condition, max_results = 1)
35
- return @memoized_hosts if (!@memoized_hosts.empty? && @memoized_condition == condition)
39
+ return @memoized_hosts if (!@memoized_hosts.empty? && @memoized_condition = condition)
36
40
  @memoized_condition = condition
37
- @memoized_hosts = ::Infoblox::Fixedaddress.find(@connection, condition.merge('_max_results' => max_results))
41
+ @memoized_hosts = ::Infoblox::Fixedaddress.find(@connection, condition.merge('_max_results' => max_results,
42
+ 'network_view' => network_view))
38
43
  end
39
44
 
40
45
  def find_host_and_name_by_ip(ip_address)
@@ -51,6 +56,7 @@ module ::Proxy::DHCP::Infoblox
51
56
  host.use_nextserver = true
52
57
  host.bootfile = options[:filename]
53
58
  host.use_bootfile = true
59
+ host.network_view = network_view
54
60
  host
55
61
  end
56
62
  end
@@ -3,10 +3,13 @@ require 'smart_proxy_dhcp_infoblox/network_address_range_regex_generator'
3
3
 
4
4
  module ::Proxy::DHCP::Infoblox
5
5
  class HostIpv4AddressCRUD < CommonCRUD
6
- def initialize(connection)
6
+ attr_reader :dns_view
7
+
8
+ def initialize(connection, dns_view)
7
9
  @memoized_hosts = []
8
10
  @memoized_condition = nil
9
- super
11
+ @dns_view = dns_view
12
+ super(connection)
10
13
  end
11
14
 
12
15
  def all_hosts(subnet_address)
@@ -15,6 +18,7 @@ module ::Proxy::DHCP::Infoblox
15
18
  hosts = ::Infoblox::Host.find(
16
19
  @connection,
17
20
  'ipv4addr~' => address_range_regex,
21
+ 'view' => dns_view,
18
22
  '_max_results' => 2147483646)
19
23
 
20
24
  ip_addr_matcher = Regexp.new(address_range_regex) # pre-compile the regex
@@ -47,7 +51,8 @@ module ::Proxy::DHCP::Infoblox
47
51
  def find_hosts(condition, max_results = 1)
48
52
  return @memoized_hosts if (!@memoized_hosts.empty? && @memoized_condition == condition)
49
53
  @memoized_condition = condition
50
- @memoized_hosts = ::Infoblox::Host.find(@connection, condition.merge('_max_results' => max_results))
54
+ @memoized_hosts = ::Infoblox::Host.find(@connection, condition.merge('view' => dns_view,
55
+ '_max_results' => max_results))
51
56
  end
52
57
 
53
58
  def build_host(options)
@@ -60,6 +65,7 @@ module ::Proxy::DHCP::Infoblox
60
65
  host_addr.use_nextserver = true
61
66
  host_addr.bootfile = options[:filename]
62
67
  host_addr.use_bootfile = true
68
+ host.view = dns_view
63
69
  host
64
70
  end
65
71
  end
@@ -20,9 +20,16 @@ module Proxy::DHCP::Infoblox
20
20
  end)
21
21
 
22
22
 
23
- c.dependency :unused_ips, lambda { ::Proxy::DHCP::Infoblox::UnusedIps.new(c.get_dependency(:connection), settings[:use_ranges])}
24
- c.dependency :host_ipv4_crud, lambda { ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(c.get_dependency(:connection))}
25
- c.dependency :fixed_address_crud, lambda { ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(c.get_dependency(:connection))}
23
+ c.dependency :unused_ips, (lambda do
24
+ ::Proxy::DHCP::Infoblox::UnusedIps.new(c.get_dependency(:connection), settings[:use_ranges],
25
+ settings[:network_view])
26
+ end)
27
+ c.dependency :host_ipv4_crud, (lambda do
28
+ ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(c.get_dependency(:connection), settings[:dns_view])
29
+ end)
30
+ c.dependency :fixed_address_crud, (lambda do
31
+ ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(c.get_dependency(:connection), settings[:network_view])
32
+ end)
26
33
  c.dependency :grid_restart, lambda { ::Proxy::DHCP::Infoblox::GridRestart.new(c.get_dependency(:connection))}
27
34
  c.dependency :dhcp_provider, (lambda do
28
35
  ::Proxy::DHCP::Infoblox::Provider.new(
@@ -30,8 +37,10 @@ module Proxy::DHCP::Infoblox
30
37
  settings[:record_type] == 'host' ? c.get_dependency(:host_ipv4_crud) : c.get_dependency(:fixed_address_crud),
31
38
  c.get_dependency(:grid_restart),
32
39
  c.get_dependency(:unused_ips),
33
- settings[:subnets])
40
+ settings[:subnets],
41
+ settings[:network_view])
34
42
  end)
35
43
  end
36
44
  end
37
45
  end
46
+
@@ -4,12 +4,13 @@ require 'smart_proxy_dhcp_infoblox/ip_address_arithmetic'
4
4
  module Proxy::DHCP::Infoblox
5
5
  class UnusedIps
6
6
  include IpAddressArithmetic
7
- attr_reader :connection, :use_ranges
7
+ attr_reader :connection, :use_ranges, :network_view
8
8
 
9
- def initialize(connection, use_ranges)
9
+ def initialize(connection, use_ranges, network_view)
10
10
  @connection = connection
11
11
  @use_ranges = use_ranges
12
12
  @memoized_network = nil
13
+ @network_view = network_view
13
14
  end
14
15
 
15
16
  def unused_ip(network_address, from_ip_address, to_ip_address)
@@ -31,7 +32,7 @@ module Proxy::DHCP::Infoblox
31
32
  end
32
33
 
33
34
  def find_range(network_address, from, to)
34
- ranges = ::Infoblox::Range.find(@connection, 'network~' => network_address)
35
+ ranges = ::Infoblox::Range.find(@connection, 'network' => network_address, 'network_view' => network_view)
35
36
  range = (from.nil? || to.nil?) ? ranges.first : ranges.find {|r| r.start_addr == from && r.end_addr == to}
36
37
  raise "No Ranges found for #{network_address} network" if range.nil?
37
38
  range
@@ -40,7 +41,8 @@ module Proxy::DHCP::Infoblox
40
41
  def find_network(network_address)
41
42
  return @memoized_network if !@memoized_network.nil? && @memoized_address == network_address
42
43
  @memoized_address = network_address
43
- @memoized_network = ::Infoblox::Network.find(@connection, 'network~' => network_address, '_max_results' => 1).first
44
+ @memoized_network = ::Infoblox::Network.find(@connection, 'network' => network_address, 'network_view' => network_view,
45
+ '_max_results' => 1).first
44
46
  raise "Subnet #{network_address} not found" if @memoized_network.nil?
45
47
  @memoized_network
46
48
  end
@@ -7,27 +7,27 @@ require 'smart_proxy_dhcp_infoblox/host_ipv4_address_crud'
7
7
 
8
8
  module CommoncrudTests
9
9
  def test_find_record_using_ip
10
- @entity.expects(:find).with(@connection, 'ipv4addr' => '192.168.42.1', '_max_results' => 1).returns([@host])
10
+ @entity.expects(:find).with(@connection, search_condition('ipv4addr' => '192.168.42.1', '_max_results' => 1)).returns([@host])
11
11
  assert_equal @reservation, @crud.find_record_by_ip('192.168.42.0/24', '192.168.42.1')
12
12
  end
13
13
 
14
14
  def test_find_record_using_ip_returns_nil_if_record_not_found
15
- @entity.expects(:find).with(@connection, 'ipv4addr' => '192.168.42.1', '_max_results' => 1).returns([])
15
+ @entity.expects(:find).with(@connection, search_condition('ipv4addr' => '192.168.42.1', '_max_results' => 1)).returns([])
16
16
  assert_nil @crud.find_record_by_ip('192.168.42.0/24', '192.168.42.1')
17
17
  end
18
18
 
19
19
  def test_find_records_using_ip_returns_empty_arrays_if_records_not_found
20
- @entity.expects(:find).with(@connection, 'ipv4addr' => '192.168.42.1', '_max_results' => 2147483646).returns([])
20
+ @entity.expects(:find).with(@connection, search_condition('ipv4addr' => '192.168.42.1', '_max_results' => 2147483646)).returns([])
21
21
  assert @crud.find_records_by_ip('192.168.42.0/24', '192.168.42.1').empty?
22
22
  end
23
23
 
24
24
  def test_find_record_using_mac
25
- @entity.expects(:find).with(@connection, 'mac' => '00:01:02:03:05:06', '_max_results' => 1).returns([@host])
25
+ @entity.expects(:find).with(@connection, search_condition('mac' => '00:01:02:03:05:06', '_max_results' => 1)).returns([@host])
26
26
  assert_equal @reservation, @crud.find_record_by_mac('192.168.42.0/24', '00:01:02:03:05:06')
27
27
  end
28
28
 
29
29
  def test_find_record_using_mac_returns_nil_if_record_not_found
30
- @entity.expects(:find).with(@connection, 'mac' => '00:01:02:03:05:06', '_max_results' => 1).returns([])
30
+ @entity.expects(:find).with(@connection, search_condition('mac' => '00:01:02:03:05:06', '_max_results' => 1)).returns([])
31
31
  assert_nil @crud.find_record_by_mac('192.168.42.0/24', '00:01:02:03:05:06')
32
32
  end
33
33
 
@@ -81,7 +81,8 @@ class HostCrudTest < Test::Unit::TestCase
81
81
 
82
82
  def setup
83
83
  @connection = Object.new
84
- @crud = ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(@connection)
84
+ @view = "something"
85
+ @crud = ::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(@connection, @view)
85
86
 
86
87
  @entity = ::Infoblox::Host
87
88
 
@@ -94,10 +95,12 @@ class HostCrudTest < Test::Unit::TestCase
94
95
 
95
96
  @host = ::Infoblox::Host.new(
96
97
  :name => @hostname,
98
+ :view => @view,
97
99
  :ipv4addrs => [{:ipv4addr => @ip, :mac => @mac, :nextserver => @nextserver, :use_nextserver => true,
98
100
  :bootfile => @filename, :use_bootfile => true, :configure_for_dhcp => true}])
99
101
  @host1 = ::Infoblox::Host.new(
100
102
  :name => 'another.test.com',
103
+ :view => @view,
101
104
  :ipv4addrs => [{:ipv4addr => @ip, :mac => '00:01:02:03:05:07', :nextserver => @nextserver, :use_nextserver => true,
102
105
  :bootfile => @filename, :use_bootfile => true, :configure_for_dhcp => true}])
103
106
 
@@ -107,7 +110,8 @@ class HostCrudTest < Test::Unit::TestCase
107
110
  end
108
111
 
109
112
  def test_all_hosts
110
- ::Infoblox::Host.expects(:find).with(@connection, 'ipv4addr~' => '192\.168\.42\..+', '_max_results' => 2147483646).returns([@host])
113
+ ::Infoblox::Host.expects(:find).with(@connection, 'ipv4addr~' => '192\.168\.42\..+', 'view' => @view,
114
+ '_max_results' => 2147483646).returns([@host])
111
115
  assert_equal @reservation, @crud.all_hosts('192.168.42.0/24').first
112
116
  end
113
117
 
@@ -128,22 +132,28 @@ class HostCrudTest < Test::Unit::TestCase
128
132
  assert_equal expected_addr.bootfile, actual_addr.bootfile
129
133
  assert actual_addr.use_bootfile
130
134
  assert actual_addr.configure_for_dhcp
135
+ assert_equal @view, built.view
131
136
  end
132
137
 
133
138
  def test_add_record_with_collision
134
139
  @crud.expects(:build_host).with(:ip => @ip, :mac => @mac, :hostname => @hostname).returns(@host)
135
140
  @host.expects(:post).raises(Infoblox::Error.new("IB.Data.Conflict"))
136
141
  @crud.expects(:find_hosts).with('ipv4addr' => @ip).returns(
137
- [::Infoblox::Host.new(:name => @hostname, :ipv4addrs => [{:ipv4addr => @ip, :mac => '11:22:33:44:55:66', :configure_for_dhcp => true}])])
142
+ [::Infoblox::Host.new(:name => @hostname, :ipv4addrs => [{:ipv4addr => @ip, :mac => '11:22:33:44:55:66"', :configure_for_dhcp => true}])])
138
143
 
139
144
  assert_raises(Proxy::DHCP::Collision) { @crud.add_record(:ip => @ip, :mac => @mac, :hostname => @hostname) }
140
145
  end
146
+
147
+ def search_condition(a_hash)
148
+ {'view' => @view}.merge(a_hash)
149
+ end
141
150
  end
142
151
 
143
152
  class FixedaddressCrudTest < Test::Unit::TestCase
144
153
  def setup
145
154
  @connection = Object.new
146
- @crud = ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(@connection)
155
+ @network_view = "something"
156
+ @crud = ::Proxy::DHCP::Infoblox::FixedAddressCRUD.new(@connection, @network_view)
147
157
 
148
158
  @entity = ::Infoblox::Fixedaddress
149
159
 
@@ -156,17 +166,18 @@ class FixedaddressCrudTest < Test::Unit::TestCase
156
166
 
157
167
  @host = ::Infoblox::Fixedaddress.new(
158
168
  :name => @hostname,
159
- :ipv4addr => @ip, :mac => @mac) # :ipv4addr => @ip, :mac => @mac) #
169
+ :ipv4addr => @ip, :mac => @mac, :network_view => @network_view)
160
170
  @host1 = ::Infoblox::Fixedaddress.new(
161
171
  :name => 'another.test.com',
162
- :ipv4addr => @ip, :mac => '00:01:02:03:05:07')
172
+ :ipv4addr => @ip, :mac => '00:01:02:03:05:07', :network_view => @network_view)
163
173
 
164
174
  @reservation = ::Proxy::DHCP::Reservation.new(@hostname, @ip, @mac, ::Proxy::DHCP::Subnet.new(@subnet_ip, '255.255.255.0'),
165
175
  :deleteable => true, :hostname => @hostname)
166
176
  end
167
177
 
168
178
  def test_all_hosts
169
- ::Infoblox::Fixedaddress.expects(:find).with(@connection, 'network' => '192.168.42.0/24', '_max_results' => 2147483646).returns([@host])
179
+ ::Infoblox::Fixedaddress.expects(:find).with(@connection, 'network' => '192.168.42.0/24', 'network_view' => @network_view,
180
+ '_max_results' => 2147483646).returns([@host])
170
181
  assert_equal @reservation, @crud.all_hosts('192.168.42.0/24').first
171
182
  end
172
183
 
@@ -181,14 +192,20 @@ class FixedaddressCrudTest < Test::Unit::TestCase
181
192
  assert built.use_nextserver
182
193
  assert_equal @filename, built.bootfile
183
194
  assert built.use_bootfile
195
+ assert_equal @network_view, built.network_view
184
196
  end
185
197
 
186
198
  def test_add_record_with_collision
187
199
  @crud.expects(:build_host).with(:ip => @ip, :mac => @mac, :hostname => @hostname).returns(@host)
188
200
  @host.expects(:post).raises(Infoblox::Error.new("IB.Data.Conflict"))
189
201
  @crud.expects(:find_hosts).with('ipv4addr' => @ip).returns(
190
- [::Infoblox::Fixedaddress.new(:name => @hostname, :ipv4addr => @ip, :mac => '11:22:33:44:55:66')])
202
+ [::Infoblox::Fixedaddress.new(:name => @hostname, :ipv4addr => @ip, :mac => '11:22:33:44:55:66',
203
+ :network_view => @network_view)])
191
204
 
192
205
  assert_raises(Proxy::DHCP::Collision) { @crud.add_record(:ip => @ip, :mac => @mac, :hostname => @hostname) }
193
206
  end
207
+
208
+ def search_condition(a_hash)
209
+ {'network_view' => @network_view}.merge(a_hash)
210
+ end
194
211
  end
@@ -11,13 +11,15 @@ class InfobloxProviderTest < Test::Unit::TestCase
11
11
  @restart_grid = Object.new
12
12
  @unused_ips = Object.new
13
13
  @managed_subnets = nil
14
+ @network_view = "another"
14
15
 
15
16
  @network = Infoblox::Network.new(:network => '192.168.42.0/24')
16
17
  @subnet = ::Proxy::DHCP::Subnet.new('192.168.42.0', '255.255.255.0')
17
18
 
18
19
 
19
20
  @network_2 = Infoblox::Network.new(:network => '192.168.43.0/24')
20
- @provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid, @unused_ips, @managed_subnets)
21
+ @provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
22
+ @unused_ips, @managed_subnets, @network_view)
21
23
  end
22
24
 
23
25
  def test_subnets
@@ -26,18 +28,21 @@ class InfobloxProviderTest < Test::Unit::TestCase
26
28
  end
27
29
 
28
30
  def test_subnets_returns_managed_subnets_only
29
- provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid, @unused_ips, ['192.168.42.0/255.255.255.0'])
31
+ provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
32
+ @unused_ips, ['192.168.42.0/255.255.255.0'], @network_view)
30
33
  Infoblox::Network.expects(:all).with(@connection).returns([@network, @network_2])
31
34
  assert_equal [@subnet], provider.subnets
32
35
  end
33
36
 
34
37
  def test_find_subnet
35
- ::Infoblox::Network.expects(:find).with(@connection, 'network~' => '192.168.42.0', '_max_results' => 1).returns([@network])
38
+ ::Infoblox::Network.expects(:find).with(@connection, 'network' => '192.168.42.0',
39
+ '_max_results' => 1, 'network_view' => @network_view).returns([@network])
36
40
  assert_equal @network, @provider.find_network('192.168.42.0')
37
41
  end
38
42
 
39
43
  def test_find_subnet_raises_exception_when_network_not_found
40
- ::Infoblox::Network.expects(:find).with(@connection, 'network~' => '192.168.42.0', '_max_results' => 1).returns([])
44
+ ::Infoblox::Network.expects(:find).with(@connection, 'network' => '192.168.42.0',
45
+ 'network_view' => @network_view, '_max_results' => 1).returns([])
41
46
  assert_raises(RuntimeError) { @provider.find_network('192.168.42.0') }
42
47
  end
43
48
 
@@ -12,14 +12,18 @@ require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_main'
12
12
 
13
13
  class PluginDefaultConfigurationTest < Test::Unit::TestCase
14
14
  def test_default_settings
15
- assert_equal({:record_type => 'host', :range => false}, Proxy::DHCP::Infoblox::Plugin.default_settings)
15
+ assert_equal({:record_type => 'host', :range => false, :dns_view => "default", :network_view => "default"},
16
+ Proxy::DHCP::Infoblox::Plugin.default_settings)
16
17
  end
17
18
  end
18
19
 
19
20
  class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
20
21
  def setup
22
+ @network_view = "network_view"
23
+ @dns_view = "dns_view"
21
24
  @settings = {:username => 'user', :password => 'password', :server => '127.0.0.1', :record_type => 'host',
22
- :use_ranges => true, :subnets => ['1.1.1.0/255.255.255.0']}
25
+ :use_ranges => true, :subnets => ['1.1.1.0/255.255.255.0'],
26
+ :dns_view => @dns_view, :network_view => @network_view}
23
27
  @container = ::Proxy::DependencyInjection::Container.new
24
28
  Proxy::DHCP::Infoblox::PluginConfiguration.new.load_dependency_injection_wirings(@container, @settings)
25
29
  end
@@ -36,16 +40,19 @@ class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
36
40
  free_ips = @container.get_dependency(:unused_ips)
37
41
  assert_not_nil free_ips.connection
38
42
  assert free_ips.use_ranges
43
+ assert_equal @network_view, free_ips.network_view
39
44
  end
40
45
 
41
46
  def test_host_ipv4_crud_configuration
42
47
  host = @container.get_dependency(:host_ipv4_crud)
43
48
  assert_not_nil host.connection
49
+ assert_equal @dns_view, host.dns_view
44
50
  end
45
51
 
46
52
  def test_fixed_address_crud_configuration
47
53
  fixed_address = @container.get_dependency(:fixed_address_crud)
48
54
  assert_not_nil fixed_address.connection
55
+ assert_equal @network_view, fixed_address.network_view
49
56
  end
50
57
 
51
58
  def test_grid_restart_configuration
@@ -58,6 +65,7 @@ class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
58
65
  assert_not_nil provider.connection
59
66
  assert_not_nil provider.restart_grid
60
67
  assert_not_nil provider.unused_ips
68
+ assert_equal @network_view, provider.network_view
61
69
  assert provider.managed_subnets.include?('1.1.1.0/255.255.255.0')
62
70
  assert provider.crud.instance_of?(::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD)
63
71
  end
@@ -5,7 +5,8 @@ require 'smart_proxy_dhcp_infoblox/unused_ips'
5
5
  class UnusedIpTest < Test::Unit::TestCase
6
6
  def setup
7
7
  @connection = Object.new
8
- @unused_ips = ::Proxy::DHCP::Infoblox::UnusedIps.new(@connection, false)
8
+ @network_view = "another"
9
+ @unused_ips = ::Proxy::DHCP::Infoblox::UnusedIps.new(@connection, false, @network_view)
9
10
  @network = Infoblox::Network.new(:network => '1.1.1.0/24')
10
11
  @range = Infoblox::Range.new(:start_addr => '1.1.1.0', :end_addr => '1.1.1.253')
11
12
  end
@@ -23,25 +24,26 @@ class UnusedIpTest < Test::Unit::TestCase
23
24
  end
24
25
 
25
26
  def test_unused_network_ip
26
- ::Infoblox::Network.expects(:find).with(@connection, 'network~' => '1.1.1.0', '_max_results' => 1).returns([@network])
27
+ ::Infoblox::Network.expects(:find).with(@connection, 'network' => '1.1.1.0',
28
+ '_max_results' => 1, 'network_view' => @network_view).returns([@network])
27
29
  @network.expects(:next_available_ip).with(1, ['1.1.1.254', '1.1.1.255']).returns(['1.1.1.1'])
28
30
  assert_equal '1.1.1.1', @unused_ips.unused_network_ip('1.1.1.0', '1.1.1.0', '1.1.1.253')
29
31
  end
30
32
 
31
33
  def test_unused_range_ip
32
- ::Infoblox::Range.expects(:find).with(@connection, 'network~' => '1.1.1.0').returns([@range])
34
+ ::Infoblox::Range.expects(:find).with(@connection, 'network' => '1.1.1.0', 'network_view' => @network_view).returns([@range])
33
35
  @range.expects(:next_available_ip).with(1).returns(['1.1.1.1'])
34
36
  assert_equal '1.1.1.1', @unused_ips.unused_range_ip('1.1.1.0', '1.1.1.0', '1.1.1.253')
35
37
  end
36
38
 
37
39
  def test_unused_ip_uses_network_api_when_use_ranges_is_false
38
- unused_ips = ::Proxy::DHCP::Infoblox::UnusedIps.new(@connection, false)
40
+ unused_ips = ::Proxy::DHCP::Infoblox::UnusedIps.new(@connection, false, @network_view)
39
41
  unused_ips.expects(:unused_network_ip).with('1.1.1.0', '1.1.1.0', '1.1.1.253')
40
42
  unused_ips.unused_ip('1.1.1.0', '1.1.1.0', '1.1.1.253')
41
43
  end
42
44
 
43
45
  def test_unused_ip_uses_range_api_when_use_ranges_is_true
44
- unused_ips = ::Proxy::DHCP::Infoblox::UnusedIps.new(@connection, true)
46
+ unused_ips = ::Proxy::DHCP::Infoblox::UnusedIps.new(@connection, true, @network_view)
45
47
  unused_ips.expects(:unused_range_ip).with('1.1.1.0', '1.1.1.0', '1.1.1.253')
46
48
  unused_ips.unused_ip('1.1.1.0', '1.1.1.0', '1.1.1.253')
47
49
  end
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.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaas Demter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Infoblox DHCP provider plugin for Foreman's smart proxy
14
14
  email:
@@ -51,17 +51,17 @@ require_paths:
51
51
  - lib
52
52
  required_ruby_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
63
  rubyforge_project:
64
- rubygems_version: 2.4.8
64
+ rubygems_version: 2.6.12
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Infoblox DHCP provider plugin for Foreman's smart proxy