smart_proxy_ipam 0.0.20 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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