smart_proxy_ipam 0.0.5 → 0.0.7

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: f64f77c875cf2954bfe2d9fb2e1c56e1848e402ec8259959382771da8cd7158b
4
- data.tar.gz: a4e3900fd2ad8a2ec16e9ab3887dd6412ce567b16f7cdb98278407c80add8e9c
3
+ metadata.gz: be6ae52f679c0d7be23248d26f179a730d0157569a07a050c72c45db0aeec2eb
4
+ data.tar.gz: 5a1dbe01a004a626b8e0ece2cfee6b362a96184df6ca37e2245e11986c8f6140
5
5
  SHA512:
6
- metadata.gz: 3608be9d60dda80356bdf9e9c59f79cf0edcd1c69210cb7c10aa818237ec85e1485e8fd12d2ee1c1d527ca3ab926d1090ef20c2a6bc4faf8f2c4b262f86df44c
7
- data.tar.gz: a99d59aab8ce7b3f1a1b6d4b90e861fef90435c9071e0b42d3f7863834a660050d8e96af471473b4e6f0a0b8db8b1f1d212502e01ac80073e79a1542d731fff6
6
+ metadata.gz: d85452528e492750756f1d3c0347301c2d80749f85229713d9ea2f56eb70c5edf72935d40877f2f486767d354a1fea70dfe0a618e32bf0674aed755de8235450
7
+ data.tar.gz: e6155d1c91673dbaba336d90280862f4ae220ec2d46079300557ce6ee6826b572ec2e8fca6bf13914e9d28a51b2ab1734648ef9f599ea724f8f006ccd715a484
@@ -12,7 +12,7 @@ module Proxy::Phpipam
12
12
 
13
13
  get '/providers' do
14
14
  content_type :json
15
- {ipam_providers: ['phpIPAM']}.to_json
15
+ {:ipam_providers => ['phpIPAM']}.to_json
16
16
  end
17
17
 
18
18
  # Gets the next available IP address based on a given subnet
@@ -22,7 +22,7 @@ module Proxy::Phpipam
22
22
  # Examples:
23
23
  # Response if success:
24
24
  # {"cidr":"100.20.20.0/24","next_ip":"100.20.20.11"}
25
- # Response if error:
25
+ # Response if :error =>
26
26
  # {"error":"The specified subnet does not exist in phpIPAM."}
27
27
  get '/next_ip' do
28
28
  content_type :json
@@ -31,26 +31,26 @@ module Proxy::Phpipam
31
31
  cidr = params[:cidr]
32
32
 
33
33
  if not cidr
34
- return {error: "A 'cidr' parameter for the subnet must be provided(e.g. 100.10.10.0/24)"}.to_json
34
+ return {:error => "A 'cidr' parameter for the subnet must be provided(e.g. 100.10.10.0/24)"}.to_json
35
35
  end
36
36
 
37
37
  phpipam_client = PhpipamClient.new
38
38
  response = phpipam_client.get_subnet(cidr)
39
39
 
40
40
  if response['message'] && response['message'].downcase == "no subnets found"
41
- return {error: "The specified subnet does not exist in External IPAM."}.to_json
41
+ return {:error => "The specified subnet does not exist in External IPAM."}.to_json
42
42
  end
43
43
 
44
44
  subnet_id = JSON.parse(response)[0]['id']
45
45
  response = phpipam_client.get_next_ip(subnet_id)
46
46
 
47
47
  if response['message'] && response['message'].downcase == "no free addresses found"
48
- return {error: "There are no more free addresses in subnet #{cidr}"}.to_json
48
+ return {:error => "There are no more free addresses in subnet #{cidr}"}.to_json
49
49
  end
50
50
 
51
51
  {cidr: cidr, next_ip: response['data']}.to_json
52
52
  rescue Errno::ECONNREFUSED
53
- return {error: "Unable to connect to External IPAM server"}.to_json
53
+ return {:error => "Unable to connect to External IPAM server"}.to_json
54
54
  end
55
55
  end
56
56
 
@@ -80,14 +80,14 @@ module Proxy::Phpipam
80
80
  cidr = params[:cidr]
81
81
 
82
82
  if not cidr
83
- return {error: "A 'cidr' parameter for the subnet must be provided(e.g. 100.10.10.0/24)"}.to_json
83
+ return {:error => "A 'cidr' parameter for the subnet must be provided(e.g. 100.10.10.0/24)"}.to_json
84
84
  end
85
85
 
86
86
  phpipam_client = PhpipamClient.new
87
87
  subnet = phpipam_client.get_subnet(cidr)
88
88
  subnet.to_json
89
89
  rescue Errno::ECONNREFUSED
90
- return {error: "Unable to connect to External IPAM server"}.to_json
90
+ return {:error => "Unable to connect to External IPAM server"}.to_json
91
91
  end
92
92
  end
93
93
 
@@ -101,7 +101,7 @@ module Proxy::Phpipam
101
101
  # "permissions":"[]","strictMode":"1","subnetOrdering":"default","order":null,
102
102
  # "editDate":"2019-04-19 21:49:55","showVLAN":"1","showVRF":"1","showSupernetOnly":"1","DNS":null}]
103
103
  # ]
104
- # Response if error:
104
+ # Response if :error =>
105
105
  # {"error":"Unable to connect to phpIPAM server"}
106
106
  get '/sections' do
107
107
  content_type :json
@@ -111,7 +111,7 @@ module Proxy::Phpipam
111
111
  sections = phpipam_client.get_sections
112
112
  sections.to_json
113
113
  rescue Errno::ECONNREFUSED
114
- return {error: "Unable to connect to External IPAM server"}.to_json
114
+ return {:error => "Unable to connect to External IPAM server"}.to_json
115
115
  end
116
116
  end
117
117
 
@@ -168,7 +168,7 @@ module Proxy::Phpipam
168
168
  # ],
169
169
  # "time":0.012
170
170
  # }
171
- # Response if error:
171
+ # Response if :error =>
172
172
  # {"error":"Unable to connect to phpIPAM server"}
173
173
  get '/sections/:section_id/subnets' do
174
174
  content_type :json
@@ -177,14 +177,14 @@ module Proxy::Phpipam
177
177
  section_id = params[:section_id]
178
178
 
179
179
  if not section_id
180
- return {error: "A 'section_id' must be provided"}.to_json
180
+ return {:error => "A 'section_id' must be provided"}.to_json
181
181
  end
182
182
 
183
183
  phpipam_client = PhpipamClient.new
184
184
  subnets = phpipam_client.get_subnets(section_id)
185
185
  subnets.to_json
186
186
  rescue Errno::ECONNREFUSED
187
- return {error: "Unable to connect to External IPAM server"}.to_json
187
+ return {:error => "Unable to connect to External IPAM server"}.to_json
188
188
  end
189
189
  end
190
190
 
@@ -205,20 +205,20 @@ module Proxy::Phpipam
205
205
  cidr = params[:cidr]
206
206
  ip = params[:ip]
207
207
 
208
- return {error: "Missing 'cidr' parameter. A CIDR IPv4 address must be provided(e.g. 100.10.10.0/24)"}.to_json if not cidr
209
- return {error: "Missing 'ip' parameter. An IPv4 address must be provided(e.g. 100.10.10.22)"}.to_json if not ip
208
+ return {:error => "Missing 'cidr' parameter. A CIDR IPv4 address must be provided(e.g. 100.10.10.0/24)"}.to_json if not cidr
209
+ return {:error => "Missing 'ip' parameter. An IPv4 address must be provided(e.g. 100.10.10.22)"}.to_json if not ip
210
210
 
211
211
  phpipam_client = PhpipamClient.new
212
212
  subnet = phpipam_client.get_subnet(cidr)
213
213
 
214
214
  if subnet['message'] && subnet['message'].downcase == "no subnets found"
215
- return {error: "The specified subnet does not exist in External IPAM."}.to_json
215
+ return {:error => "The specified subnet does not exist in External IPAM."}.to_json
216
216
  end
217
217
 
218
218
  subnet_id = JSON.parse(subnet)[0]['id']
219
219
  phpipam_client.ip_exists(ip, subnet_id)
220
220
  rescue Errno::ECONNREFUSED
221
- return {error: "Unable to connect to External IPAM server"}.to_json
221
+ return {:error => "Unable to connect to External IPAM server"}.to_json
222
222
  end
223
223
  end
224
224
 
@@ -231,7 +231,7 @@ module Proxy::Phpipam
231
231
  # Examples:
232
232
  # Response if success:
233
233
  # {"message":"IP 100.10.10.123 added to subnet 100.10.10.0/24 successfully."}
234
- # Response if error:
234
+ # Response if :error =>
235
235
  # {"error":"The specified subnet does not exist in phpIPAM."}
236
236
  post '/add_ip_to_subnet' do
237
237
  content_type :json
@@ -240,23 +240,23 @@ module Proxy::Phpipam
240
240
  cidr = params[:cidr]
241
241
  ip = params[:ip]
242
242
 
243
- return {error: "Missing 'cidr' parameter. A CIDR IPv4 address must be provided(e.g. 100.10.10.0/24)"}.to_json if not cidr
244
- return {error: "Missing 'ip' parameter. An IPv4 address must be provided(e.g. 100.10.10.22)"}.to_json if not ip
243
+ return {:error => "Missing 'cidr' parameter. A CIDR IPv4 address must be provided(e.g. 100.10.10.0/24)"}.to_json if not cidr
244
+ return {:error => "Missing 'ip' parameter. An IPv4 address must be provided(e.g. 100.10.10.22)"}.to_json if not ip
245
245
 
246
246
  phpipam_client = PhpipamClient.new
247
247
  response = phpipam_client.get_subnet(cidr)
248
248
 
249
249
  if response['message'] && response['message'].downcase == "no subnets found"
250
- return {error: "The specified subnet does not exist in External IPAM."}.to_json
250
+ return {:error => "The specified subnet does not exist in External IPAM."}.to_json
251
251
  end
252
252
 
253
253
  subnet_id = JSON.parse(response)[0]['id']
254
254
 
255
255
  phpipam_client.add_ip_to_subnet(ip, subnet_id, 'Address auto added by Foreman')
256
256
 
257
- {message: "IP #{ip} added to subnet #{cidr} successfully."}.to_json
257
+ {:message => "IP #{ip} added to subnet #{cidr} successfully."}.to_json
258
258
  rescue Errno::ECONNREFUSED
259
- return {error: "Unable to connect to External IPAM server"}.to_json
259
+ return {:error => "Unable to connect to External IPAM server"}.to_json
260
260
  end
261
261
  end
262
262
 
@@ -268,7 +268,7 @@ module Proxy::Phpipam
268
268
  # Example:
269
269
  # Response if success:
270
270
  # {"code": 200, "success": true, "message": "Address deleted", "time": 0.017}
271
- # Response if error:
271
+ # Response if :error =>
272
272
  # {"code": 404, "success": 0, "message": "Address does not exist", "time": 0.008}
273
273
  post '/delete_ip_from_subnet' do
274
274
  content_type :json
@@ -277,23 +277,23 @@ module Proxy::Phpipam
277
277
  cidr = params[:cidr]
278
278
  ip = params[:ip]
279
279
 
280
- return {error: "Missing 'cidr' parameter. A CIDR IPv4 address must be provided(e.g. 100.10.10.0/24)"}.to_json if not cidr
281
- return {error: "Missing 'ip' parameter. An IPv4 address must be provided(e.g. 100.10.10.22)"}.to_json if not ip
280
+ return {:error => "Missing 'cidr' parameter. A CIDR IPv4 address must be provided(e.g. 100.10.10.0/24)"}.to_json if not cidr
281
+ return {:error => "Missing 'ip' parameter. An IPv4 address must be provided(e.g. 100.10.10.22)"}.to_json if not ip
282
282
 
283
283
  phpipam_client = PhpipamClient.new
284
284
  response = phpipam_client.get_subnet(cidr)
285
285
 
286
286
  if response['message'] && response['message'].downcase == "no subnets found"
287
- return {error: "The specified subnet does not exist in External IPAM."}.to_json
287
+ return {:error => "The specified subnet does not exist in External IPAM."}.to_json
288
288
  end
289
289
 
290
290
  subnet_id = JSON.parse(response)[0]['id']
291
291
 
292
292
  phpipam_client.delete_ip_from_subnet(ip, subnet_id)
293
293
 
294
- {message: "IP #{ip} deleted from subnet #{cidr} successfully."}.to_json
294
+ {:message => "IP #{ip} deleted from subnet #{cidr} successfully."}.to_json
295
295
  rescue Errno::ECONNREFUSED
296
- return {error: "Unable to connect to External IPAM server"}.to_json
296
+ return {:error => "Unable to connect to External IPAM server"}.to_json
297
297
  end
298
298
  end
299
299
 
@@ -9,7 +9,11 @@ module Proxy::Phpipam
9
9
  class PhpipamClient
10
10
  def initialize
11
11
  conf = Proxy::Ipam.get_config[:phpipam]
12
- @phpipam_config = {url: conf[:url], user: conf[:user], password: conf[:password]}
12
+ @phpipam_config = {
13
+ :url => conf[:url],
14
+ :user => conf[:user],
15
+ :password => conf[:password]
16
+ }
13
17
  @api_base = "#{conf[:url]}/api/#{conf[:user]}/"
14
18
  @token = nil
15
19
  end
@@ -25,7 +29,7 @@ module Proxy::Phpipam
25
29
 
26
30
  if subnets
27
31
  if subnets['message'] && subnets['message'].downcase == 'no subnets found'
28
- return {"message": "no subnets found"}.to_json
32
+ return {:message => "no subnets found"}.to_json
29
33
  else
30
34
  # Only return the relevant fields to Foreman
31
35
  subnets['data'].each do |subnet|
@@ -43,7 +47,7 @@ module Proxy::Phpipam
43
47
  end
44
48
 
45
49
  def add_ip_to_subnet(ip, subnet_id, desc)
46
- data = {'subnetId': subnet_id, 'ip': ip, 'description': desc}
50
+ data = {:subnetId => subnet_id, :ip => ip, :description => desc}
47
51
  post('addresses/', data)
48
52
  end
49
53
 
@@ -91,14 +95,14 @@ module Proxy::Phpipam
91
95
  # the ip existence on an empty subnet returns a malformed response from phpIPAM, containing
92
96
  # HTML in the JSON response.
93
97
  if usage['data']['used'] == "0"
94
- return {ip: ip, exists: false}.to_json
98
+ return {:ip => ip, :exists => false}.to_json
95
99
  else
96
100
  response = get("subnets/#{subnet_id.to_s}/addresses/#{ip}/")
97
101
 
98
102
  if response && response['message'] && response['message'].downcase == 'no addresses found'
99
- return {ip: ip, exists: false}.to_json
103
+ return {:ip => ip, :exists => false}.to_json
100
104
  else
101
- return {ip: ip, exists: true}.to_json
105
+ return {:ip => ip, :exists => true}.to_json
102
106
  end
103
107
  end
104
108
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Proxy
3
3
  module Ipam
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.7'
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.5
4
+ version: 0.0.7
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-07-10 00:00:00.000000000 Z
11
+ date: 2019-07-11 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