smart_proxy_ipam 0.0.13 → 0.0.14

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
  SHA256:
3
- metadata.gz: e15677a434645d7983b2d76599f64846fd15676de6752fd552939463156e406c
4
- data.tar.gz: a9905c07b628625af2f3d69507f8388d92cfec0cb16fb5bd4583e59ce488147f
3
+ metadata.gz: f4017f16c516229f75256a5faef4a29916ffd626784c643e77784a4cbb708ec6
4
+ data.tar.gz: c04dd0e4ee1e7402c02086a60b14360787627cc6a336e7d61d063541b494fad2
5
5
  SHA512:
6
- metadata.gz: ca743342ca290e14d6c4116475b3106ae71cffff89d7192b7b9873082a5ccaa80b406b25c3d31676b6d51c6cb50efc94c4d821226214de93e1a3c654bb24caf7
7
- data.tar.gz: a550aab54cfeff4b727a088cf34cb97deb6e3df0575572d6e007699b248e542840de35aa01ec587f5e75c4d9ed48f5b3ea03fcdefbe332ef76a9ee2478a5ad5c
6
+ metadata.gz: d8992cd2c717f34846b37b9d8d5e9955835a6e8946c9edfb4d9bb34b793f6e8cdd0ac0a6064479d1b1bbbe78c6345dd8bcf7658046f07e47df2e84458dfd0316
7
+ data.tar.gz: 42d32cb87be69dfb8467dd618e1ab539e6cef7081e6914ab461520af3ea83cfcdd6469e596efcc3fd75530843401e045a8297288f47dfa407a68445a5afe8ff3
@@ -14,41 +14,43 @@ module Proxy::Phpipam
14
14
 
15
15
  # Gets the next available IP address based on a given subnet
16
16
  #
17
- # Input: cidr(string): CIDR address in the format: "100.20.20.0/24"
18
- # Returns: Hash with "next_ip", or hash with "error"
19
- # Examples:
20
- # Response if success:
21
- # {"cidr":"100.20.20.0/24","next_ip":"100.20.20.11"}
22
- # Response if :error =>
23
- # {"error":"The specified subnet does not exist in phpIPAM."}
24
- get '/next_ip' do
17
+ # Inputs: address: Network address of the subnet(e.g. 100.55.55.0)
18
+ # prefix: Network prefix(e.g. 24)
19
+ #
20
+ # Returns: Hash with next available IP address in "data", or hash with "message" containing
21
+ # error message from phpIPAM.
22
+ #
23
+ # Response if success:
24
+ # {"code": 200, "success": true, "data": "100.55.55.3", "time": 0.012}
25
+ get '/subnet/:address/:prefix/next_ip' do
25
26
  content_type :json
26
27
 
27
28
  begin
28
- err = validate_required_params(["cidr", "mac"], params)
29
+ err = validate_required_params(["address", "prefix", "mac"], params)
29
30
  return err if err.length > 0
30
31
 
31
- cidr = params[:cidr]
32
32
  mac = params[:mac]
33
+ cidr = params[:address] + '/' + params[:prefix]
33
34
  phpipam_client = PhpipamClient.new
34
35
  subnet = JSON.parse(phpipam_client.get_subnet(cidr))
36
+ return {:code => subnet['code'], :error => subnet['message']}.to_json if no_subnets_found(subnet)
37
+ ipaddr = phpipam_client.get_next_ip(subnet['data'][0]['id'], mac, cidr)
38
+ return {:code => subnet['code'], :error => ipaddr['message']}.to_json if no_free_ip_found(JSON.parse(ipaddr))
35
39
 
36
- return {:error => errors[:no_subnet]}.to_json if no_subnets_found(subnet)
37
-
38
- ip = phpipam_client.get_next_ip(subnet[0]['id'], mac, cidr)
39
-
40
- return {:error => errors[:no_free_ip]}.to_json if no_free_ip_found(ip)
41
-
42
- {:cidr => cidr, :next_ip => ip['next_ip']}.to_json
40
+ ipaddr
43
41
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET
44
- return {:error => errors[:no_connection]}.to_json
42
+ logger.debug(errors[:no_connection])
43
+ raise
45
44
  end
46
45
  end
47
46
 
48
47
  # Gets the subnet from phpIPAM
49
48
  #
50
- # Input: cidr(string): CIDR address in the format: "100.20.20.0/24"
49
+ # Inputs: address: Network address of the subnet
50
+ # prefix: Network prefix(e.g. 24)
51
+ #
51
52
  # Returns: JSON with "data" key on success, or JSON with "error" key when there is an error
53
+ #
52
54
  # Examples:
53
55
  # Response if subnet exists:
54
56
  # {
@@ -64,19 +66,20 @@ module Proxy::Phpipam
64
66
  # {
65
67
  # "code":200,"success":0,"message":"No subnets found","time":0.01
66
68
  # }
67
- get '/get_subnet' do
69
+ get '/subnet/:address/:prefix' do
68
70
  content_type :json
69
71
 
70
72
  begin
71
- err = validate_required_params(["cidr"], params)
73
+ err = validate_required_params(["address", "prefix"], params)
72
74
  return err if err.length > 0
73
75
 
76
+ cidr = params[:address] + '/' + params[:prefix]
77
+
74
78
  phpipam_client = PhpipamClient.new
75
- subnet = JSON.parse(phpipam_client.get_subnet(params[:cidr]))
76
- return {:error => errors[:no_subnet]}.to_json if no_subnets_found(subnet)
77
- subnet.to_json
79
+ phpipam_client.get_subnet(cidr)
78
80
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET
79
- return {:error => errors[:no_connection]}.to_json
81
+ logger.debug(errors[:no_connection])
82
+ raise
80
83
  end
81
84
  end
82
85
 
@@ -97,9 +100,10 @@ module Proxy::Phpipam
97
100
 
98
101
  begin
99
102
  phpipam_client = PhpipamClient.new
100
- phpipam_client.get_sections.to_json
103
+ phpipam_client.get_sections
101
104
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET
102
- return {:error => errors[:no_connection]}.to_json
105
+ logger.debug(errors[:no_connection])
106
+ raise
103
107
  end
104
108
  end
105
109
 
@@ -165,107 +169,115 @@ module Proxy::Phpipam
165
169
  err = validate_required_params(["section_name"], params)
166
170
  return err if err.length > 0
167
171
 
168
- section_name = URI.decode(params[:section_name])
172
+ section_name = CGI.unescape(params[:section_name])
169
173
  phpipam_client = PhpipamClient.new
170
- section = phpipam_client.get_section(section_name)
174
+ section = JSON.parse(phpipam_client.get_section(section_name))
171
175
 
172
- return {:error => errors[:no_section]}.to_json if section.nil?
176
+ return {:code => section['code'], :error => section['message']}.to_json if no_section_found(section)
173
177
 
174
- subnets = phpipam_client.get_subnets(section['id'].to_s)
175
- subnets.to_json
178
+ phpipam_client.get_subnets(section['data']['id'].to_s)
176
179
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET
177
- return {:error => errors[:no_connection]}.to_json
180
+ logger.debug(errors[:no_connection])
181
+ raise
178
182
  end
179
183
  end
180
184
 
181
185
  # Checks whether an IP address has already been taken in external ipam.
182
186
  #
183
- # Inputs: 1. ip(string). IP address to be checked.
184
- # 2. cidr(string): CIDR address in the format: "100.20.20.0/24"
187
+ # Params: 1. address: The network address of the IPv4 or IPv6 subnet.
188
+ # 2. prefix: The subnet prefix(e.g. 24)
189
+ # 3. ip: IP address to be queried
190
+ #
185
191
  # Returns: JSON object with 'exists' field being either true or false
192
+ #
186
193
  # Example:
187
194
  # Response if exists:
188
195
  # {"ip":"100.20.20.18","exists":true}
189
196
  # Response if not exists:
190
197
  # {"ip":"100.20.20.18","exists":false}
191
- get '/ip_exists' do
198
+ get '/subnet/:address/:prefix/:ip' do
192
199
  content_type :json
193
200
 
194
201
  begin
195
- err = validate_required_params(["cidr", "ip"], params)
202
+ err = validate_required_params(["address", "prefix", "ip"], params)
196
203
  return err if err.length > 0
197
204
 
205
+ ip = params[:ip]
206
+ cidr = params[:address] + '/' + params[:prefix]
198
207
  phpipam_client = PhpipamClient.new
199
- subnet = JSON.parse(phpipam_client.get_subnet(params[:cidr]))
208
+ subnet = JSON.parse(phpipam_client.get_subnet(cidr))
200
209
 
201
- return {:error => errors[:no_subnet]}.to_json if no_subnets_found(subnet)
210
+ return {:code => subnet['code'], :error => subnet['message']}.to_json if no_subnets_found(subnet)
202
211
 
203
- phpipam_client.ip_exists(params[:ip], subnet[0]['id'])
212
+ phpipam_client.ip_exists(ip, subnet['data'][0]['id'])
204
213
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET
205
- return {:error => errors[:no_connection]}.to_json
214
+ logger.debug(errors[:no_connection])
215
+ raise
206
216
  end
207
217
  end
208
218
 
209
- # Adds an IP address to the specified subnet
219
+ # Adds an IP address to the specified subnet
220
+ #
221
+ # Params: 1. address: The network address of the IPv4 or IPv6 subnet.
222
+ # 2. prefix: The subnet prefix(e.g. 24)
223
+ # 3. ip: IP address to be added
210
224
  #
211
- # Inputs: 1. ip(string). IP address to be added.
212
- # 2. subnet_id(integer). The id of the external ipam subnet
213
- # 3. description(string). IP address description
214
225
  # Returns: Hash with "message" on success, or hash with "error"
226
+ #
215
227
  # Examples:
216
228
  # Response if success:
217
- # {"message":"IP 100.10.10.123 added to subnet 100.10.10.0/24 successfully."}
229
+ # IPv4: {"message":"IP 100.10.10.123 added to subnet 100.10.10.0/24 successfully."}
230
+ # IPv6: {"message":"IP 2001:db8:abcd:12::3 added to subnet 2001:db8:abcd:12::/124 successfully."}
218
231
  # Response if :error =>
219
232
  # {"error":"The specified subnet does not exist in phpIPAM."}
220
- post '/add_ip_to_subnet' do
233
+ post '/subnet/:address/:prefix/:ip' do
221
234
  content_type :json
222
235
 
223
236
  begin
224
- err = validate_required_params(["cidr", "ip"], params)
237
+ err = validate_required_params(["address", "ip", "prefix"], params)
225
238
  return err if err.length > 0
226
239
 
227
240
  ip = params[:ip]
228
- cidr = params[:cidr]
241
+ cidr = params[:address] + '/' + params[:prefix]
229
242
  phpipam_client = PhpipamClient.new
230
243
  subnet = JSON.parse(phpipam_client.get_subnet(cidr))
231
244
 
232
- return {:error => errors[:no_subnet]}.to_json if no_subnets_found(subnet)
233
-
234
- phpipam_client.add_ip_to_subnet(ip, subnet[0]['id'], 'Address auto added by Foreman')
245
+ return {:code => subnet['code'], :error => subnet['message']}.to_json if no_subnets_found(subnet)
235
246
 
236
- {:message => "IP #{ip} added to subnet #{cidr} successfully."}.to_json
247
+ phpipam_client.add_ip_to_subnet(ip, subnet['data'][0]['id'], 'Address auto added by Foreman')
237
248
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET
238
- return {:error => errors[:no_connection]}.to_json
249
+ logger.debug(errors[:no_connection])
250
+ raise
239
251
  end
240
252
  end
241
253
 
242
254
  # Deletes IP address from a given subnet
243
255
  #
244
- # Inputs: 1. ip(string). IP address to be checked.
245
- # 2. cidr(string): CIDR address in the format: "100.20.20.0/24"
256
+ # Params: 1. address: The network address of the IPv4 or IPv6 subnet.
257
+ # 2. prefix: The subnet prefix(e.g. 24)
258
+ # 3. ip: IP address to be deleted
259
+ #
246
260
  # Returns: JSON object
247
261
  # Example:
248
262
  # Response if success:
249
263
  # {"code": 200, "success": true, "message": "Address deleted", "time": 0.017}
250
264
  # Response if :error =>
251
265
  # {"code": 404, "success": 0, "message": "Address does not exist", "time": 0.008}
252
- post '/delete_ip_from_subnet' do
266
+ delete '/subnet/:address/:prefix/:ip' do
253
267
  content_type :json
254
268
 
255
269
  begin
256
- err = validate_required_params(["cidr", "ip"], params)
270
+ err = validate_required_params(["address", "prefix", "ip"], params)
257
271
  return err if err.length > 0
258
272
 
259
273
  ip = params[:ip]
260
- cidr = params[:cidr]
274
+ cidr = params[:address] + '/' + params[:prefix]
261
275
  phpipam_client = PhpipamClient.new
262
276
  subnet = JSON.parse(phpipam_client.get_subnet(cidr))
263
277
 
264
- return {:error => errors[:no_subnet]}.to_json if no_subnets_found(subnet)
265
-
266
- phpipam_client.delete_ip_from_subnet(ip, subnet[0]['id'])
278
+ return {:code => subnet['code'], :error => subnet['message']}.to_json if no_subnets_found(subnet)
267
279
 
268
- {:message => "IP #{ip} deleted from subnet #{cidr} successfully."}.to_json
280
+ phpipam_client.delete_ip_from_subnet(ip, subnet['data'][0]['id'])
269
281
  rescue Errno::ECONNREFUSED, Errno::ECONNRESET
270
282
  return {:error => errors[:no_connection]}.to_json
271
283
  end
@@ -28,109 +28,72 @@ module Proxy::Phpipam
28
28
  end
29
29
 
30
30
  def get_subnet(cidr)
31
- subnets = get("subnets/cidr/#{cidr.to_s}")
32
- return {:error => errors[:no_subnet]}.to_json if no_subnets_found(subnets)
33
- response = []
34
-
35
- # Only return the relevant fields
36
- subnets['data'].each do |subnet|
37
- response.push({
38
- :id => subnet['id'],
39
- :subnet => subnet['subnet'],
40
- :description => subnet['description'],
41
- :mask => subnet['mask']
42
- })
43
- end
31
+ response = get("subnets/cidr/#{cidr.to_s}")
32
+ json_body = JSON.parse(response.body)
44
33
 
45
- response.to_json
46
- end
34
+ return response.body if no_subnets_found(json_body)
47
35
 
48
- def add_ip_to_subnet(ip, subnet_id, desc)
49
- data = {:subnetId => subnet_id, :ip => ip, :description => desc}
50
- post('addresses/', data)
36
+ json_body['data'] = filter_fields(json_body, [:id, :subnet, :description, :mask])
37
+ response.body = json_body.to_json
38
+ response.header['Content-Length'] = json_body.to_s.length
39
+ response.body
51
40
  end
52
41
 
53
42
  def get_section(section_name)
54
- get("sections/#{section_name}/")["data"]
43
+ response = get("sections/#{section_name}/")
44
+ response.body
55
45
  end
56
46
 
57
47
  def get_sections
58
- sections = get('sections/')['data']
59
- response = []
60
-
61
- if sections
62
- sections.each do |section|
63
- response.push({
64
- :id => section['id'],
65
- :name => section['name'],
66
- :description => section['description']
67
- })
68
- end
69
- end
70
-
71
- response
48
+ response = get('sections/')
49
+ json_body = JSON.parse(response.body)
50
+ json_body['data'] = filter_fields(json_body, [:id, :name, :description])
51
+ logger.debug("=================")
52
+ logger.debug("SECTIONS JSON: " + json_body.to_s)
53
+ logger.debug("=================")
54
+ response.body = json_body.to_json
55
+ response.header['Content-Length'] = json_body.to_s.length
56
+ response.body
72
57
  end
73
58
 
74
59
  def get_subnets(section_id)
75
- subnets = get("sections/#{section_id}/subnets/")
76
- response = []
77
-
78
- if subnets && subnets['data']
79
- # Only return the relevant fields
80
- subnets['data'].each do |subnet|
81
- response.push({
82
- :id => subnet['id'],
83
- :subnet => subnet['subnet'],
84
- :mask => subnet['mask'],
85
- :sectionId => subnet['sectionId'],
86
- :description => subnet['description']
87
- })
88
- end
89
- end
90
-
91
- response
60
+ response = get("sections/#{section_id}/subnets/")
61
+ json_body = JSON.parse(response.body)
62
+ json_body['data'] = filter_fields(json_body, [:id, :subnet, :mask, :sectionId, :description])
63
+ response.body = json_body.to_json
64
+ response.header['Content-Length'] = json_body.to_s.length
65
+ response.body
92
66
  end
93
67
 
94
68
  def ip_exists(ip, subnet_id)
95
- usage = get_subnet_usage(subnet_id)
96
-
97
- # We need to check subnet usage first in the case there are zero ips in the subnet. Checking
98
- # the ip existence on an empty subnet returns a malformed response from phpIPAM(v1.3), containing
99
- # HTML in the JSON response.
100
- if usage['data']['used'] == "0"
101
- return {:ip => ip, :exists => false}.to_json
102
- else
103
- response = get("subnets/#{subnet_id.to_s}/addresses/#{ip}/")
104
-
105
- if ip_not_found_in_ipam(response)
106
- return {:ip => ip, :exists => false}.to_json
107
- else
108
- return {:ip => ip, :exists => true}.to_json
109
- end
110
- end
69
+ response = get("subnets/#{subnet_id.to_s}/addresses/#{ip}/")
70
+ response.body
111
71
  end
112
72
 
113
-
114
- def get_subnet_usage(subnet_id)
115
- get("subnets/#{subnet_id.to_s}/usage/")
73
+ def add_ip_to_subnet(ip, subnet_id, desc)
74
+ data = {:subnetId => subnet_id, :ip => ip, :description => desc}
75
+ response = post('addresses/', data)
76
+ response.body
116
77
  end
117
78
 
118
79
  def delete_ip_from_subnet(ip, subnet_id)
119
- delete("addresses/#{ip}/#{subnet_id.to_s}/")
80
+ response = delete("addresses/#{ip}/#{subnet_id.to_s}/")
81
+ response.body
120
82
  end
121
83
 
122
84
  def get_next_ip(subnet_id, mac, cidr)
123
85
  response = get("subnets/#{subnet_id.to_s}/first_free/")
86
+ json_body = JSON.parse(response.body)
124
87
  subnet_hash = @@ip_cache[cidr.to_sym]
125
88
 
126
- return response if response['message']
89
+ return {:code => json_body['code'], :error => json_body['message']}.to_json if json_body['message']
127
90
 
128
91
  if subnet_hash && subnet_hash.key?(mac.to_sym)
129
- response['next_ip'] = @@ip_cache[cidr.to_sym][mac.to_sym][:ip]
92
+ json_body['data'] = @@ip_cache[cidr.to_sym][mac.to_sym][:ip]
130
93
  else
131
94
  next_ip = nil
132
- new_ip = response['data']
133
- ip_not_in_cache = subnet_hash && !subnet_hash.to_s.include?(new_ip.to_s)
95
+ new_ip = json_body['data']
96
+ ip_not_in_cache = subnet_hash.nil? ? true : !subnet_hash.to_s.include?(new_ip.to_s)
134
97
 
135
98
  if ip_not_in_cache
136
99
  next_ip = new_ip.to_s
@@ -139,20 +102,15 @@ module Proxy::Phpipam
139
102
  next_ip = find_new_ip(subnet_id, new_ip, mac, cidr)
140
103
  end
141
104
 
142
- if next_ip.nil?
143
- response['error'] = "Unable to find another available IP address in subnet #{cidr}"
144
- return response
145
- end
146
-
147
- unless usable_ip(next_ip, cidr)
148
- response['error'] = "It is possible that there are no more free addresses in subnet #{cidr}. Available IP's may be cached, and could become available after in-memory IP cache is cleared(up to #{CLEAR_CACHE_DELAY} seconds)."
149
- return response
150
- end
105
+ return {:code => 404, :error => "Unable to find another available IP address in subnet #{cidr}"}.to_json if next_ip.nil?
106
+ return {:code => 404, :error => "It is possible that there are no more free addresses in subnet #{cidr}. Available IP's may be cached, and could become available after in-memory IP cache is cleared(up to #{DEFAULT_CLEANUP_INTERVAL} seconds)."}.to_json unless usable_ip(next_ip, cidr)
151
107
 
152
- response['next_ip'] = next_ip
108
+ json_body['data'] = next_ip
153
109
  end
154
110
 
155
- response
111
+ response.body = json_body.to_json
112
+ response.header['Content-Length'] = json_body.to_s.length
113
+ response.body
156
114
  end
157
115
 
158
116
  def start_cleanup_task
@@ -195,7 +153,7 @@ module Proxy::Phpipam
195
153
  def add_ip_to_cache(ip, mac, cidr)
196
154
  logger.debug("Adding IP #{ip} to cache for subnet #{cidr}")
197
155
  @@m.synchronize do
198
- #clear cache data which has the same mac and ip with the new one
156
+ # Clear cache data which has the same mac and ip with the new one
199
157
  @@ip_cache.each do |key, values|
200
158
  if values.keys.include? mac.to_sym
201
159
  @@ip_cache[key].delete(mac.to_sym)
@@ -224,7 +182,7 @@ module Proxy::Phpipam
224
182
  verify_ip = JSON.parse(ip_exists(new_ip, subnet_id))
225
183
 
226
184
  # If new IP doesn't exist in IPAM and not in the cache
227
- if verify_ip['exists'] == false && !ip_exists_in_cache(new_ip, cidr, mac)
185
+ if ip_not_found_in_ipam(verify_ip) && !ip_exists_in_cache(new_ip, cidr, mac)
228
186
  found_ip = new_ip.to_s
229
187
  add_ip_to_cache(found_ip, mac, cidr)
230
188
  break
@@ -255,18 +213,15 @@ module Proxy::Phpipam
255
213
  network.include?(IPAddr.new(ip)) && network.to_range.last != ip
256
214
  end
257
215
 
258
- def get(path, body=nil)
216
+ def get(path)
259
217
  authenticate
260
218
  uri = URI(@api_base + path)
261
- uri.query = URI.encode_www_form(body) if body
262
219
  request = Net::HTTP::Get.new(uri)
263
220
  request['token'] = @token
264
221
 
265
- response = Net::HTTP.start(uri.hostname, uri.port) {|http|
222
+ Net::HTTP.start(uri.hostname, uri.port) {|http|
266
223
  http.request(request)
267
224
  }
268
-
269
- JSON.parse(response.body)
270
225
  end
271
226
 
272
227
  def delete(path, body=nil)
@@ -276,11 +231,9 @@ module Proxy::Phpipam
276
231
  request = Net::HTTP::Delete.new(uri)
277
232
  request['token'] = @token
278
233
 
279
- response = Net::HTTP.start(uri.hostname, uri.port) {|http|
234
+ Net::HTTP.start(uri.hostname, uri.port) {|http|
280
235
  http.request(request)
281
236
  }
282
-
283
- JSON.parse(response.body)
284
237
  end
285
238
 
286
239
  def post(path, body=nil)
@@ -290,11 +243,9 @@ module Proxy::Phpipam
290
243
  request = Net::HTTP::Post.new(uri)
291
244
  request['token'] = @token
292
245
 
293
- response = Net::HTTP.start(uri.hostname, uri.port) {|http|
246
+ Net::HTTP.start(uri.hostname, uri.port) {|http|
294
247
  http.request(request)
295
248
  }
296
-
297
- JSON.parse(response.body)
298
249
  end
299
250
 
300
251
  def authenticate
@@ -6,13 +6,17 @@ module PhpipamHelper
6
6
  err.push errors[param.to_sym]
7
7
  end
8
8
  end
9
- err.length == 0 ? [] : {:error => err}.to_json
9
+ err.length == 0 ? [] : {:code => 400, :error => err}.to_json
10
10
  end
11
11
 
12
12
  def no_subnets_found(subnet)
13
13
  !subnet.kind_of?(Array) && subnet['message'] && subnet['message'].downcase == "no subnets found"
14
14
  end
15
15
 
16
+ def no_section_found(section)
17
+ section['message'] && section['message'].downcase == "not found"
18
+ end
19
+
16
20
  def no_free_ip_found(ip)
17
21
  !ip.kind_of?(Array) && ip['message'] && ip['message'].downcase == "no free addresses found"
18
22
  end
@@ -21,15 +25,23 @@ module PhpipamHelper
21
25
  ip && ip['message'] && ip['message'].downcase == 'no addresses found'
22
26
  end
23
27
 
28
+ # Returns an array of hashes with only the fields given in the fields param
29
+ def filter_fields(json_body, fields)
30
+ data = []
31
+ json_body['data'].each do |subnet|
32
+ item = {}
33
+ fields.each do |field| item[field.to_sym] = subnet[field.to_s] end
34
+ data.push(item)
35
+ end if json_body && json_body['data']
36
+ data
37
+ end
38
+
24
39
  def errors
25
40
  {
26
- :cidr => "A 'cidr' parameter for the subnet must be provided(e.g. 100.10.10.0/24)",
41
+ :cidr => "A 'cidr' parameter for the subnet must be provided(e.g. IPv4: 100.10.10.0/24, IPv6: 2001:db8:abcd:12::/124)",
27
42
  :mac => "A 'mac' address must be provided(e.g. 00:0a:95:9d:68:10)",
28
- :ip => "Missing 'ip' parameter. An IPv4 address must be provided(e.g. 100.10.10.22)",
43
+ :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)",
29
44
  :section_name => "A 'section_name' must be provided",
30
- :no_free_ip => "There are no more free addresses in this subnet",
31
- :no_section => "Section not found in External IPAM.",
32
- :no_subnet => "The specified subnet does not exist in External IPAM.",
33
45
  :no_connection => "Unable to connect to External IPAM server"
34
46
  }
35
47
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Proxy
3
3
  module Ipam
4
- VERSION = '0.0.13'
4
+ VERSION = '0.0.14'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_ipam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-16 00:00:00.000000000 Z
11
+ date: 2019-12-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Smart proxy plugin for IPAM integration with various IPAM providers
14
14
  email: chrisjsmith001@gmail.com