smart_proxy_dhcp_device42 1.0.4 → 1.0.7

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
  SHA1:
3
- metadata.gz: 7b060da2f4f3ba7a2079d3b055581bff788ea048
4
- data.tar.gz: 5698c44288c4a2f4403af0845327f7911dbf58d7
3
+ metadata.gz: 720587ff8e5e3c27316e02285178dafe2b8a4cd5
4
+ data.tar.gz: e2d27fe1e2c7a00566f2779cceafff35a96be08b
5
5
  SHA512:
6
- metadata.gz: 1a818d400d61757938f7864ff53dfdfb73bc056a55e7d5f13f89d08b789c793e1da98bd46787f764150a8cbb2f8029714ba0b36588e06f8ca8df356c414ee946
7
- data.tar.gz: 4dcebf75f8f001a2638e19b46b3b896da25988b2fb1e9b5691fc409a237dbfe565f96bcb399c5da4f2d798e27c39bc99154a3e1886524d648f7ec2b7f6d7998a
6
+ metadata.gz: 06102dcdd46fa4f8d26d22d677008dc5c38f98c7e3870c4b8f10de26bfaa5243faa2993b49557bc996f0a526a502c886e10cfa187568dc1a2abab1b8a25ce05a
7
+ data.tar.gz: 1cd2fa271260a0358a687ae500beffedccf60b2b343d8e8b271dbac34457e26bb91a91c87a9e1ff30788b29847c7211d3855bb68240ab044958ff3e74157baaf
data/README.md CHANGED
@@ -18,13 +18,13 @@ When installing using "gem", make sure to install the bundle file:
18
18
  To enable this DHCP provider, edit `/etc/foreman-proxy/settings.d/dhcp.yml` and set:
19
19
 
20
20
  :use_provider: dhcp_device42
21
- :scheme: server scheme
22
- :verify: secure verification ( bool )
23
- :server: IP of device42 server
24
21
  :subnets: subnets you want to use (optional unless you set device42_subnets to false)
25
22
 
26
23
  Configuration options for this plugin are in `/etc/foreman-proxy/settings.d/dhcp_device42.yml` and include:
27
24
 
25
+ :scheme: server scheme
26
+ :verify: secure verification ( bool )
27
+ :server: IP of device42 server
28
28
  :username: API Username
29
29
  :password: API Password
30
30
 
@@ -0,0 +1,9 @@
1
+ ---
2
+ #
3
+ # Configuration file for 'dhcp_device42' dhcp provider
4
+ #
5
+ :scheme: http
6
+ :verify: false
7
+ :server: 192.168.0.2
8
+ :username: "username"
9
+ :password: "password"
@@ -5,5 +5,8 @@ module Proxy
5
5
  end
6
6
 
7
7
  require 'smart_proxy_dhcp_device42/plugin_configuration'
8
+ require 'smart_proxy_dhcp_device42/scheme_validator'
9
+ require 'smart_proxy_dhcp_device42/verify_validator'
10
+ require 'smart_proxy_dhcp_device42/module_loader'
8
11
  require 'smart_proxy_dhcp_device42/dhcp_device42_version'
9
12
  require 'smart_proxy_dhcp_device42/dhcp_device42_plugin'
@@ -23,10 +23,6 @@ class Device42
23
23
 
24
24
  def rest_get(endpoint, querystring)
25
25
  response = HTTParty.get("%s://%s/api/1.0/%s/%s" % [@scheme, @host, endpoint, querystring], {
26
- :headers => {
27
- 'Content-Type' => 'application/x-www-form-urlencoded',
28
- 'charset' => 'utf-8'
29
- },
30
26
  :basic_auth => { :username => @username, :password => @password },
31
27
  :verify => @verify
32
28
  })
@@ -37,8 +33,7 @@ class Device42
37
33
  response = HTTParty.post("%s://%s/api/1.0/%s/" % [@scheme, @host, endpoint], {
38
34
  :body => body,
39
35
  :headers => {
40
- 'Content-Type' => 'application/x-www-form-urlencoded',
41
- 'charset' => 'utf-8'
36
+ 'Content-Type' => 'application/x-www-form-urlencoded'
42
37
  },
43
38
  :basic_auth => { :username => @username, :password => @password },
44
39
  :verify => @verify
@@ -61,8 +56,7 @@ class Device42
61
56
  :query => query
62
57
  },
63
58
  :headers => {
64
- 'Content-Type' => 'application/x-www-form-urlencoded',
65
- 'charset' => 'utf-8'
59
+ 'Content-Type' => 'application/x-www-form-urlencoded'
66
60
  },
67
61
  :basic_auth => { :username => @username, :password => @password },
68
62
  :verify => @verify
@@ -84,15 +78,22 @@ class Device42
84
78
  rest_post('ips', ip)
85
79
  end
86
80
 
87
- def remove_host(name)
88
- device = {
89
- :name => name
90
- }
91
- response = JSON.parse(rest_post('devices', device))
92
- device_id = response['msg'][1]
81
+ def remove_host(hostname)
82
+ response = JSON.parse(rest_get('devices/name', hostname))
83
+ device_id = response['id']
93
84
  rest_delete('devices', device_id)
94
85
  end
95
86
 
87
+ def get_hosts(network_address)
88
+ csv = doql("SELECT d.name, i.ip_address, n.hwaddress, s.network, s.mask_bits FROM view_subnet_v1 s
89
+ JOIN view_ipaddress_v1 i ON i.subnet_fk = s.subnet_pk
90
+ JOIN view_device_v1 d ON d.device_pk = i.device_fk
91
+ JOIN view_netport_v1 n ON n.netport_pk = i.netport_fk
92
+ WHERE s.network in ('%s')
93
+ AND i.available = False" % network_address)
94
+ return csv_to_array(csv)
95
+ end
96
+
96
97
  def get_hosts_by_ip(ip)
97
98
  csv = doql("SELECT d.name, i.ip_address, n.hwaddress, s.network, s.mask_bits FROM view_ipaddress_v1 i
98
99
  JOIN view_device_v1 d ON d.device_pk = i.device_fk
@@ -46,6 +46,21 @@ module Proxy::DHCP::Device42
46
46
  difined_subnets
47
47
  end
48
48
 
49
+ def all_hosts(network_address)
50
+ records = @connection.get_hosts(network_address)
51
+ return [] if records.empty?
52
+ reservs = []
53
+ records.each do |record|
54
+ reserv = build_reservation(record)
55
+ reservs.push(reserv) if !reserv.nil?
56
+ end
57
+ reservs
58
+ end
59
+
60
+ def all_leases(network_address)
61
+ [] # device42 doesn't support leases
62
+ end
63
+
49
64
  def unused_ip(subnet, _, from_ip_address, to_ip_address)
50
65
  @connection.get_next_ip(subnet, from_ip_address, to_ip_address)
51
66
  end
@@ -2,11 +2,17 @@ module Proxy::DHCP::Device42
2
2
  class Plugin < ::Proxy::Provider
3
3
  plugin :dhcp_device42, ::Proxy::DHCP::Device42::VERSION
4
4
 
5
- validate_presence :username, :password
5
+ validate_presence :username, :password, :server, :scheme, :verify
6
6
 
7
7
  requires :dhcp, '>= 1.16'
8
8
 
9
9
  load_classes ::Proxy::DHCP::Device42::PluginConfiguration
10
10
  load_dependency_injection_wirings ::Proxy::DHCP::Device42::PluginConfiguration
11
+ override_module_loader_class ::Proxy::DHCP::Device42::ModuleLoader
12
+
13
+ load_validators :scheme_validator => ::Proxy::DHCP::Device42::SchemeValidator, :verify_validator => ::Proxy::DHCP::Device42::VerifyValidator
14
+
15
+ validate :scheme, :scheme_validator => true
16
+ validate :verify, :verify_validator => true
11
17
  end
12
18
  end
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module DHCP
3
3
  module Device42
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.7'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,6 @@
1
+ class ::Proxy::DHCP::Device42::ModuleLoader < ::Proxy::DefaultModuleLoader
2
+ def log_provider_settings(settings)
3
+ super(settings)
4
+ logger.warn("http is used for connection to Device42 appliance") if settings[:scheme] != 'https'
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module ::Proxy::DHCP::Device42
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
+ end
@@ -0,0 +1,8 @@
1
+ module ::Proxy::DHCP::Device42
2
+ class VerifyValidator < ::Proxy::PluginValidators::Base
3
+ def validate!(settings)
4
+ return true if [true, false].include?(settings[:verify])
5
+ raise ::Proxy::Error::ConfigurationError, "Setting 'verify' can be set to either 'true' or 'false' ( bool )"
6
+ end
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_dhcp_device42
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatolii Chmykhalo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-27 00:00:00.000000000 Z
11
+ date: 2018-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -34,13 +34,16 @@ files:
34
34
  - LICENSE
35
35
  - README.md
36
36
  - bundler.d/dhcp_device42.rb
37
- - config/dhcp_device42.yml
37
+ - config/dhcp_device42.yml.example
38
38
  - lib/smart_proxy_dhcp_device42.rb
39
39
  - lib/smart_proxy_dhcp_device42/device42_api.rb
40
40
  - lib/smart_proxy_dhcp_device42/dhcp_device42_main.rb
41
41
  - lib/smart_proxy_dhcp_device42/dhcp_device42_plugin.rb
42
42
  - lib/smart_proxy_dhcp_device42/dhcp_device42_version.rb
43
+ - lib/smart_proxy_dhcp_device42/module_loader.rb
43
44
  - lib/smart_proxy_dhcp_device42/plugin_configuration.rb
45
+ - lib/smart_proxy_dhcp_device42/scheme_validator.rb
46
+ - lib/smart_proxy_dhcp_device42/verify_validator.rb
44
47
  homepage: https://www.device42.com
45
48
  licenses:
46
49
  - GPL-3.0
@@ -1,8 +0,0 @@
1
- ---
2
- # Configuration file for 'dhcp_device42' dhcp provider
3
- #
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
- :username: "admin"
8
- :password: "admin"