smart_proxy_dhcp_bluecat 0.1.0
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 +7 -0
- data/LICENSE +674 -0
- data/README.md +47 -0
- data/bundler.d/dhcp_bluecat.rb +1 -0
- data/config/dhcp_bluecat.yml.example +35 -0
- data/lib/lib/smart_proxy_dhcp_bluecat.rb +11 -0
- data/lib/lib/smart_proxy_dhcp_bluecat/bluecat_api.rb +345 -0
- data/lib/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_main.rb +109 -0
- data/lib/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_plugin.rb +34 -0
- data/lib/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_version.rb +7 -0
- data/lib/lib/smart_proxy_dhcp_bluecat/module_loader.rb +6 -0
- data/lib/lib/smart_proxy_dhcp_bluecat/plugin_configuration.rb +33 -0
- data/lib/lib/smart_proxy_dhcp_bluecat/settings_validator.rb +62 -0
- data/lib/smart_proxy_dhcp_bluecat.rb +11 -0
- data/lib/smart_proxy_dhcp_bluecat/bluecat_api.rb +345 -0
- data/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_main.rb +109 -0
- data/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_plugin.rb +34 -0
- data/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_version.rb +7 -0
- data/lib/smart_proxy_dhcp_bluecat/module_loader.rb +6 -0
- data/lib/smart_proxy_dhcp_bluecat/plugin_configuration.rb +33 -0
- data/lib/smart_proxy_dhcp_bluecat/settings_validator.rb +62 -0
- metadata +108 -0
@@ -0,0 +1,109 @@
|
|
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
|
@@ -0,0 +1,34 @@
|
|
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
|
@@ -0,0 +1,33 @@
|
|
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
|
@@ -0,0 +1,62 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smart_proxy_dhcp_bluecat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthias Hähnel
|
8
|
+
- The Foreman Team
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-10-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: ipaddress
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rubocop
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.50.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.50.0
|
56
|
+
description: BlueCat DHCP provider plugin for Foreman's smart proxy
|
57
|
+
email:
|
58
|
+
- matthias.haehnel@sixt.com
|
59
|
+
- theforeman.rubygems@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- config/dhcp_bluecat.yml.example
|
65
|
+
- lib/smart_proxy_dhcp_bluecat.rb
|
66
|
+
- lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_main.rb
|
67
|
+
- lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_plugin.rb
|
68
|
+
- lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_version.rb
|
69
|
+
- lib/smart_proxy_dhcp_bluecat/module_loader.rb
|
70
|
+
- lib/smart_proxy_dhcp_bluecat/plugin_configuration.rb
|
71
|
+
- lib/smart_proxy_dhcp_bluecat/settings_validator.rb
|
72
|
+
- lib/smart_proxy_dhcp_bluecat/bluecat_api.rb
|
73
|
+
- lib/lib/smart_proxy_dhcp_bluecat/bluecat_api.rb
|
74
|
+
- lib/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_main.rb
|
75
|
+
- lib/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_plugin.rb
|
76
|
+
- lib/lib/smart_proxy_dhcp_bluecat/dhcp_bluecat_version.rb
|
77
|
+
- lib/lib/smart_proxy_dhcp_bluecat/module_loader.rb
|
78
|
+
- lib/lib/smart_proxy_dhcp_bluecat/plugin_configuration.rb
|
79
|
+
- lib/lib/smart_proxy_dhcp_bluecat/settings_validator.rb
|
80
|
+
- lib/lib/smart_proxy_dhcp_bluecat.rb
|
81
|
+
- bundler.d/dhcp_bluecat.rb
|
82
|
+
- README.md
|
83
|
+
- LICENSE
|
84
|
+
homepage: https://github.com/theforeman/smart_proxy_dhcp_bluecat
|
85
|
+
licenses:
|
86
|
+
- GPL-3.0
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.0.14.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: BlueCat DHCP provider plugin for Foreman's smart proxy
|
108
|
+
test_files: []
|