From c7be21c3076ef5633c2f81686c47a30a889782c8 Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Fri, 15 Jan 2021 11:36:19 -0600 Subject: [PATCH] only get subnets marked as pools; capture gatewayAddress and dnsServerAddresses --- src/main/python/get_ip_ranges/source.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/python/get_ip_ranges/source.py b/src/main/python/get_ip_ranges/source.py index 59211c3..954ebae 100644 --- a/src/main/python/get_ip_ranges/source.py +++ b/src/main/python/get_ip_ranges/source.py @@ -63,8 +63,8 @@ def do_get_ip_ranges(self, auth_credentials, cert): # Request list of subnets subnet_uri = f'{uri}/subnets/' ipRanges = [] - req = requests.get(subnet_uri, headers=token, verify=cert) - subnets = req.json()['data'] + subnet_req = requests.get(f'{subnet_uri}?filter_by=isPool&filter_value=1', headers=token, verify=cert) + subnets = subnet_req.json()['data'] for subnet in subnets: ipRange = {} ipRange['id'] = str(subnet['id']) @@ -76,6 +76,10 @@ def do_get_ip_ranges(self, auth_credentials, cert): ipRange['startIPAddress'] = str(network[10]) ipRange['endIPAddress'] = str(network[-6]) ipRange['subnetPrefixLength'] = str(subnet['mask']) + ipRange['dnsServerAddresses'] = [server.strip() for server in str(subnet['nameservers']['namesrv1']).split(';')] + gw_req = requests.get(f"{subnet_uri}/{subnet['id']}/addresses/?filter_by=is_gateway&filter_value=1", headers=token, verify=cert) + if gw_req.status_code == 200: + ipRange['gatewayAddress'] = gw_req.json()['data'][0]['ip'] logging.debug(ipRange) ipRanges.append(ipRange)