smart_proxy_dhcp_infoblox 0.0.14 → 0.0.15

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: ed4af7f2889b7259c13b0ed75d551ae139812fd086e56c40b724bddfaa46cf78
4
- data.tar.gz: 7b1716d0ac19d220f26389221fe04793d14a34b4002a1a2c8e531a18e6b0d6a9
3
+ metadata.gz: c031d153855f68611243ce742482f2c3e0274ad9187dc638cb4f691b3d687448
4
+ data.tar.gz: 330d031ca651443261dd0df8921577f4c545e2aba97018d42953b71178ed1aae
5
5
  SHA512:
6
- metadata.gz: 82d8cb3847b9cd9b801a3ce16cee9fb113122fba6e662a10da0f576a7ad6951b6b09d5b1a73a5cb5eedec60f722ecaa7a7089f4e2e2247fbbcbe4b3e525f4352
7
- data.tar.gz: e56a98657864b67315907210d27b8c286386ce1dd62bdb78d3a4b0d8595cafb61fc534d7f4083322b530d129aad42b5e8f4cdd5ffc22758bbe3a9838fe14bde6
6
+ metadata.gz: a694d48389e3da2154b4d2d6b1ecca186c2e8e8b91d146c4641b06bd7b1f6912c0679979f362a68b63ec9205b570fd71959f916be109036c9721eb36801b1bab
7
+ data.tar.gz: 324fe4540b931eedb3c913c52b5bb17a02968646d43abf324a5bd34030199632157750e13618046fbd68fd7c64887fcbbac1657b72d00a3e81fc6443defe56e8
@@ -1,15 +1,24 @@
1
1
  ---
2
- #
3
2
  # Configuration file for 'dhcp_infoblox' dhcp provider
4
3
  #
5
- # use :server setting in dhcp.yml if you are managing a dhcp server which is not localhost
6
- # use :subnets setting in dhcp.yml if you want to restrict subnets available to smart-proxy
7
- #
8
- :username: "infoblox"
4
+ # Use :server setting in dhcp.yml if you are managing a dhcp server which is not localhost.
5
+ # Use :subnets setting in dhcp.yml if you want to restrict subnets available to smart-proxy.
6
+
7
+ # Credentials for Infoblox API, make sure the DHCP Role is assigned
8
+ :username: "admin"
9
9
  :password: "infoblox"
10
- #
11
- # Record type to manage: can be "host" or "fixedaddress"
12
- #
13
- :record_type: 'host'
14
- #:dns_view: 'non-default'
15
- #:network_view: 'another-non-default'
10
+
11
+ # Record type to manage: can be "host" or "fixedaddress". The latter is recommended as
12
+ # "host" setting will cause conflicts when using Infoblox DNS smart proxy plugin. When
13
+ # using "host" setting make sure domain exists in Infoblox.
14
+ :record_type: 'fixedaddress'
15
+
16
+ # View used for fixedaddress record type.
17
+ #:network_view: 'default'
18
+
19
+ # View used for host record type, usually 'default.myview' for custom names.
20
+ #:dns_view: 'default'
21
+
22
+ # Number of seconds to wait after successful Grid restart (make sure to increase Foreman and CLI timeouts).
23
+ # Set to 0 to disable the delay.
24
+ #:wait_after_restart: 10
@@ -1,5 +1,6 @@
1
1
  require 'resolv'
2
2
  require 'smart_proxy_dhcp_infoblox/ip_address_arithmetic'
3
+ require 'smart_proxy_dhcp_infoblox/network_address_range_regex_generator'
3
4
  require "proxy/validations"
4
5
 
5
6
  module ::Proxy::DHCP::Infoblox
@@ -13,8 +14,20 @@ module ::Proxy::DHCP::Infoblox
13
14
  @connection = connection
14
15
  end
15
16
 
16
- def all_leases(network_address)
17
- [] # infoblox doesn't support leases
17
+ def all_leases(network_address, subnet)
18
+ address_range_regex = NetworkAddressesRegularExpressionGenerator.new.generate_regex(network_address)
19
+ ::Infoblox::Lease.find(@connection, 'address~' => address_range_regex).map do |lease|
20
+ Proxy::DHCP::Lease.new(
21
+ lease.client_hostname,
22
+ lease.address,
23
+ lease.hardware,
24
+ subnet,
25
+ lease.starts,
26
+ lease.ends,
27
+ lease.binding_state,
28
+ :hostname => lease.client_hostname
29
+ )
30
+ end
18
31
  end
19
32
 
20
33
  def find_record(subnet_address, an_address)
@@ -32,7 +32,7 @@ module Proxy::DHCP::Infoblox
32
32
  end
33
33
 
34
34
  def all_leases(network_address)
35
- crud.all_leases(full_network_address(network_address))
35
+ crud.all_leases(full_network_address(network_address), find_subnet(network_address))
36
36
  end
37
37
 
38
38
  def find_record(subnet_address, an_address)
@@ -92,7 +92,7 @@ module Proxy::DHCP::Infoblox
92
92
  def find_network(network_address)
93
93
  network = ::Infoblox::Network.find(connection, 'network' => network_address, 'network_view' => network_view,
94
94
  '_max_results' => 1).first
95
- raise "Subnet #{network_address} not found" if network.nil?
95
+ raise "Subnet #{network_address} not found in network view #{network_view}" if network.nil?
96
96
  network
97
97
  end
98
98
 
@@ -2,7 +2,12 @@ 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', :dns_view => "default", :network_view => "default", :blacklist_duration_minutes => 30 * 60
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
+
6
11
  validate_presence :username, :password
7
12
 
8
13
  requires :dhcp, '>= 1.13'
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module DHCP
3
3
  module Infoblox
4
- VERSION = '0.0.14'.freeze
4
+ VERSION = '0.0.15'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  module ::Proxy::DHCP::Infoblox
2
2
  class GridRestart
3
- MAX_ATTEMPTS = 3
3
+ MAX_ATTEMPTS = 5
4
4
 
5
5
  include ::Proxy::Log
6
6
  attr_reader :connection
@@ -10,21 +10,32 @@ module ::Proxy::DHCP::Infoblox
10
10
  end
11
11
 
12
12
  def try_restart
13
- logger.debug 'Restarting grid.'
13
+ logger.info 'Restarting Infoblox Grid'
14
14
 
15
+ delay = Proxy::DHCP::Infoblox::Plugin.settings.wait_after_restart.to_i
15
16
  MAX_ATTEMPTS.times do |tries|
17
+ if restart
18
+ if delay > 0
19
+ logger.info "Starting post-restart delay of #{delay} seconds..."
20
+ sleep delay
21
+ logger.debug "Post-restart delay done"
22
+ end
23
+ return
24
+ end
16
25
  sleep tries
17
- return if restart
18
26
  end
19
27
 
20
- logger.info 'Restarting Grid failed.'
28
+ logger.warn 'Restarting Infoblox Grid failed, giving up'
21
29
  false
22
30
  end
23
31
 
32
+ private
33
+
24
34
  def restart
25
35
  (@grid ||= ::Infoblox::Grid.get(@connection).first).restartservices
26
36
  true
27
37
  rescue Exception => e
38
+ logger.warn "Error during Grid restart: #{e}"
28
39
  false
29
40
  end
30
41
  end
@@ -16,9 +16,49 @@ class InfobloxProviderTest < Test::Unit::TestCase
16
16
  @network = Infoblox::Network.new(:network => '192.168.42.0/24')
17
17
  @subnet = ::Proxy::DHCP::Subnet.new('192.168.42.0', '255.255.255.0')
18
18
 
19
- @network_2 = Infoblox::Network.new(:network => '192.168.43.0/24')
19
+ @network_2 = Infoblox::Network.new(:network => '192.168.32.0/19')
20
+ @subnet_2 = ::Proxy::DHCP::Subnet.new('192.168.32.0', '255.255.224.0')
21
+
22
+ @network_3 = Infoblox::Network.new(:network => '192.168.43.0/24')
23
+
24
+ @provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
25
+ @unused_ips, @managed_subnets, @network_view)
26
+
27
+ @lease = Infoblox::Lease.new(:address => '192.168.43.127',
28
+ :binding_state => 'active',
29
+ :client_hostname => 'example',
30
+ :hardware => 'ba:be:fa:ce:ca:fe',
31
+ :network => @subnet.network,
32
+ :starts => nil,
33
+ :ends => nil)
34
+
35
+ @lease_2 = Infoblox::Lease.new(:address => '192.168.60.121',
36
+ :binding_state => 'active',
37
+ :client_hostname => 'example',
38
+ :hardware => 'c0:fe:fe:f0:01:bb',
39
+ :network => @subnet_2.network,
40
+ :starts => nil,
41
+ :ends => nil)
42
+ end
43
+
44
+ def test_leases
45
+ @crud = ::Proxy::DHCP::Infoblox::CommonCRUD.new(@connection)
20
46
  @provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
21
47
  @unused_ips, @managed_subnets, @network_view)
48
+
49
+ @provider.expects(:full_network_address).with(@subnet.network).returns(@network.network)
50
+ Infoblox::Lease.expects(:find).with(@connection, 'address~' => "192\\.168\\.42\\..+").returns([@lease])
51
+ assert_equal @lease.hardware, @provider.all_leases(@subnet.network).first.mac
52
+ end
53
+
54
+ def test_nonclass_leases
55
+ @crud = ::Proxy::DHCP::Infoblox::CommonCRUD.new(@connection)
56
+ @provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
57
+ @unused_ips, @managed_subnets, @network_view)
58
+
59
+ @provider.expects(:full_network_address).with(@subnet_2.network).returns(@network_2.network)
60
+ Infoblox::Lease.expects(:find).with(@connection, 'address~' => "192\\.168\\.(0?3[3456789]|0?[45][0123456789]|0?6[012])\\..+").returns([@lease_2])
61
+ assert_equal @lease_2.hardware, @provider.all_leases(@subnet_2.network).first.mac
22
62
  end
23
63
 
24
64
  def test_subnets
@@ -29,7 +69,7 @@ class InfobloxProviderTest < Test::Unit::TestCase
29
69
  def test_subnets_returns_managed_subnets_only
30
70
  provider = Proxy::DHCP::Infoblox::Provider.new(@connection, @crud, @restart_grid,
31
71
  @unused_ips, ['192.168.42.0/255.255.255.0'], @network_view)
32
- Infoblox::Network.expects(:all).with(@connection).returns([@network, @network_2])
72
+ Infoblox::Network.expects(:all).with(@connection).returns([@network, @network_3])
33
73
  assert_equal [@subnet], provider.subnets
34
74
  end
35
75
 
@@ -12,7 +12,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', :blacklist_duration_minutes => 30 * 60, :dns_view => "default", :network_view => "default" },
15
+ assert_equal({ :record_type => 'fixedaddress',
16
+ :blacklist_duration_minutes => 30 * 60,
17
+ :wait_after_restart => 10,
18
+ :dns_view => "default",
19
+ :network_view => "default" },
16
20
  Proxy::DHCP::Infoblox::Plugin.default_settings)
17
21
  end
18
22
  end
@@ -21,8 +25,8 @@ class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
21
25
  def setup
22
26
  @network_view = "network_view"
23
27
  @dns_view = "dns_view"
24
- @settings = { :username => 'user', :password => 'password', :server => '127.0.0.1', :record_type => 'host',
25
- :subnets => ['1.1.1.0/255.255.255.0'], :blacklist_duration_minutes => 300,
28
+ @settings = { :username => 'user', :password => 'password', :server => '127.0.0.1', :record_type => 'fixedaddress',
29
+ :subnets => ['1.1.1.0/255.255.255.0'], :blacklist_duration_minutes => 300, :wait_after_restart => 1,
26
30
  :dns_view => @dns_view, :network_view => @network_view }
27
31
  @container = ::Proxy::DependencyInjection::Container.new
28
32
  Proxy::DHCP::Infoblox::PluginConfiguration.new.load_dependency_injection_wirings(@container, @settings)
@@ -66,7 +70,7 @@ class InfobloxDhcpProductionWiringTest < Test::Unit::TestCase
66
70
  assert_not_nil provider.free_ips
67
71
  assert_equal @network_view, provider.network_view
68
72
  assert provider.managed_subnets.include?('1.1.1.0/255.255.255.0')
69
- assert provider.crud.instance_of?(::Proxy::DHCP::Infoblox::HostIpv4AddressCRUD)
73
+ assert provider.crud.instance_of?(::Proxy::DHCP::Infoblox::FixedAddressCRUD)
70
74
  end
71
75
 
72
76
  def test_provider_configuration_with_fixedaddress_crud
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.14
4
+ version: 0.0.15
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-12-12 00:00:00.000000000 Z
11
+ date: 2019-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: infoblox
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.0.4
19
+ version: '3.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '2.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.0.4
26
+ version: '3.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rubocop
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,17 +88,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
88
  - !ruby/object:Gem::Version
95
89
  version: '0'
96
90
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.7.6
91
+ rubygems_version: 3.0.3
99
92
  signing_key:
100
93
  specification_version: 4
101
94
  summary: Infoblox DHCP provider plugin for Foreman's smart proxy
102
95
  test_files:
103
- - test/record_type_validator_test.rb
104
- - test/regex_generator_test.rb
105
96
  - test/test_helper.rb
97
+ - test/infoblox_provider_test.rb
98
+ - test/plugin_configuration_test.rb
99
+ - test/record_type_validator_test.rb
106
100
  - test/unused_ip_test.rb
107
101
  - test/host_and_fixedaddress_crud_test.rb
102
+ - test/regex_generator_test.rb
108
103
  - test/integration_test.rb
109
- - test/plugin_configuration_test.rb
110
- - test/infoblox_provider_test.rb