smart_proxy_ipam 0.0.18 → 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 +4 -4
- data/README.md +31 -26
- data/bundler.d/ipam.rb +0 -1
- data/lib/smart_proxy_ipam.rb +2 -0
- data/lib/smart_proxy_ipam/api_resource.rb +57 -0
- data/lib/smart_proxy_ipam/dependency_injection.rb +9 -0
- data/lib/smart_proxy_ipam/ip_cache.rb +130 -0
- data/lib/smart_proxy_ipam/ipam.rb +11 -6
- data/lib/smart_proxy_ipam/ipam_api.rb +391 -0
- data/lib/smart_proxy_ipam/ipam_helper.rb +113 -0
- data/lib/smart_proxy_ipam/ipam_http_config.ru +2 -3
- data/lib/smart_proxy_ipam/ipam_validator.rb +48 -0
- data/lib/smart_proxy_ipam/netbox/netbox_client.rb +193 -0
- data/lib/smart_proxy_ipam/netbox/netbox_plugin.rb +17 -0
- data/lib/smart_proxy_ipam/phpipam/phpipam_client.rb +118 -268
- data/lib/smart_proxy_ipam/phpipam/phpipam_plugin.rb +17 -0
- data/lib/smart_proxy_ipam/version.rb +1 -2
- data/settings.d/externalipam.yml.example +1 -6
- data/settings.d/externalipam_netbox.yml.example +3 -0
- data/settings.d/externalipam_phpipam.yml.example +4 -0
- metadata +17 -9
- data/lib/smart_proxy_ipam/ipam_main.rb +0 -11
- data/lib/smart_proxy_ipam/phpipam/phpipam_api.rb +0 -378
- data/lib/smart_proxy_ipam/phpipam/phpipam_helper.rb +0 -62
@@ -1,62 +0,0 @@
|
|
1
|
-
module PhpipamHelper
|
2
|
-
def validate_required_params(required_params, params)
|
3
|
-
err = []
|
4
|
-
required_params.each do |param|
|
5
|
-
if not params[param.to_sym]
|
6
|
-
err.push errors[param.to_sym]
|
7
|
-
end
|
8
|
-
end
|
9
|
-
err.length == 0 ? [] : {:code => 400, :error => err}.to_json
|
10
|
-
end
|
11
|
-
|
12
|
-
def no_subnets_found?(subnet)
|
13
|
-
subnet['error'] && subnet['error'].downcase == "no subnets found"
|
14
|
-
end
|
15
|
-
|
16
|
-
def no_section_found?(section)
|
17
|
-
section['message'] && section['message'].downcase == "not found"
|
18
|
-
end
|
19
|
-
|
20
|
-
def no_sections_found?(sections)
|
21
|
-
sections['message'] && sections['message'].downcase == "no sections available"
|
22
|
-
end
|
23
|
-
|
24
|
-
def no_free_ip_found?(ip)
|
25
|
-
ip['error'] && ip['error'].downcase == "no free addresses found"
|
26
|
-
end
|
27
|
-
|
28
|
-
def ip_not_found_in_ipam?(ip)
|
29
|
-
ip && ip['message'] && ip['message'].downcase == 'no addresses found'
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns an array of hashes with only the fields given in the fields param
|
33
|
-
def filter_fields(json_body, fields)
|
34
|
-
data = []
|
35
|
-
json_body['data'].each do |subnet|
|
36
|
-
item = {}
|
37
|
-
fields.each do |field| item[field.to_sym] = subnet[field.to_s] end
|
38
|
-
data.push(item)
|
39
|
-
end if json_body && json_body['data']
|
40
|
-
data
|
41
|
-
end
|
42
|
-
|
43
|
-
# Returns a hash with only the fields given in the fields param
|
44
|
-
def filter_hash(hash, fields)
|
45
|
-
new_hash = {}
|
46
|
-
fields.each do |field|
|
47
|
-
new_hash[field.to_sym] = hash[field.to_s] if hash[field.to_s]
|
48
|
-
end
|
49
|
-
new_hash
|
50
|
-
end
|
51
|
-
|
52
|
-
def errors
|
53
|
-
{
|
54
|
-
:cidr => "A 'cidr' parameter for the subnet must be provided(e.g. IPv4: 100.10.10.0/24, IPv6: 2001:db8:abcd:12::/124)",
|
55
|
-
:mac => "A 'mac' address must be provided(e.g. 00:0a:95:9d:68:10)",
|
56
|
-
:ip => "Missing 'ip' parameter. An IPv4 or IPv6 address must be provided(e.g. IPv4: 100.10.10.22, IPv6: 2001:db8:abcd:12::3)",
|
57
|
-
:section_name => "A 'section_name' must be provided",
|
58
|
-
:no_connection => "Unable to connect to External IPAM server",
|
59
|
-
:no_section => "Group not found in External IPAM"
|
60
|
-
}
|
61
|
-
end
|
62
|
-
end
|