smart_proxy_dhcp_bluecat 0.1.0 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/LICENSE +673 -673
- data/README.md +47 -47
- data/bundler.d/dhcp_bluecat.rb +1 -1
- data/config/dhcp_bluecat.yml.example +35 -35
- data/lib/smart_proxy_dhcp_bluecat.rb +11 -11
- data/lib/smart_proxy_dhcp_bluecat/bluecat_api.rb +386 -345
- data/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_main.rb +128 -109
- data/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_plugin.rb +38 -34
- data/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_version.rb +1 -1
- data/lib/smart_proxy_dhcp_bluecat/module_loader.rb +12 -6
- data/lib/smart_proxy_dhcp_bluecat/plugin_configuration.rb +37 -33
- data/lib/smart_proxy_dhcp_bluecat/settings_validator.rb +66 -62
- metadata +18 -27
- data/lib/lib/smart_proxy_dhcp_bluecat.rb +0 -11
- data/lib/lib/smart_proxy_dhcp_bluecat/bluecat_api.rb +0 -345
- data/lib/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_main.rb +0 -109
- data/lib/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_plugin.rb +0 -34
- data/lib/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_version.rb +0 -7
- data/lib/lib/smart_proxy_dhcp_bluecat/module_loader.rb +0 -6
- data/lib/lib/smart_proxy_dhcp_bluecat/plugin_configuration.rb +0 -33
- data/lib/lib/smart_proxy_dhcp_bluecat/settings_validator.rb +0 -62
@@ -1,109 +1,128 @@
|
|
1
|
-
require 'dhcp_common/server'
|
2
|
-
|
3
|
-
module Proxy
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
1
|
+
require 'dhcp_common/server'
|
2
|
+
|
3
|
+
module Proxy
|
4
|
+
module DHCP
|
5
|
+
module BlueCat
|
6
|
+
# this class handles commuincation from foreman
|
7
|
+
class Provider < ::Proxy::DHCP::Server
|
8
|
+
include Proxy::Log
|
9
|
+
include Proxy::Util
|
10
|
+
|
11
|
+
attr_reader :connection
|
12
|
+
def initialize(connection, managed_subnets)
|
13
|
+
@connection = connection
|
14
|
+
@managed_subnets = managed_subnets
|
15
|
+
super('bluecat', managed_subnets, nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
# returns all subnets
|
19
|
+
def subnets
|
20
|
+
logger.debug('START subnets')
|
21
|
+
subnets = @connection.subnets
|
22
|
+
logger.debug('END subnets')
|
23
|
+
logger.debug('Returned: ' + subnets.class.to_s + ': ' + subnets.to_s)
|
24
|
+
subnets
|
25
|
+
end
|
26
|
+
|
27
|
+
# returns all hosts in a subnet
|
28
|
+
# in bluecat leases and hosts are the same
|
29
|
+
def all_hosts(network_address)
|
30
|
+
logger.debug('START all_hosts with network_address: ' + network_address.to_s)
|
31
|
+
hosts = @connection.hosts(network_address)
|
32
|
+
logger.debug('END all_hosts with network_address: ' + network_address.to_s)
|
33
|
+
logger.debug('Returned: ' + hosts.class.to_s + ': ' + hosts.to_s)
|
34
|
+
hosts
|
35
|
+
end
|
36
|
+
|
37
|
+
# returns all leases in a subnet
|
38
|
+
# in bluecat leases and hosts are the same
|
39
|
+
def all_leases(network_address)
|
40
|
+
logger.debug('START all_leases with network_address: ' + network_address.to_s)
|
41
|
+
hosts = @connection.hosts(network_address)
|
42
|
+
logger.debug('END all_leases with network_address: ' + network_address.to_s)
|
43
|
+
logger.debug('Returned: ' + hosts.class.to_s + ': ' + hosts.to_s)
|
44
|
+
hosts
|
45
|
+
end
|
46
|
+
|
47
|
+
# returns the next free ip in a subnet
|
48
|
+
def unused_ip(subnet, mac_address, from_ip_address, to_ip_address)
|
49
|
+
logger.debug('START unused_ip with subnet: ' + subnet.to_s + ' mac_address: ' + mac_address.to_s + ' from_ip_address: ' + from_ip_address.to_s + ' to_ip_address: ' + to_ip_address.to_s)
|
50
|
+
ip = @connection.next_ip(subnet, from_ip_address, to_ip_address)
|
51
|
+
logger.debug('END unused_ip with subnet: ' + subnet.to_s + ' mac_address: ' + mac_address.to_s + ' from_ip_address: ' + from_ip_address.to_s + ' to_ip_address: ' + to_ip_address.to_s)
|
52
|
+
logger.debug('Returned: ' + ip.class.to_s + ': ' + ip.to_s)
|
53
|
+
ip
|
54
|
+
end
|
55
|
+
|
56
|
+
# returns a record
|
57
|
+
# foreman calls this method with a ip or a mac address
|
58
|
+
def find_record(subnet_address, address)
|
59
|
+
logger.debug('START find_record with subnet_address: ' + subnet_address.to_s + ' address: ' + address.to_s)
|
60
|
+
records = if IPAddress.valid?(address)
|
61
|
+
find_records_by_ip(subnet_address, address)
|
62
|
+
else
|
63
|
+
find_record_by_mac(subnet_address, address)
|
64
|
+
end
|
65
|
+
logger.debug('END find_record with subnet_address: ' + subnet_address.to_s + ' address: ' + address.to_s)
|
66
|
+
logger.debug('Returned: ' + records.class.to_s + ': ' + records.to_s)
|
67
|
+
return [] if records.nil?
|
68
|
+
records
|
69
|
+
end
|
70
|
+
|
71
|
+
# returns a record based on a ip address
|
72
|
+
def find_records_by_ip(subnet_address, ip)
|
73
|
+
logger.debug('START find_records_by_ip with subnet_address: ' + subnet_address.to_s + ' ip: ' + ip.to_s)
|
74
|
+
records = @connection.hosts_by_ip(ip)
|
75
|
+
logger.debug('END find_records_by_ip with subnet_address: ' + subnet_address.to_s + ' ip: ' + ip.to_s)
|
76
|
+
logger.debug('Returned: ' + records.class.to_s + ': ' + records.to_s)
|
77
|
+
return [] if records.nil?
|
78
|
+
records
|
79
|
+
end
|
80
|
+
|
81
|
+
# returns a record based on a mac address
|
82
|
+
def find_record_by_mac(subnet_address, mac_address)
|
83
|
+
logger.debug('START find_record_by_mac with subnet_address: ' + subnet_address.to_s + ' mac_address: ' + mac_address.to_s)
|
84
|
+
record = @connection.host_by_mac(mac_address)
|
85
|
+
logger.debug('END find_record_by_mac with subnet_address: ' + subnet_address.to_s + ' mac_address: ' + mac_address.to_s)
|
86
|
+
logger.debug('Returned: ' + record.class.to_s + ': ' + record.to_s)
|
87
|
+
record
|
88
|
+
end
|
89
|
+
|
90
|
+
# returns a subnet based on a subnet address
|
91
|
+
def find_subnet(subnet_address)
|
92
|
+
logger.debug('START find_subnet with subnet_address: ' + subnet_address.to_s)
|
93
|
+
net = @connection.find_mysubnet(subnet_address)
|
94
|
+
logger.debug('END find_subnet with subnet_address: ' + subnet_address.to_s)
|
95
|
+
logger.debug('Returned: ' + net.class.to_s + ': ' + net.to_s)
|
96
|
+
net
|
97
|
+
end
|
98
|
+
|
99
|
+
# returns a subnet based on a subnet address
|
100
|
+
def get_subnet(subnet_address)
|
101
|
+
logger.debug('START get_subnet with subnet_address: ' + subnet_address.to_s)
|
102
|
+
net = @connection.find_mysubnet(subnet_address)
|
103
|
+
logger.debug('END get_subnet with subnet_address: ' + subnet_address.to_s)
|
104
|
+
logger.debug('Returned: ' + net.class.to_s + ': ' + net.to_s)
|
105
|
+
net
|
106
|
+
end
|
107
|
+
|
108
|
+
# adds a host record
|
109
|
+
def add_record(options)
|
110
|
+
logger.debug('START add_record with options: ' + options.to_s)
|
111
|
+
@connection.add_host(options)
|
112
|
+
logger.debug('END add_record with options: ' + options.to_s)
|
113
|
+
end
|
114
|
+
|
115
|
+
# removes a host record
|
116
|
+
def del_record(record)
|
117
|
+
logger.debug('START del_record with record: ' + record.to_s)
|
118
|
+
if record.empty?
|
119
|
+
logger.debug('record empty, nothing to do')
|
120
|
+
else
|
121
|
+
@connection.remove_host(record.ip)
|
122
|
+
end
|
123
|
+
logger.debug('END del_record with record: ' + record.to_s)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -1,34 +1,38 @@
|
|
1
|
-
module Proxy
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
1
|
+
module Proxy
|
2
|
+
module DHCP
|
3
|
+
module BlueCat
|
4
|
+
class Plugin < ::Proxy::Provider
|
5
|
+
plugin :dhcp_bluecat, ::Proxy::DHCP::BlueCat::VERSION
|
6
|
+
|
7
|
+
validate_presence :scheme, :verify, :host, :parent_block, :view_name, :config_id, :config_name, :server_id, :username, :password
|
8
|
+
|
9
|
+
requires :dhcp, '>= 1.16'
|
10
|
+
|
11
|
+
load_classes ::Proxy::DHCP::BlueCat::PluginConfiguration
|
12
|
+
load_dependency_injection_wirings ::Proxy::DHCP::BlueCat::PluginConfiguration
|
13
|
+
|
14
|
+
load_validators scheme_validator: ::Proxy::DHCP::BlueCat::SchemeValidator,
|
15
|
+
verify_validator: ::Proxy::DHCP::BlueCat::VerifyValidator,
|
16
|
+
host_validator: ::Proxy::DHCP::BlueCat::HostValidator,
|
17
|
+
parent_block_validator: ::Proxy::DHCP::BlueCat::ParentBlockValidator,
|
18
|
+
view_name_validator: ::Proxy::DHCP::BlueCat::ViewNameValidator,
|
19
|
+
config_id_validator: ::Proxy::DHCP::BlueCat::ConfigIdValidator,
|
20
|
+
config_name_validator: ::Proxy::DHCP::BlueCat::ConfigNameValidator,
|
21
|
+
server_id_validator: ::Proxy::DHCP::BlueCat::ServerIdValidator,
|
22
|
+
username_validator: ::Proxy::DHCP::BlueCat::UsernameValidator,
|
23
|
+
password_validator: ::Proxy::DHCP::BlueCat::PasswordValidator
|
24
|
+
|
25
|
+
validate :scheme, scheme_validator: true
|
26
|
+
validate :verify, verify_validator: true
|
27
|
+
validate :host, host_validator: true
|
28
|
+
validate :parent_block, parent_block_validator: true
|
29
|
+
validate :view_name, view_name_validator: true
|
30
|
+
validate :config_id, config_id_validator: true
|
31
|
+
validate :config_name, config_name_validator: true
|
32
|
+
validate :server_id, server_id_validator: true
|
33
|
+
validate :username, username_validator: true
|
34
|
+
validate :password, password_validator: true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,6 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Proxy
|
2
|
+
module DHCP
|
3
|
+
module BlueCat
|
4
|
+
class ModuleLoader < ::Proxy::DefaultModuleLoader
|
5
|
+
def log_provider_settings(settings)
|
6
|
+
super(settings)
|
7
|
+
logger.warn('http is used for connection to BlueCat address manager') if settings[:scheme] != 'https'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,33 +1,37 @@
|
|
1
|
-
module Proxy
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
1
|
+
module Proxy
|
2
|
+
module DHCP
|
3
|
+
module BlueCat
|
4
|
+
class PluginConfiguration
|
5
|
+
def load_classes
|
6
|
+
require 'dhcp_common/dhcp_common'
|
7
|
+
require 'smart_proxy_dhcp_bluecat/bluecat_api'
|
8
|
+
require 'smart_proxy_dhcp_bluecat/dhcp_bluecat_main'
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_dependency_injection_wirings(c, settings)
|
12
|
+
c.dependency :connection, (lambda do
|
13
|
+
::Proxy::DHCP::BlueCat::BlueCatAPI.new(
|
14
|
+
settings[:scheme],
|
15
|
+
settings[:verify],
|
16
|
+
settings[:host],
|
17
|
+
settings[:parent_block],
|
18
|
+
settings[:view_name],
|
19
|
+
settings[:config_name],
|
20
|
+
settings[:config_id],
|
21
|
+
settings[:server_id],
|
22
|
+
settings[:username],
|
23
|
+
settings[:password]
|
24
|
+
)
|
25
|
+
end)
|
26
|
+
|
27
|
+
c.dependency :dhcp_provider, (lambda do
|
28
|
+
::Proxy::DHCP::BlueCat::Provider.new(
|
29
|
+
c.get_dependency(:connection),
|
30
|
+
settings[:subnets]
|
31
|
+
)
|
32
|
+
end)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,62 +1,66 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
1
|
+
module Proxy
|
2
|
+
module DHCP
|
3
|
+
module BlueCat
|
4
|
+
class SchemeValidator < ::Proxy::PluginValidators::Base
|
5
|
+
def validate!(settings)
|
6
|
+
return true if ['http', 'https'].include?(settings[:scheme])
|
7
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'scheme' can be set to either 'http' or 'https'"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class VerifyValidator < ::Proxy::PluginValidators::Base
|
11
|
+
def validate!(settings)
|
12
|
+
return true if [true, false].include?(settings[:verify])
|
13
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'verify' can be set to either 'true' or 'false' (bool)"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
class HostValidator < ::Proxy::PluginValidators::Base
|
17
|
+
def validate!(settings)
|
18
|
+
return true if ['http', 'https'].include?(settings[:scheme])
|
19
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'scheme' can be set to either 'http' or 'https'"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
class ParentBlockValidator < ::Proxy::PluginValidators::Base
|
23
|
+
def validate!(settings)
|
24
|
+
return true if settings[:parent_block].is_a?(Integer)
|
25
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'parent_block' must be (integer)"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
class ViewNameValidator < ::Proxy::PluginValidators::Base
|
29
|
+
def validate!(settings)
|
30
|
+
return true if settings[:view_name].is_a?(String)
|
31
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'view_name' must be (string)"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
class ConfigIdValidator < ::Proxy::PluginValidators::Base
|
35
|
+
def validate!(settings)
|
36
|
+
return true if settings[:config_id].is_a?(Integer)
|
37
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'parent_block' must be (integer)"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
class ConfigNameValidator < ::Proxy::PluginValidators::Base
|
41
|
+
def validate!(settings)
|
42
|
+
return true if settings[:config_name].is_a?(String)
|
43
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'config_name' must be (string)"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
class ServerIdValidator < ::Proxy::PluginValidators::Base
|
47
|
+
def validate!(settings)
|
48
|
+
return true if settings[:server_id].is_a?(Integer)
|
49
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'server_id' must be (integer)"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
class UsernameValidator < ::Proxy::PluginValidators::Base
|
53
|
+
def validate!(settings)
|
54
|
+
return true if settings[:username].is_a?(String)
|
55
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'username' must be (string)"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
class PasswordValidator < ::Proxy::PluginValidators::Base
|
59
|
+
def validate!(settings)
|
60
|
+
return true if settings[:password].is_a?(String)
|
61
|
+
raise ::Proxy::Error::ConfigurationError, "Setting 'password' must be (string)"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|