From cfd083dae03aec21b0a3b84ddf9621a85e2160ff Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Tue, 21 Dec 2021 22:07:21 -0600 Subject: [PATCH 1/2] allow for custom filters instead of just 'isPool' (#3) --- src/main/python/get_ip_ranges/source.py | 10 ++-- src/main/resources/endpoint-schema.json | 65 +++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/main/python/get_ip_ranges/source.py b/src/main/python/get_ip_ranges/source.py index 993ba0b..e29824d 100644 --- a/src/main/python/get_ip_ranges/source.py +++ b/src/main/python/get_ip_ranges/source.py @@ -55,7 +55,9 @@ def do_get_ip_ranges(self, auth_credentials, cert): password = auth_credentials["privateKey"] hostname = self.inputs["endpoint"]["endpointProperties"]["hostName"] apiAppId = self.inputs["endpoint"]["endpointProperties"]["apiAppId"] - filterPool = self.inputs["endpoint"]["endpointProperties"]["filterPool"] + enableFilter = self.inputs["endpoint"]["endpointProperties"]["enableFilter"] + filterField = self.inputs["endpoint"]["endpointProperties"]["filterField"] + filterValue = self.inputs["endpoint"]["endpointProperties"]["filterValue"] uri = f'https://{hostname}/api/{apiAppId}/' auth = (username, password) @@ -64,10 +66,12 @@ def do_get_ip_ranges(self, auth_credentials, cert): # Request list of subnets subnet_uri = f'{uri}/subnets/' - if filterPool == "true": - queryFilter = 'filter_by=isPool&filter_value=1' + if enableFilter == "true": + queryFilter = f'filter_by={filterField}&filter_value={filterValue}' + logging.info(f"Searching for subnets matching filter: {queryFilter}") else: queryFilter = '' + logging.info(f"Searching for all known subnets") ipRanges = [] subnets = requests.get(f'{subnet_uri}?{queryFilter}', headers=token, verify=cert) subnets = subnets.json()['data'] diff --git a/src/main/resources/endpoint-schema.json b/src/main/resources/endpoint-schema.json index 8ca5a2d..4641ede 100644 --- a/src/main/resources/endpoint-schema.json +++ b/src/main/resources/endpoint-schema.json @@ -25,8 +25,32 @@ "display":"textField" }, { - "id":"filterPool", + "id":"enableFilter", "display": "checkbox" + }, + { + "id":"filterField", + "display":"textField", + "state":{ + "visible":[{ + "equals":{ + "enableFilter":true + }, + "value":true + }] + } + }, + { + "id":"filterValue", + "display":"textField", + "state":{ + "visible":[{ + "equals":{ + "enableFilter":true + }, + "value":true + }] + } } ] } @@ -71,14 +95,47 @@ "required":true } }, - "filterPool":{ + "enableFilter":{ "type":{ "dataType":"boolean" }, - "label":"Only find ranges marked as Pools", - "signpost":"If enabled, vRA will only retrieve subnets marked as pools in phpIPAM", + "label":"Subnets must match filter", + "signpost":"Enable to only retrieve subnets matching a designated filter. Useful for limiting the discovery scope to subnets which should be owned/managed by vRA.", "default":true + }, + "filterField":{ + "type":{ + "dataType":"string" + }, + "label":"Field for filter", + "signpost":"'isPool' to match subnets marked as IP Pools. See the phpIPAM API documentation.", + "constraints":{ + "required":[{ + "equals":{ + "enableFilter":true + }, + "value":true + }] + }, + "default":"isPool" + }, + "filterValue":{ + "type":{ + "dataType":"string" + }, + "label":"Value for filter", + "signpost":"'1' to match filters which are true", + "constraints":{ + "required":[{ + "equals":{ + "enableFilter":true + }, + "value":true + }] + }, + "default":"1" } + }, "options":{ From c1c197e73f26607de0d50e9ef3f177c46fcdc417 Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Tue, 21 Dec 2021 22:09:38 -0600 Subject: [PATCH 2/2] increment version: v1.0.7 --- pom.xml | 2 +- src/main/resources/CHANGELOG.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b8237cb..40306cd 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ conditions of the subcomponent's license, as noted in the LICENSE file. phpIPAM phpIPAM integration for vRA - 1.0.6 + 1.0.7 false true diff --git a/src/main/resources/CHANGELOG.md b/src/main/resources/CHANGELOG.md index 0407d6f..92ed0d7 100644 --- a/src/main/resources/CHANGELOG.md +++ b/src/main/resources/CHANGELOG.md @@ -1,3 +1,6 @@ +# v1.0.7 +Enable optional custom subnet filter + # v1.0.6 Fix for [an error](https://github.com/jbowdre/phpIPAM-for-vRA8/issues/3) when a subnet doesn't have a defined gateway.