smart_proxy_ipam 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smart_proxy_ipam/phpipam/phpipam_client.rb +34 -13
- data/lib/smart_proxy_ipam/version.rb +1 -1
- metadata +2 -3
- data/settings.d/external_ipam.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e15677a434645d7983b2d76599f64846fd15676de6752fd552939463156e406c
|
4
|
+
data.tar.gz: a9905c07b628625af2f3d69507f8388d92cfec0cb16fb5bd4583e59ce488147f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca743342ca290e14d6c4116475b3106ae71cffff89d7192b7b9873082a5ccaa80b406b25c3d31676b6d51c6cb50efc94c4d821226214de93e1a3c654bb24caf7
|
7
|
+
data.tar.gz: a550aab54cfeff4b727a088cf34cb97deb6e3df0575572d6e007699b248e542840de35aa01ec587f5e75c4d9ed48f5b3ea03fcdefbe332ef76a9ee2478a5ad5c
|
@@ -3,6 +3,7 @@ require 'json'
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'monitor'
|
5
5
|
require 'concurrent'
|
6
|
+
require 'time'
|
6
7
|
require 'smart_proxy_ipam/ipam'
|
7
8
|
require 'smart_proxy_ipam/ipam_main'
|
8
9
|
require 'smart_proxy_ipam/phpipam/phpipam_helper'
|
@@ -125,10 +126,11 @@ module Proxy::Phpipam
|
|
125
126
|
return response if response['message']
|
126
127
|
|
127
128
|
if subnet_hash && subnet_hash.key?(mac.to_sym)
|
128
|
-
response['next_ip'] = @@ip_cache[cidr.to_sym][mac.to_sym]
|
129
|
+
response['next_ip'] = @@ip_cache[cidr.to_sym][mac.to_sym][:ip]
|
129
130
|
else
|
131
|
+
next_ip = nil
|
130
132
|
new_ip = response['data']
|
131
|
-
ip_not_in_cache = subnet_hash && subnet_hash.
|
133
|
+
ip_not_in_cache = subnet_hash && !subnet_hash.to_s.include?(new_ip.to_s)
|
132
134
|
|
133
135
|
if ip_not_in_cache
|
134
136
|
next_ip = new_ip.to_s
|
@@ -164,28 +166,47 @@ module Proxy::Phpipam
|
|
164
166
|
# @@ip_cache structure
|
165
167
|
# {
|
166
168
|
# "100.55.55.0/24":{
|
167
|
-
# "00:0a:95:9d:68:10": "100.55.55.1"
|
169
|
+
# "00:0a:95:9d:68:10": {"ip": "100.55.55.1", "timestamp": "2019-09-17 12:03:43 -D400"}
|
168
170
|
# },
|
169
171
|
# "123.11.33.0/24":{
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
172
|
+
# "00:0a:95:9d:68:33": {"ip": "123.11.33.1", "timestamp": "2019-09-17 12:04:43 -0400"}
|
173
|
+
# "00:0a:95:9d:68:34": {"ip": "123.11.33.2", "timestamp": "2019-09-17 12:05:48 -0400"}
|
174
|
+
# "00:0a:95:9d:68:35": {"ip": "123.11.33.3", "timestamp:: "2019-09-17 12:06:50 -0400"}
|
173
175
|
# }
|
174
176
|
# }
|
175
177
|
def init_cache
|
176
178
|
logger.debug("Clearing ip cache.")
|
177
179
|
@@m.synchronize do
|
178
|
-
@@ip_cache
|
180
|
+
if @@ip_cache and not @@ip_cache.empty?
|
181
|
+
@@ip_cache.each do |key, values|
|
182
|
+
values.each do |mac, value|
|
183
|
+
if Time.now - Time.parse(value[:timestamp]) > DEFAULT_CLEANUP_INTERVAL
|
184
|
+
@@ip_cache[key].delete(mac)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
@@ip_cache.delete(key) if @@ip_cache[key].nil? or @@ip_cache[key].empty?
|
188
|
+
end
|
189
|
+
else
|
190
|
+
@@ip_cache = {}
|
191
|
+
end
|
179
192
|
end
|
180
193
|
end
|
181
194
|
|
182
195
|
def add_ip_to_cache(ip, mac, cidr)
|
183
196
|
logger.debug("Adding IP #{ip} to cache for subnet #{cidr}")
|
184
197
|
@@m.synchronize do
|
198
|
+
#clear cache data which has the same mac and ip with the new one
|
199
|
+
@@ip_cache.each do |key, values|
|
200
|
+
if values.keys.include? mac.to_sym
|
201
|
+
@@ip_cache[key].delete(mac.to_sym)
|
202
|
+
end
|
203
|
+
@@ip_cache.delete(key) if @@ip_cache[key].nil? or @@ip_cache[key].empty?
|
204
|
+
end
|
205
|
+
|
185
206
|
if @@ip_cache.key?(cidr.to_sym)
|
186
|
-
@@ip_cache[cidr.to_sym][mac.to_sym] = ip.to_s
|
207
|
+
@@ip_cache[cidr.to_sym][mac.to_sym] = {:ip => ip.to_s, :timestamp => Time.now.to_s}
|
187
208
|
else
|
188
|
-
@@ip_cache = @@ip_cache.merge({cidr.to_sym => {mac.to_sym => ip.to_s}})
|
209
|
+
@@ip_cache = @@ip_cache.merge({cidr.to_sym => {mac.to_sym => {:ip => ip.to_s, :timestamp => Time.now.to_s}}})
|
189
210
|
end
|
190
211
|
end
|
191
212
|
end
|
@@ -203,7 +224,7 @@ module Proxy::Phpipam
|
|
203
224
|
verify_ip = JSON.parse(ip_exists(new_ip, subnet_id))
|
204
225
|
|
205
226
|
# If new IP doesn't exist in IPAM and not in the cache
|
206
|
-
if verify_ip['exists'] == false && !ip_exists_in_cache(new_ip, cidr)
|
227
|
+
if verify_ip['exists'] == false && !ip_exists_in_cache(new_ip, cidr, mac)
|
207
228
|
found_ip = new_ip.to_s
|
208
229
|
add_ip_to_cache(found_ip, mac, cidr)
|
209
230
|
break
|
@@ -224,8 +245,8 @@ module Proxy::Phpipam
|
|
224
245
|
IPAddr.new(ip.to_s).succ.to_s
|
225
246
|
end
|
226
247
|
|
227
|
-
def ip_exists_in_cache(ip, cidr)
|
228
|
-
@@ip_cache[cidr.to_sym] &&
|
248
|
+
def ip_exists_in_cache(ip, cidr, mac)
|
249
|
+
@@ip_cache[cidr.to_sym] && @@ip_cache[cidr.to_sym].to_s.include?(ip.to_s)
|
229
250
|
end
|
230
251
|
|
231
252
|
# Checks if given IP is within a subnet. Broadcast address is considered unusable
|
@@ -289,4 +310,4 @@ module Proxy::Phpipam
|
|
289
310
|
@token = response['data']['token']
|
290
311
|
end
|
291
312
|
end
|
292
|
-
end
|
313
|
+
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.
|
4
|
+
version: 0.0.13
|
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-
|
11
|
+
date: 2019-10-16 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
|
@@ -29,7 +29,6 @@ files:
|
|
29
29
|
- lib/smart_proxy_ipam/phpipam/phpipam_client.rb
|
30
30
|
- lib/smart_proxy_ipam/phpipam/phpipam_helper.rb
|
31
31
|
- lib/smart_proxy_ipam/version.rb
|
32
|
-
- settings.d/external_ipam.yml
|
33
32
|
- settings.d/external_ipam.yml.example
|
34
33
|
homepage: http://github.com/grizzthedj/smart_proxy_ipam
|
35
34
|
licenses:
|