smart_proxy_dhcp_bluecat 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- 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 +0,0 @@
|
|
1
|
-
require 'dhcp_common/server'
|
2
|
-
|
3
|
-
module Proxy::DHCP::BlueCat
|
4
|
-
class Provider < ::Proxy::DHCP::Server
|
5
|
-
include Proxy::Log
|
6
|
-
include Proxy::Util
|
7
|
-
|
8
|
-
attr_reader :connection
|
9
|
-
def initialize(connection, managed_subnets)
|
10
|
-
@connection = connection
|
11
|
-
@managed_subnets = managed_subnets
|
12
|
-
super('bluecat', managed_subnets, nil)
|
13
|
-
end
|
14
|
-
|
15
|
-
def subnets
|
16
|
-
logger.debug('START subnets')
|
17
|
-
subnets = @connection.get_subnets
|
18
|
-
logger.debug('END subnets')
|
19
|
-
logger.debug('Returned: ' + subnets.class.to_s + ': ' + subnets.to_s)
|
20
|
-
subnets
|
21
|
-
end
|
22
|
-
|
23
|
-
def all_hosts(network_address)
|
24
|
-
logger.debug('START all_hosts with network_address: ' + network_address.to_s)
|
25
|
-
hosts = @connection.get_hosts(network_address)
|
26
|
-
logger.debug('END all_hosts with network_address: ' + network_address.to_s)
|
27
|
-
logger.debug('Returned: ' + hosts.class.to_s + ': ' + hosts.to_s)
|
28
|
-
hosts
|
29
|
-
end
|
30
|
-
|
31
|
-
def all_leases(network_address)
|
32
|
-
logger.debug('START all_leases with network_address: ' + network_address.to_s)
|
33
|
-
hosts = @connection.get_hosts(network_address)
|
34
|
-
logger.debug('END all_leases with network_address: ' + network_address.to_s)
|
35
|
-
logger.debug('Returned: ' + hosts.class.to_s + ': ' + hosts.to_s)
|
36
|
-
hosts
|
37
|
-
end
|
38
|
-
|
39
|
-
def unused_ip(subnet, mac_address, from_ip_address, to_ip_address)
|
40
|
-
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)
|
41
|
-
ip = @connection.get_next_ip(subnet, from_ip_address, to_ip_address)
|
42
|
-
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)
|
43
|
-
logger.debug('Returned: ' + ip.class.to_s + ': ' + ip.to_s)
|
44
|
-
ip
|
45
|
-
end
|
46
|
-
|
47
|
-
def find_record(subnet_address, address)
|
48
|
-
logger.debug('START find_record with subnet_address: ' + subnet_address.to_s + ' address: ' + address.to_s)
|
49
|
-
records = if IPAddress.valid?(address)
|
50
|
-
find_records_by_ip(subnet_address, address)
|
51
|
-
else
|
52
|
-
find_record_by_mac(subnet_address, address)
|
53
|
-
end
|
54
|
-
logger.debug('END find_record with subnet_address: ' + subnet_address.to_s + ' address: ' + address.to_s)
|
55
|
-
logger.debug('Returned: ' + records.class.to_s + ': ' + records.to_s)
|
56
|
-
return [] if records.nil?
|
57
|
-
records
|
58
|
-
end
|
59
|
-
|
60
|
-
def find_records_by_ip(subnet_address, ip)
|
61
|
-
logger.debug('START find_records_by_ip with subnet_address: ' + subnet_address.to_s + ' ip: ' + ip.to_s)
|
62
|
-
records = @connection.get_hosts_by_ip(ip)
|
63
|
-
logger.debug('END find_records_by_ip with subnet_address: ' + subnet_address.to_s + ' ip: ' + ip.to_s)
|
64
|
-
logger.debug('Returned: ' + records.class.to_s + ': ' + records.to_s)
|
65
|
-
return [] if records.nil?
|
66
|
-
records
|
67
|
-
end
|
68
|
-
|
69
|
-
def find_record_by_mac(subnet_address, mac_address)
|
70
|
-
logger.debug('START find_record_by_mac with subnet_address: ' + subnet_address.to_s + ' mac_address: ' + mac_address.to_s)
|
71
|
-
record = @connection.get_host_by_mac(mac_address)
|
72
|
-
logger.debug('END find_record_by_mac with subnet_address: ' + subnet_address.to_s + ' mac_address: ' + mac_address.to_s)
|
73
|
-
logger.debug('Returned: ' + record.class.to_s + ': ' + record.to_s)
|
74
|
-
record
|
75
|
-
end
|
76
|
-
|
77
|
-
def find_subnet(subnet_address)
|
78
|
-
logger.debug('START find_subnet with subnet_address: ' + subnet_address.to_s)
|
79
|
-
net = @connection.find_mysubnet(subnet_address)
|
80
|
-
logger.debug('END find_subnet with subnet_address: ' + subnet_address.to_s)
|
81
|
-
logger.debug('Returned: ' + net.class.to_s + ': ' + net.to_s)
|
82
|
-
net
|
83
|
-
end
|
84
|
-
|
85
|
-
def get_subnet(subnet_address)
|
86
|
-
logger.debug('START get_subnet with subnet_address: ' + subnet_address.to_s)
|
87
|
-
net = @connection.find_mysubnet(subnet_address)
|
88
|
-
logger.debug('END get_subnet with subnet_address: ' + subnet_address.to_s)
|
89
|
-
logger.debug('Returned: ' + net.class.to_s + ': ' + net.to_s)
|
90
|
-
net
|
91
|
-
end
|
92
|
-
|
93
|
-
def add_record(options)
|
94
|
-
logger.debug('START add_record with options: ' + options.to_s)
|
95
|
-
@connection.add_host(options)
|
96
|
-
logger.debug('END add_record with options: ' + options.to_s)
|
97
|
-
end
|
98
|
-
|
99
|
-
def del_record(record)
|
100
|
-
logger.debug('START del_record with record: ' + record.to_s)
|
101
|
-
if record.empty?
|
102
|
-
logger.debug('record empty, nothing to do')
|
103
|
-
else
|
104
|
-
@connection.remove_host(record.ip)
|
105
|
-
end
|
106
|
-
logger.debug('END del_record with record: ' + record.to_s)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Proxy::DHCP::BlueCat
|
2
|
-
class Plugin < ::Proxy::Provider
|
3
|
-
plugin :dhcp_bluecat, ::Proxy::DHCP::BlueCat::VERSION
|
4
|
-
|
5
|
-
validate_presence :scheme, :verify, :host, :parent_block, :view_name, :config_id, :config_name, :server_id, :username, :password
|
6
|
-
|
7
|
-
requires :dhcp, '>= 1.16'
|
8
|
-
|
9
|
-
load_classes ::Proxy::DHCP::BlueCat::PluginConfiguration
|
10
|
-
load_dependency_injection_wirings ::Proxy::DHCP::BlueCat::PluginConfiguration
|
11
|
-
|
12
|
-
load_validators scheme_validator: ::Proxy::DHCP::BlueCat::SchemeValidator,
|
13
|
-
verify_validator: ::Proxy::DHCP::BlueCat::VerifyValidator,
|
14
|
-
host_validator: ::Proxy::DHCP::BlueCat::HostValidator,
|
15
|
-
parent_block_validator: ::Proxy::DHCP::BlueCat::ParentBlockValidator,
|
16
|
-
view_name_validator: ::Proxy::DHCP::BlueCat::ViewNameValidator,
|
17
|
-
config_id_validator: ::Proxy::DHCP::BlueCat::ConfigIdValidator,
|
18
|
-
config_name_validator: ::Proxy::DHCP::BlueCat::ConfigNameValidator,
|
19
|
-
server_id_validator: ::Proxy::DHCP::BlueCat::ServerIdValidator,
|
20
|
-
username_validator: ::Proxy::DHCP::BlueCat::UsernameValidator,
|
21
|
-
password_validator: ::Proxy::DHCP::BlueCat::PasswordValidator
|
22
|
-
|
23
|
-
validate :scheme, scheme_validator: true
|
24
|
-
validate :verify, verify_validator: true
|
25
|
-
validate :host, host_validator: true
|
26
|
-
validate :parent_block, parent_block_validator: true
|
27
|
-
validate :view_name, view_name_validator: true
|
28
|
-
validate :config_id, config_id_validator: true
|
29
|
-
validate :config_name, config_name_validator: true
|
30
|
-
validate :server_id, server_id_validator: true
|
31
|
-
validate :username, username_validator: true
|
32
|
-
validate :password, password_validator: true
|
33
|
-
end
|
34
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Proxy::DHCP::BlueCat
|
2
|
-
class PluginConfiguration
|
3
|
-
def load_classes
|
4
|
-
require 'dhcp_common/dhcp_common'
|
5
|
-
require 'smart_proxy_dhcp_bluecat/bluecat_api'
|
6
|
-
require 'smart_proxy_dhcp_bluecat/dhcp_bluecat_main'
|
7
|
-
end
|
8
|
-
|
9
|
-
def load_dependency_injection_wirings(c, settings)
|
10
|
-
c.dependency :connection, (lambda do
|
11
|
-
BlueCat.new(
|
12
|
-
settings[:scheme],
|
13
|
-
settings[:verify],
|
14
|
-
settings[:host],
|
15
|
-
settings[:parent_block],
|
16
|
-
settings[:view_name],
|
17
|
-
settings[:config_name],
|
18
|
-
settings[:config_id],
|
19
|
-
settings[:server_id],
|
20
|
-
settings[:username],
|
21
|
-
settings[:password]
|
22
|
-
)
|
23
|
-
end)
|
24
|
-
|
25
|
-
c.dependency :dhcp_provider, (lambda do
|
26
|
-
::Proxy::DHCP::BlueCat::Provider.new(
|
27
|
-
c.get_dependency(:connection),
|
28
|
-
settings[:subnets]
|
29
|
-
)
|
30
|
-
end)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module ::Proxy::DHCP::BlueCat
|
2
|
-
class SchemeValidator < ::Proxy::PluginValidators::Base
|
3
|
-
def validate!(settings)
|
4
|
-
return true if ['http', 'https'].include?(settings[:scheme])
|
5
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'scheme' can be set to either 'http' or 'https'"
|
6
|
-
end
|
7
|
-
end
|
8
|
-
class VerifyValidator < ::Proxy::PluginValidators::Base
|
9
|
-
def validate!(settings)
|
10
|
-
return true if [true, false].include?(settings[:verify])
|
11
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'verify' can be set to either 'true' or 'false' (bool)"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
class HostValidator < ::Proxy::PluginValidators::Base
|
15
|
-
def validate!(settings)
|
16
|
-
return true if ['http', 'https'].include?(settings[:scheme])
|
17
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'scheme' can be set to either 'http' or 'https'"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
class ParentBlockValidator < ::Proxy::PluginValidators::Base
|
21
|
-
def validate!(settings)
|
22
|
-
return true if settings[:parent_block].is_a?(Integer)
|
23
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'parent_block' must be (integer)"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
class ViewNameValidator < ::Proxy::PluginValidators::Base
|
27
|
-
def validate!(settings)
|
28
|
-
return true if settings[:view_name].is_a?(String)
|
29
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'view_name' must be (string)"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
class ConfigIdValidator < ::Proxy::PluginValidators::Base
|
33
|
-
def validate!(settings)
|
34
|
-
return true if settings[:config_id].is_a?(Integer)
|
35
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'parent_block' must be (integer)"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
class ConfigNameValidator < ::Proxy::PluginValidators::Base
|
39
|
-
def validate!(settings)
|
40
|
-
return true if settings[:config_name].is_a?(String)
|
41
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'config_name' must be (string)"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
class ServerIdValidator < ::Proxy::PluginValidators::Base
|
45
|
-
def validate!(settings)
|
46
|
-
return true if settings[:server_id].is_a?(Integer)
|
47
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'server_id' must be (integer)"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
class UsernameValidator < ::Proxy::PluginValidators::Base
|
51
|
-
def validate!(settings)
|
52
|
-
return true if settings[:username].is_a?(String)
|
53
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'username' must be (string)"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
class PasswordValidator < ::Proxy::PluginValidators::Base
|
57
|
-
def validate!(settings)
|
58
|
-
return true if settings[:password].is_a?(String)
|
59
|
-
raise ::Proxy::Error::ConfigurationError, "Setting 'password' must be (string)"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|