smart_proxy_dhcp_infoblox 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/config/dhcp_infoblox.yml.example +0 -5
- data/lib/smart_proxy_dhcp_infoblox/dhcp_infoblox_main.rb +17 -5
- data/lib/smart_proxy_dhcp_infoblox/dhcp_infoblox_plugin.rb +1 -1
- data/lib/smart_proxy_dhcp_infoblox/dhcp_infoblox_version.rb +1 -1
- data/lib/smart_proxy_dhcp_infoblox/plugin_configuration.rb +3 -5
- data/test/integration_test.rb +97 -0
- data/test/plugin_configuration_test.rb +7 -8
- data/test/unused_ip_test.rb +38 -30
- metadata +4 -3
- data/lib/smart_proxy_dhcp_infoblox/unused_ips.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27302f51a2acaa0673c4b5f53552866d24ebb739
|
4
|
+
data.tar.gz: a92c72fdaea22d0395ef95e7f24f514e28e09b9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9c5e1be7b5d16517e9cc1135c022622b3899372da1061448c8e9f69862160e5c4cc77d9352ef7685573028cad57772cdb9368e280dc43f7f761555a9b88d76e
|
7
|
+
data.tar.gz: 4bb48cb0751a23e604035432883ad1d5b4d32cb00996bcfdde389a9d0e9e008a4d93bcab97a53066fb2e60a0092e1dbca0e53b7a1fede206e8b9695d878051c4
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# SmartProxyDhcpInfoblox
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/theforeman/smart_proxy_dhcp_infoblox.svg?branch=master)](https://travis-ci.org/theforeman/smart_proxy_dhcp_infoblox)
|
4
|
+
|
3
5
|
This plugin adds a new DHCP provider for managing records with infoblox servers
|
4
6
|
|
5
7
|
## Installation
|
@@ -26,7 +28,6 @@ Configuration options for this plugin are in `/etc/foreman-proxy/settings.d/dhcp
|
|
26
28
|
* username: API Username
|
27
29
|
* password: API Password
|
28
30
|
* record_type: host / fixedaddress (see different record types chapter)
|
29
|
-
* use_ranges: use infoblox ranges (true) or infoblox networks (false) to find the next free ip in your infoblox
|
30
31
|
|
31
32
|
## Different record types
|
32
33
|
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.
|
@@ -11,10 +11,5 @@
|
|
11
11
|
# Record type to manage: can be "host" or "fixedaddress"
|
12
12
|
#
|
13
13
|
:record_type: 'host'
|
14
|
-
#
|
15
|
-
# Use pre-definded ranges in networks to find available IP's
|
16
|
-
#
|
17
|
-
:use_ranges: false
|
18
|
-
|
19
14
|
#:dns_view: 'non-default'
|
20
15
|
#:network_view: 'another-non-default'
|
@@ -7,15 +7,14 @@ module Proxy::DHCP::Infoblox
|
|
7
7
|
include Proxy::Util
|
8
8
|
include IpAddressArithmetic
|
9
9
|
|
10
|
-
attr_reader :connection, :crud, :restart_grid, :
|
10
|
+
attr_reader :connection, :crud, :restart_grid, :network_view
|
11
11
|
|
12
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
|
-
@unused_ips = unused_ips
|
17
16
|
@network_view = network_view
|
18
|
-
super('infoblox', managed_subnets, nil)
|
17
|
+
super('infoblox', managed_subnets, nil, unused_ips)
|
19
18
|
end
|
20
19
|
|
21
20
|
def find_subnet(address);::Proxy::DHCP::Subnet.new(address, '255.255.255.0'); end
|
@@ -72,8 +71,21 @@ module Proxy::DHCP::Infoblox
|
|
72
71
|
restart_grid.try_restart
|
73
72
|
end
|
74
73
|
|
75
|
-
|
76
|
-
|
74
|
+
require 'dhcp_common/subnet'
|
75
|
+
def get_subnet(subnet_address)
|
76
|
+
address, prefix_length = full_network_address(subnet_address).split("/")
|
77
|
+
netmask = cidr_to_ip_mask(prefix_length.to_i)
|
78
|
+
end
|
79
|
+
|
80
|
+
def find_ip_by_mac_address_and_range(subnet, mac_address, from_address, to_address)
|
81
|
+
r = crud.find_record_by_mac("#{subnet.network}/#{subnet.cidr}", mac_address)
|
82
|
+
|
83
|
+
if r && (IPAddr.new(from_address)..IPAddr.new(to_address)).cover?(IPAddr.new(r.ip))
|
84
|
+
logger.debug "Found an existing DHCP record #{r}, reusing..."
|
85
|
+
return r.ip
|
86
|
+
end
|
87
|
+
|
88
|
+
nil
|
77
89
|
end
|
78
90
|
|
79
91
|
def find_network(network_address)
|
@@ -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', :
|
5
|
+
default_settings :record_type => 'host', :dns_view => "default", :network_view => "default", :blacklist_duration_minutes => 30*60
|
6
6
|
validate_presence :username, :password
|
7
7
|
|
8
8
|
requires :dhcp, '>= 1.13'
|
@@ -3,10 +3,10 @@ module Proxy::DHCP::Infoblox
|
|
3
3
|
def load_classes
|
4
4
|
require 'infoblox'
|
5
5
|
require 'dhcp_common/dhcp_common'
|
6
|
+
require 'dhcp_common/free_ips'
|
6
7
|
require 'smart_proxy_dhcp_infoblox/host_ipv4_address_crud'
|
7
8
|
require 'smart_proxy_dhcp_infoblox/fixed_address_crud'
|
8
9
|
require 'smart_proxy_dhcp_infoblox/grid_restart'
|
9
|
-
require 'smart_proxy_dhcp_infoblox/unused_ips'
|
10
10
|
require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_main'
|
11
11
|
end
|
12
12
|
|
@@ -20,10 +20,8 @@ module Proxy::DHCP::Infoblox
|
|
20
20
|
end)
|
21
21
|
|
22
22
|
|
23
|
-
c.
|
24
|
-
|
25
|
-
settings[:network_view])
|
26
|
-
end)
|
23
|
+
c.singleton_dependency :unused_ips, lambda {::Proxy::DHCP::FreeIps.new(settings[:blacklist_duration_minutes]) }
|
24
|
+
|
27
25
|
c.dependency :host_ipv4_crud, (lambda do
|
28
26
|
::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD.new(c.get_dependency(:connection), settings[:dns_view])
|
29
27
|
end)
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "rack/test"
|
2
|
+
require 'test_helper'
|
3
|
+
require 'json'
|
4
|
+
require 'dhcp_common/dhcp_common'
|
5
|
+
require 'dhcp/dhcp'
|
6
|
+
require 'dhcp/dependency_injection'
|
7
|
+
require 'dhcp/dhcp_api'
|
8
|
+
|
9
|
+
ENV['RACK_ENV'] = 'test'
|
10
|
+
|
11
|
+
class IntegrationTest < ::Test::Unit::TestCase
|
12
|
+
include Rack::Test::Methods
|
13
|
+
|
14
|
+
def app
|
15
|
+
app = Proxy::DhcpApi.new
|
16
|
+
app.helpers.server = @server
|
17
|
+
app
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@free_ips = ::Proxy::DHCP::FreeIps.new
|
22
|
+
@server = ::Proxy::DHCP::Infoblox::Provider.new(nil, Object.new, Object.new, @free_ips, [],
|
23
|
+
"default")
|
24
|
+
|
25
|
+
@expected_reservation = {"name" => "testing-01", "ip" => "10.0.0.200", "mac" => "11:22:33:a9:61:09",
|
26
|
+
"subnet" => "10.0.0.0/255.255.255.0", "hostname" => "testing-01"}
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def test_get_subnets
|
31
|
+
@server.expects(:subnets).returns([])
|
32
|
+
get "/"
|
33
|
+
assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_get_network
|
37
|
+
@server.expects(:all_hosts).with("10.0.0.0").returns([@expected_reservation])
|
38
|
+
@server.expects(:all_leases).with("10.0.0.0").returns([])
|
39
|
+
|
40
|
+
get "/10.0.0.0"
|
41
|
+
|
42
|
+
assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_get_unused_ip
|
46
|
+
@server.expects(:get_subnet).with("10.0.0.0").returns(::Proxy::DHCP::Subnet.new("10.0.0.0", "255.255.255.0"))
|
47
|
+
@server.expects(:all_hosts).with("10.0.0.0").returns([@expected_reservation])
|
48
|
+
@server.expects(:all_leases).with("10.0.0.0").returns([])
|
49
|
+
@free_ips.expects(:find_free_ip).with("10.0.0.100", "10.0.0.200", [@expected_reservation]).returns("10.0.0.150")
|
50
|
+
|
51
|
+
get "/10.0.0.0/unused_ip?from=10.0.0.100&to=10.0.0.200"
|
52
|
+
|
53
|
+
assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}"
|
54
|
+
parsed_response = JSON.parse(last_response.body)
|
55
|
+
assert parsed_response.key?('ip')
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_get_records_by_ip
|
59
|
+
@server.expects(:find_records_by_ip).with("10.0.0.0", "10.0.0.200").returns([@expected_reservation])
|
60
|
+
get "/10.0.0.0/ip/10.0.0.200"
|
61
|
+
assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}"
|
62
|
+
parsed_response = JSON.parse(last_response.body)
|
63
|
+
assert_equal 1, parsed_response.size
|
64
|
+
assert_equal @expected_reservation, parsed_response.first
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_get_record_by_mac
|
68
|
+
@server.expects(:find_record_by_mac).with("10.0.0.0", "11:22:33:a9:61:09").returns(@expected_reservation)
|
69
|
+
get "/10.0.0.0/mac/11:22:33:a9:61:09"
|
70
|
+
assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}"
|
71
|
+
assert_equal @expected_reservation, JSON.parse(last_response.body)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_create_record
|
75
|
+
record = {
|
76
|
+
"hostname" => "test-02",
|
77
|
+
"ip" => "10.0.0.250",
|
78
|
+
"mac" => "10:10:10:10:10:10",
|
79
|
+
"network" => "10.0.0.0",
|
80
|
+
}
|
81
|
+
@server.expects(:add_record).with(has_entries(record))
|
82
|
+
post "/10.0.0.0", record
|
83
|
+
assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_delete_records_by_ip
|
87
|
+
@server.expects(:del_records_by_ip).with("10.0.0.0", "10.0.0.200")
|
88
|
+
delete "/10.0.0.0/ip/10.0.0.200"
|
89
|
+
assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_delete_record_by_mac
|
93
|
+
@server.expects(:del_record_by_mac).with("10.0.0.0", "11:22:33:a9:61:09")
|
94
|
+
delete "/10.0.0.0/mac/11:22:33:a9:61:09"
|
95
|
+
assert last_response.ok?, "Last response was not ok: #{last_response.status} #{last_response.body}"
|
96
|
+
end
|
97
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'infoblox'
|
3
3
|
require 'dhcp_common/dhcp_common'
|
4
|
+
require 'dhcp_common/free_ips'
|
4
5
|
require 'smart_proxy_dhcp_infoblox/plugin_configuration'
|
5
6
|
require 'smart_proxy_dhcp_infoblox/record_type_validator'
|
6
7
|
require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_plugin'
|
7
8
|
require 'smart_proxy_dhcp_infoblox/host_ipv4_address_crud'
|
8
9
|
require 'smart_proxy_dhcp_infoblox/fixed_address_crud'
|
9
10
|
require 'smart_proxy_dhcp_infoblox/grid_restart'
|
10
|
-
require 'smart_proxy_dhcp_infoblox/unused_ips'
|
11
11
|
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', :
|
15
|
+
assert_equal({:record_type => 'host', :blacklist_duration_minutes => 30*60, :dns_view => "default", :network_view => "default"},
|
16
16
|
Proxy::DHCP::Infoblox::Plugin.default_settings)
|
17
17
|
end
|
18
18
|
end
|
@@ -22,7 +22,7 @@ class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
|
|
22
22
|
@network_view = "network_view"
|
23
23
|
@dns_view = "dns_view"
|
24
24
|
@settings = {:username => 'user', :password => 'password', :server => '127.0.0.1', :record_type => 'host',
|
25
|
-
:
|
25
|
+
:subnets => ['1.1.1.0/255.255.255.0'], :blacklist_duration_minutes => 300,
|
26
26
|
:dns_view => @dns_view, :network_view => @network_view}
|
27
27
|
@container = ::Proxy::DependencyInjection::Container.new
|
28
28
|
Proxy::DHCP::Infoblox::PluginConfiguration.new.load_dependency_injection_wirings(@container, @settings)
|
@@ -37,10 +37,9 @@ class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_unused_ips_configuration
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
assert_equal @network_view, free_ips.network_view
|
40
|
+
unused_ips = @container.get_dependency(:unused_ips)
|
41
|
+
assert unused_ips
|
42
|
+
assert_equal 300, unused_ips.blacklist_interval
|
44
43
|
end
|
45
44
|
|
46
45
|
def test_host_ipv4_crud_configuration
|
@@ -64,7 +63,7 @@ class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
|
|
64
63
|
provider = @container.get_dependency(:dhcp_provider)
|
65
64
|
assert_not_nil provider.connection
|
66
65
|
assert_not_nil provider.restart_grid
|
67
|
-
assert_not_nil provider.
|
66
|
+
assert_not_nil provider.free_ips
|
68
67
|
assert_equal @network_view, provider.network_view
|
69
68
|
assert provider.managed_subnets.include?('1.1.1.0/255.255.255.0')
|
70
69
|
assert provider.crud.instance_of?(::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD)
|
data/test/unused_ip_test.rb
CHANGED
@@ -1,50 +1,58 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'infoblox'
|
3
|
-
require '
|
3
|
+
require 'dhcp_common/free_ips'
|
4
|
+
require 'smart_proxy_dhcp_infoblox/dhcp_infoblox_main'
|
5
|
+
require 'ostruct'
|
4
6
|
|
5
7
|
class UnusedIpTest < Test::Unit::TestCase
|
6
8
|
def setup
|
7
9
|
@connection = Object.new
|
10
|
+
@crud = Object.new
|
11
|
+
@restart_grid = Object.new
|
12
|
+
@managed_subnets = nil
|
8
13
|
@network_view = "another"
|
9
|
-
@unused_ips = ::Proxy::DHCP::
|
14
|
+
@unused_ips = ::Proxy::DHCP::FreeIps.new
|
10
15
|
@network = Infoblox::Network.new(:network => '1.1.1.0/24')
|
11
|
-
@
|
16
|
+
@provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
|
17
|
+
@unused_ips, @managed_subnets, @network_view)
|
12
18
|
end
|
13
19
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
20
|
+
def test_unused_network_ip
|
21
|
+
expected_ip = '1.1.1.1'
|
22
|
+
@provider.expects(:get_subnet).with('1.1.0.0').returns(::Proxy::DHCP::Subnet.new('1.1.0.0', '255.255.0.0'))
|
23
|
+
@provider.expects(:all_hosts).with('1.1.0.0').returns([host = Object.new])
|
24
|
+
@provider.expects(:all_leases).with('1.1.0.0').returns([lease = Object.new])
|
25
|
+
@unused_ips.expects(:find_free_ip).with('1.1.0.1', '1.1.255.254', [host, lease]).returns(expected_ip)
|
17
26
|
|
18
|
-
|
19
|
-
assert @unused_ips.excluded_ips('192.168.42.0/24', nil, '192.168.42.253').empty?
|
20
|
-
end
|
27
|
+
ip = @provider.unused_ip('1.1.0.0', nil, nil, nil)
|
21
28
|
|
22
|
-
|
23
|
-
assert @unused_ips.excluded_ips('192.168.42.0/24', '192.168.42.250', nil).empty?
|
29
|
+
assert_equal expected_ip, ip
|
24
30
|
end
|
25
31
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
@
|
30
|
-
|
31
|
-
end
|
32
|
+
def test_unused_network_ip_with_mac_address_present
|
33
|
+
expected_ip = '1.1.1.1'
|
34
|
+
mac_address = '00:01:02:03:04:05'
|
35
|
+
@provider.expects(:get_subnet).with('1.1.0.0').returns(subnet = ::Proxy::DHCP::Subnet.new('1.1.0.0', '255.255.0.0'))
|
36
|
+
@provider.expects(:find_ip_by_mac_address_and_range).with(subnet, mac_address, '1.1.0.1', '1.1.255.254').returns(expected_ip)
|
32
37
|
|
33
|
-
|
34
|
-
::Infoblox::Range.expects(:find).with(@connection, 'network' => '1.1.1.0', 'network_view' => @network_view).returns([@range])
|
35
|
-
@range.expects(:next_available_ip).with(1).returns(['1.1.1.1'])
|
36
|
-
assert_equal '1.1.1.1', @unused_ips.unused_range_ip('1.1.1.0', '1.1.1.0', '1.1.1.253')
|
37
|
-
end
|
38
|
+
ip = @provider.unused_ip('1.1.0.0', mac_address, nil, nil)
|
38
39
|
|
39
|
-
|
40
|
-
unused_ips = ::Proxy::DHCP::Infoblox::UnusedIps.new(@connection, false, @network_view)
|
41
|
-
unused_ips.expects(:unused_network_ip).with('1.1.1.0', '1.1.1.0', '1.1.1.253')
|
42
|
-
unused_ips.unused_ip('1.1.1.0', '1.1.1.0', '1.1.1.253')
|
40
|
+
assert_equal expected_ip, ip
|
43
41
|
end
|
44
42
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
def test_unused_network_ip_with_mac_address_present_with_address_outside_range
|
44
|
+
expected_ip = '1.1.1.1'
|
45
|
+
start_range = '1.1.10.1'
|
46
|
+
end_range = '1.1.100.1'
|
47
|
+
mac_address = '00:01:02:03:04:05'
|
48
|
+
@provider.expects(:get_subnet).with('1.1.0.0').returns(subnet = ::Proxy::DHCP::Subnet.new('1.1.0.0', '255.255.0.0'))
|
49
|
+
@crud.expects(:find_record_by_mac).with('1.1.0.0/16', mac_address).returns(OpenStruct.new(:ip => '10.0.0.1'))
|
50
|
+
@provider.expects(:all_hosts).with('1.1.0.0').returns([host = Object.new])
|
51
|
+
@provider.expects(:all_leases).with('1.1.0.0').returns([lease = Object.new])
|
52
|
+
@unused_ips.expects(:find_free_ip).with(start_range, end_range, [host, lease]).returns(expected_ip)
|
53
|
+
|
54
|
+
ip = @provider.unused_ip('1.1.0.0', mac_address, start_range, end_range)
|
55
|
+
|
56
|
+
assert_equal expected_ip, ip
|
49
57
|
end
|
50
58
|
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.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Klaas Demter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: infoblox
|
@@ -53,9 +53,9 @@ files:
|
|
53
53
|
- lib/smart_proxy_dhcp_infoblox/network_address_range_regex_generator.rb
|
54
54
|
- lib/smart_proxy_dhcp_infoblox/plugin_configuration.rb
|
55
55
|
- lib/smart_proxy_dhcp_infoblox/record_type_validator.rb
|
56
|
-
- lib/smart_proxy_dhcp_infoblox/unused_ips.rb
|
57
56
|
- test/host_and_fixedaddress_crud_test.rb
|
58
57
|
- test/infoblox_provider_test.rb
|
58
|
+
- test/integration_test.rb
|
59
59
|
- test/plugin_configuration_test.rb
|
60
60
|
- test/record_type_validator_test.rb
|
61
61
|
- test/regex_generator_test.rb
|
@@ -86,6 +86,7 @@ signing_key:
|
|
86
86
|
specification_version: 4
|
87
87
|
summary: Infoblox DHCP provider plugin for Foreman's smart proxy
|
88
88
|
test_files:
|
89
|
+
- test/integration_test.rb
|
89
90
|
- test/infoblox_provider_test.rb
|
90
91
|
- test/plugin_configuration_test.rb
|
91
92
|
- test/regex_generator_test.rb
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'ipaddr'
|
2
|
-
require 'smart_proxy_dhcp_infoblox/ip_address_arithmetic'
|
3
|
-
|
4
|
-
module Proxy::DHCP::Infoblox
|
5
|
-
class UnusedIps
|
6
|
-
include IpAddressArithmetic
|
7
|
-
attr_reader :connection, :use_ranges, :network_view
|
8
|
-
|
9
|
-
def initialize(connection, use_ranges, network_view)
|
10
|
-
@connection = connection
|
11
|
-
@use_ranges = use_ranges
|
12
|
-
@memoized_network = nil
|
13
|
-
@network_view = network_view
|
14
|
-
end
|
15
|
-
|
16
|
-
def unused_ip(network_address, from_ip_address, to_ip_address)
|
17
|
-
@use_ranges ? unused_range_ip(network_address, from_ip_address, to_ip_address) : unused_network_ip(network_address, from_ip_address, to_ip_address)
|
18
|
-
end
|
19
|
-
|
20
|
-
def unused_network_ip(network_address, from_ip_address, to_ip_address)
|
21
|
-
find_network(network_address).next_available_ip(1, excluded_ips(find_network(network_address).network, from_ip_address, to_ip_address)).first
|
22
|
-
end
|
23
|
-
|
24
|
-
def unused_range_ip(network_address, from_ip_address, to_ip_address)
|
25
|
-
find_range(network_address, from_ip_address, to_ip_address).next_available_ip(1).first
|
26
|
-
end
|
27
|
-
|
28
|
-
def excluded_ips(subnet_address, from, to)
|
29
|
-
return [] if from.nil? || to.nil?
|
30
|
-
(IPAddr.new(network_cidr_to_range(subnet_address).first)..IPAddr.new(network_cidr_to_range(subnet_address).last)).to_a.map(&:to_s) -
|
31
|
-
(IPAddr.new(from)..IPAddr.new(to)).to_a.map(&:to_s)
|
32
|
-
end
|
33
|
-
|
34
|
-
def find_range(network_address, from, to)
|
35
|
-
ranges = ::Infoblox::Range.find(@connection, 'network' => network_address, 'network_view' => network_view)
|
36
|
-
range = (from.nil? || to.nil?) ? ranges.first : ranges.find {|r| r.start_addr == from && r.end_addr == to}
|
37
|
-
raise "No Ranges found for #{network_address} network" if range.nil?
|
38
|
-
range
|
39
|
-
end
|
40
|
-
|
41
|
-
def find_network(network_address)
|
42
|
-
return @memoized_network if !@memoized_network.nil? && @memoized_address == network_address
|
43
|
-
@memoized_address = network_address
|
44
|
-
@memoized_network = ::Infoblox::Network.find(@connection, 'network' => network_address, 'network_view' => network_view,
|
45
|
-
'_max_results' => 1).first
|
46
|
-
raise "Subnet #{network_address} not found" if @memoized_network.nil?
|
47
|
-
@memoized_network
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|