smart_proxy_ipam 0.0.22 → 0.1.4

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.
@@ -1,66 +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
- def auth_error
33
- {:code => 401, :error => "Invalid username and password for External IPAM"}.to_json
34
- end
35
-
36
- # Returns an array of hashes with only the fields given in the fields param
37
- def filter_fields(json_body, fields)
38
- data = []
39
- json_body['data'].each do |subnet|
40
- item = {}
41
- fields.each do |field| item[field.to_sym] = subnet[field.to_s] end
42
- data.push(item)
43
- end if json_body && json_body['data']
44
- data
45
- end
46
-
47
- # Returns a hash with only the fields given in the fields param
48
- def filter_hash(hash, fields)
49
- new_hash = {}
50
- fields.each do |field|
51
- new_hash[field.to_sym] = hash[field.to_s] if hash[field.to_s]
52
- end
53
- new_hash
54
- end
55
-
56
- def errors
57
- {
58
- :cidr => "A 'cidr' parameter for the subnet must be provided(e.g. IPv4: 100.10.10.0/24, IPv6: 2001:db8:abcd:12::/124)",
59
- :mac => "A 'mac' address must be provided(e.g. 00:0a:95:9d:68:10)",
60
- :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)",
61
- :section_name => "A 'section_name' must be provided",
62
- :no_connection => "Unable to connect to External IPAM server",
63
- :no_section => "Group not found in External IPAM"
64
- }
65
- end
66
- end