From 4ec122748075a8393d9b0e6bdd4a4773735bddcf Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 8 Apr 2020 15:24:48 +0000 Subject: [server/external-backends] Infoblox: Instead of only getting the next 20 free IPs, GET THEM ALL! --- .../external-backends/backends/infoblox-backend.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'server') 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'}]}) -- cgit v1.2.3-55-g7522