smart_proxy_ipam 0.0.21 → 0.0.22
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f0b5b073c4b57b12c9ca83fd64a21422ec79a2ad2f9e2207a024e3d7a36ea27
|
4
|
+
data.tar.gz: dcee04479c5e2862e24b8195c4b22bf614869e865b35ca55516cb8c37e75b946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9b297ff0d4baa62b0d5423ec74b203aa114802f461eb4ab8a6cdb575d80bbc45b9695d5b7f1da9e7e069a2a48cf9bd06c700ca3c40e407f989d79e66ae8c19c
|
7
|
+
data.tar.gz: 4b4368f41022d1d9c778a9767d558f8a4c782165631dfddc06bb63c24f4b15a78fb0e28c6d189e81b6c5a0d95dfcec4391641bf169c1fecc0b15ff0cfe5b0539
|
@@ -38,12 +38,12 @@ module Proxy::Phpipam
|
|
38
38
|
|
39
39
|
subnet = JSON.parse(phpipam_client.get_subnet(cidr, section_name))
|
40
40
|
|
41
|
-
return {:
|
41
|
+
return {:error => subnet['error']}.to_json if no_subnets_found?(subnet)
|
42
42
|
|
43
43
|
ipaddr = phpipam_client.get_next_ip(subnet['data']['id'], mac, cidr, section_name)
|
44
44
|
ipaddr_parsed = JSON.parse(ipaddr)
|
45
45
|
|
46
|
-
return {:
|
46
|
+
return {:error => ipaddr_parsed['error']}.to_json if no_free_ip_found?(ipaddr_parsed)
|
47
47
|
|
48
48
|
ipaddr
|
49
49
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
@@ -113,7 +113,7 @@ module Proxy::Phpipam
|
|
113
113
|
return auth_error unless phpipam_client.authenticated?
|
114
114
|
|
115
115
|
sections = phpipam_client.get_sections
|
116
|
-
return {:
|
116
|
+
return {:data => []}.to_json if no_sections_found?(JSON.parse(sections))
|
117
117
|
|
118
118
|
sections
|
119
119
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
@@ -122,7 +122,7 @@ module Proxy::Phpipam
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
# Get a single
|
125
|
+
# Get a single section from external ipam
|
126
126
|
#
|
127
127
|
# Input: Section name
|
128
128
|
# Returns: A JSON section on success, hash with "error" key otherwise
|
@@ -146,9 +146,9 @@ module Proxy::Phpipam
|
|
146
146
|
return auth_error unless phpipam_client.authenticated?
|
147
147
|
|
148
148
|
section = JSON.parse(phpipam_client.get_section(params[:group]))
|
149
|
-
return {
|
149
|
+
return {}.to_json if no_section_found?(section)
|
150
150
|
|
151
|
-
section.to_json
|
151
|
+
section['data'].to_json
|
152
152
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
153
153
|
logger.debug(errors[:no_connection])
|
154
154
|
raise
|
@@ -221,7 +221,7 @@ module Proxy::Phpipam
|
|
221
221
|
return auth_error unless phpipam_client.authenticated?
|
222
222
|
|
223
223
|
section = JSON.parse(phpipam_client.get_section(params[:group]))
|
224
|
-
return {:
|
224
|
+
return {:error => errors[:no_section]}.to_json if no_section_found?(section)
|
225
225
|
|
226
226
|
phpipam_client.get_subnets(section['data']['id'].to_s, false)
|
227
227
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
@@ -258,14 +258,15 @@ module Proxy::Phpipam
|
|
258
258
|
return auth_error unless phpipam_client.authenticated?
|
259
259
|
|
260
260
|
subnet = JSON.parse(phpipam_client.get_subnet(cidr, section_name))
|
261
|
-
return {:
|
261
|
+
return {:error => subnet['error']}.to_json if no_subnets_found?(subnet)
|
262
262
|
|
263
|
-
|
263
|
+
response = phpipam_client.ip_exists(ip, subnet['data']['id'])
|
264
|
+
ip_exists = JSON.parse(response.body)
|
264
265
|
|
265
266
|
if ip_exists['data']
|
266
|
-
return
|
267
|
+
return Net::HTTPFound.new('HTTP/1.1', 200, 'Found').to_json
|
267
268
|
else
|
268
|
-
return
|
269
|
+
return Net::HTTPNotFound.new('HTTP/1.1', 404, 'Not Found').to_json
|
269
270
|
end
|
270
271
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
271
272
|
logger.debug(errors[:no_connection])
|
@@ -302,14 +303,15 @@ module Proxy::Phpipam
|
|
302
303
|
return auth_error unless phpipam_client.authenticated?
|
303
304
|
|
304
305
|
subnet = JSON.parse(phpipam_client.get_subnet(cidr, section_name))
|
305
|
-
return {:
|
306
|
+
return {:error => subnet['error']}.to_json if no_subnets_found?(subnet)
|
306
307
|
|
307
|
-
|
308
|
+
response = phpipam_client.add_ip_to_subnet(ip, subnet['data']['id'], 'Address auto added by Foreman')
|
309
|
+
add_ip = JSON.parse(response.body)
|
308
310
|
|
309
311
|
if add_ip['message'] && add_ip['message'] == "Address created"
|
310
|
-
return
|
312
|
+
return Net::HTTPCreated.new('HTTP/1.1', 201, 'Created').to_json
|
311
313
|
else
|
312
|
-
return {:
|
314
|
+
return {:error => add_ip['message']}.to_json
|
313
315
|
end
|
314
316
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
315
317
|
logger.debug(errors[:no_connection])
|
@@ -343,14 +345,15 @@ module Proxy::Phpipam
|
|
343
345
|
return auth_error unless phpipam_client.authenticated?
|
344
346
|
|
345
347
|
subnet = JSON.parse(phpipam_client.get_subnet(cidr, section_name))
|
346
|
-
return {:
|
348
|
+
return {:error => subnet['error']}.to_json if no_subnets_found?(subnet)
|
347
349
|
|
348
|
-
|
350
|
+
response = phpipam_client.delete_ip_from_subnet(ip, subnet['data']['id'])
|
351
|
+
delete_ip = JSON.parse(response.body)
|
349
352
|
|
350
353
|
if delete_ip['message'] && delete_ip['message'] == "Address deleted"
|
351
|
-
return
|
352
|
-
else
|
353
|
-
return {:
|
354
|
+
return Net::HTTPOK.new('HTTP/1.1', 200, 'Address Deleted').to_json
|
355
|
+
else
|
356
|
+
return {:error => delete_ip['message']}.to_json
|
354
357
|
end
|
355
358
|
rescue Errno::ECONNREFUSED, Errno::ECONNRESET
|
356
359
|
logger.debug(errors[:no_connection])
|
@@ -39,6 +39,9 @@ module Proxy::Phpipam
|
|
39
39
|
|
40
40
|
def get_subnet_by_section(cidr, section_name, include_id = true)
|
41
41
|
section = JSON.parse(get_section(section_name))
|
42
|
+
|
43
|
+
return {:error => "No section #{URI.unescape(section_name)} found"}.to_json if no_section_found?(section)
|
44
|
+
|
42
45
|
subnets = JSON.parse(get_subnets(section['data']['id'], include_id))
|
43
46
|
subnet_id = nil
|
44
47
|
|
@@ -47,12 +50,12 @@ module Proxy::Phpipam
|
|
47
50
|
subnet_id = subnet['id'] if subnet_cidr == cidr
|
48
51
|
end
|
49
52
|
|
50
|
-
return {
|
51
|
-
|
53
|
+
return {}.to_json if subnet_id.nil?
|
54
|
+
|
52
55
|
response = get("subnets/#{subnet_id.to_s}/")
|
53
56
|
json_body = JSON.parse(response.body)
|
54
57
|
json_body['data'] = filter_hash(json_body['data'], [:id, :subnet, :mask, :description]) if json_body['data']
|
55
|
-
json_body = filter_hash(json_body, [:
|
58
|
+
json_body = filter_hash(json_body, [:data, :error, :message])
|
56
59
|
response.body = json_body.to_json
|
57
60
|
response.header['Content-Length'] = json_body.to_s.length
|
58
61
|
response.body
|
@@ -61,8 +64,9 @@ module Proxy::Phpipam
|
|
61
64
|
def get_subnet_by_cidr(cidr)
|
62
65
|
response = get("subnets/cidr/#{cidr.to_s}")
|
63
66
|
json_body = JSON.parse(response.body)
|
67
|
+
return {}.to_json if json_body['data'].nil?
|
64
68
|
json_body['data'] = filter_fields(json_body, [:id, :subnet, :description, :mask])[0]
|
65
|
-
json_body = filter_hash(json_body, [:
|
69
|
+
json_body = filter_hash(json_body, [:data, :error, :message])
|
66
70
|
response.body = json_body.to_json
|
67
71
|
response.header['Content-Length'] = json_body.to_s.length
|
68
72
|
response.body
|
@@ -72,7 +76,7 @@ module Proxy::Phpipam
|
|
72
76
|
response = get("sections/#{section_name}/")
|
73
77
|
json_body = JSON.parse(response.body)
|
74
78
|
json_body['data'] = filter_hash(json_body['data'], [:id, :name, :description]) if json_body['data']
|
75
|
-
json_body = filter_hash(json_body, [:
|
79
|
+
json_body = filter_hash(json_body, [:data, :error, :message])
|
76
80
|
response.body = json_body.to_json
|
77
81
|
response.header['Content-Length'] = json_body.to_s.length
|
78
82
|
response.body
|
@@ -82,7 +86,7 @@ module Proxy::Phpipam
|
|
82
86
|
response = get('sections/')
|
83
87
|
json_body = JSON.parse(response.body)
|
84
88
|
json_body['data'] = filter_fields(json_body, [:id, :name, :description]) if json_body['data']
|
85
|
-
json_body = filter_hash(json_body, [:
|
89
|
+
json_body = filter_hash(json_body, [:data, :error, :message])
|
86
90
|
response.body = json_body.to_json
|
87
91
|
response.header['Content-Length'] = json_body.to_s.length
|
88
92
|
response.body
|
@@ -94,7 +98,7 @@ module Proxy::Phpipam
|
|
94
98
|
fields.push(:id) if include_id
|
95
99
|
json_body = JSON.parse(response.body)
|
96
100
|
json_body['data'] = filter_fields(json_body, fields) if json_body['data']
|
97
|
-
json_body = filter_hash(json_body, [:
|
101
|
+
json_body = filter_hash(json_body, [:data, :error, :message])
|
98
102
|
response.body = json_body.to_json
|
99
103
|
response.header['Content-Length'] = json_body.to_s.length
|
100
104
|
response.body
|
@@ -104,29 +108,29 @@ module Proxy::Phpipam
|
|
104
108
|
response = get("subnets/#{subnet_id.to_s}/addresses/#{ip}/")
|
105
109
|
json_body = JSON.parse(response.body)
|
106
110
|
json_body['data'] = filter_fields(json_body, [:ip]) if json_body['data']
|
107
|
-
json_body = filter_hash(json_body, [:
|
111
|
+
json_body = filter_hash(json_body, [:data, :error, :message])
|
108
112
|
response.body = json_body.to_json
|
109
113
|
response.header['Content-Length'] = json_body.to_s.length
|
110
|
-
response
|
114
|
+
response
|
111
115
|
end
|
112
116
|
|
113
117
|
def add_ip_to_subnet(ip, subnet_id, desc)
|
114
118
|
data = {:subnetId => subnet_id, :ip => ip, :description => desc}
|
115
119
|
response = post('addresses/', data)
|
116
120
|
json_body = JSON.parse(response.body)
|
117
|
-
json_body = filter_hash(json_body, [:
|
121
|
+
json_body = filter_hash(json_body, [:error, :message])
|
118
122
|
response.body = json_body.to_json
|
119
123
|
response.header['Content-Length'] = json_body.to_s.length
|
120
|
-
response
|
124
|
+
response
|
121
125
|
end
|
122
126
|
|
123
127
|
def delete_ip_from_subnet(ip, subnet_id)
|
124
128
|
response = delete("addresses/#{ip}/#{subnet_id.to_s}/")
|
125
129
|
json_body = JSON.parse(response.body)
|
126
|
-
json_body = filter_hash(json_body, [:
|
130
|
+
json_body = filter_hash(json_body, [:error, :message])
|
127
131
|
response.body = json_body.to_json
|
128
132
|
response.header['Content-Length'] = json_body.to_s.length
|
129
|
-
response
|
133
|
+
response
|
130
134
|
end
|
131
135
|
|
132
136
|
def get_next_ip(subnet_id, mac, cidr, section_name)
|
@@ -136,7 +140,7 @@ module Proxy::Phpipam
|
|
136
140
|
@@ip_cache[section.to_sym] = {} if @@ip_cache[section.to_sym].nil?
|
137
141
|
subnet_hash = @@ip_cache[section.to_sym][cidr.to_sym]
|
138
142
|
|
139
|
-
return {:
|
143
|
+
return {:error => json_body['message']}.to_json if json_body['message']
|
140
144
|
|
141
145
|
if subnet_hash && subnet_hash.key?(mac.to_sym)
|
142
146
|
json_body['data'] = @@ip_cache[section_name.to_sym][cidr.to_sym][mac.to_sym][:ip]
|
@@ -152,13 +156,13 @@ module Proxy::Phpipam
|
|
152
156
|
next_ip = find_new_ip(subnet_id, new_ip, mac, cidr, section)
|
153
157
|
end
|
154
158
|
|
155
|
-
return {:
|
156
|
-
return {:
|
159
|
+
return {:error => "Unable to find another available IP address in subnet #{cidr}"}.to_json if next_ip.nil?
|
160
|
+
return {: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)
|
157
161
|
|
158
162
|
json_body['data'] = next_ip
|
159
163
|
end
|
160
164
|
|
161
|
-
json_body = {:
|
165
|
+
json_body = {:data => json_body['data']}
|
162
166
|
|
163
167
|
response.body = json_body.to_json
|
164
168
|
response.header['Content-Length'] = json_body.to_s.length
|
@@ -261,7 +265,7 @@ module Proxy::Phpipam
|
|
261
265
|
|
262
266
|
loop do
|
263
267
|
new_ip = increment_ip(temp_ip)
|
264
|
-
verify_ip = JSON.parse(ip_exists(new_ip, subnet_id))
|
268
|
+
verify_ip = JSON.parse(ip_exists(new_ip, subnet_id).body)
|
265
269
|
|
266
270
|
# If new IP doesn't exist in IPAM and not in the cache
|
267
271
|
if ip_not_found_in_ipam?(verify_ip) && !ip_exists_in_cache(new_ip, cidr, mac, section_name)
|
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.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-19 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
|