summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2020-04-08 17:24:48 +0200
committerJannik Schönartz2020-04-08 17:24:48 +0200
commit4ec122748075a8393d9b0e6bdd4a4773735bddcf (patch)
treebb2d10006f20c73214205ad4c0a390d896cdc656
parent[server/log] Add log when setting dhcp ip in the client registration failed (diff)
downloadbas-4ec122748075a8393d9b0e6bdd4a4773735bddcf.tar.gz
bas-4ec122748075a8393d9b0e6bdd4a4773735bddcf.tar.xz
bas-4ec122748075a8393d9b0e6bdd4a4773735bddcf.zip
[server/external-backends] Infoblox: Instead of only getting the next 20 free IPs, GET THEM ALL!
-rw-r--r--server/lib/external-backends/backends/infoblox-backend.js20
1 files changed, 15 insertions, 5 deletions
diff --git a/server/lib/external-backends/backends/infoblox-backend.js b/server/lib/external-backends/backends/infoblox-backend.js
index 9cedfb7..6c80392 100644
--- a/server/lib/external-backends/backends/infoblox-backend.js
+++ b/server/lib/external-backends/backends/infoblox-backend.js
@@ -79,9 +79,15 @@ class InfobloxBackend extends ExternalBackends {
let host = JSON.parse(await ipam.getHost(ipv4))[0]
if (!host) return { error: 'HOST_NOT_FOUND' }
if (host.lease_state && host.lease_state === 'ACTIVE') {
- // If leased return the next 20 free ips of the subnet.
const dhcpNetwork = JSON.parse(await ipam.getNetworkFromIp(ipv4))
- const nextIps = await ipam.getNext(dhcpNetwork[0]._ref, 20)
+
+ // If leased return the next 20 free ips of the subnet. API method is limited to 20 ...
+ // const nextIps = await ipam.getNext(dhcpNetwork[0]._ref, 20)
+
+ // Instead of only getting the next 20 ips, GET THEM ALL
+ let nextIps = JSON.parse(await ipam.getIpsFromSubnet(dhcpNetwork[0].network))
+ nextIps = nextIps.filter(x => x.status === 'UNUSED').map(y => y.ip_address)
+
return { leased: true, nextIps: nextIps }
}
@@ -269,7 +275,8 @@ class InfobloxBackend extends ExternalBackends {
result['getHost.43'] = JSON.parse(await ipam.getHost('10.21.11.43'))
// Get ips from subnet
- // result["getIpsFromSubnet"] = JSON.parse(await ipam.getIpsFromSubnet('10.21.9.0/24'))
+ result['getIpsFromSubnet'] = JSON.parse(await ipam.getIpsFromSubnet('10.21.9.0/24'))
+ result['getIpsFromSubnet'] = result['getIpsFromSubnet'].filter(x => x.status === 'UNUSED').map(y => y.ip_address)
// List records
// result["list"] = JSON.parse(await ipam.list('record:host'))
@@ -278,10 +285,13 @@ class InfobloxBackend extends ExternalBackends {
result['getDomain'] = await ipam.getDomain()
// Get next ip
- // result["getNextIp.1"] = await ipam.getNext(result["getNetworkFromIp"][0]._ref, 1)
+ result['getNextIp.1'] = await ipam.getNext(result['getNetworkFromIp'][0]._ref, 1)
// Get next 20 ips
- // result["getNextIp.20"] = await ipam.getNext(result["getNetworkFromIp"][0]._ref, 20)
+ result['getNextIp.20'] = await ipam.getNext(result['getNetworkFromIp'][0]._ref, 20)
+
+ // Get all unsued ips
+ // result["getUnusedIps"] = await ipam.getNext(result["getNetworkFromIp"][0]._ref, 20)
// Create Host
// result['createHost'] = await ipam.create('record:host?_return_fields%2B=ipv4addrs&_return_as_object=1', {'name': 'wapiTest2.lp.privat', 'ipv4addrs': [{'ipv4addr': '10.21.9.218', 'mac': 'aa:bb:cc:11:22:21'}]})