enable optional custom subnet filter

This commit is contained in:
John Bowdre 2021-12-21 22:19:39 -06:00
commit 6a042450f9
4 changed files with 72 additions and 8 deletions

View file

@ -23,7 +23,7 @@ conditions of the subcomponent's license, as noted in the LICENSE file.
<properties> <properties>
<provider.name>phpIPAM</provider.name> <provider.name>phpIPAM</provider.name>
<provider.description>phpIPAM integration for vRA</provider.description> <provider.description>phpIPAM integration for vRA</provider.description>
<provider.version>1.0.6</provider.version> <provider.version>1.0.7</provider.version>
<provider.supportsAddressSpaces>false</provider.supportsAddressSpaces> <provider.supportsAddressSpaces>false</provider.supportsAddressSpaces>
<provider.supportsUpdateRecord>true</provider.supportsUpdateRecord> <provider.supportsUpdateRecord>true</provider.supportsUpdateRecord>

View file

@ -55,7 +55,9 @@ def do_get_ip_ranges(self, auth_credentials, cert):
password = auth_credentials["privateKey"] password = auth_credentials["privateKey"]
hostname = self.inputs["endpoint"]["endpointProperties"]["hostName"] hostname = self.inputs["endpoint"]["endpointProperties"]["hostName"]
apiAppId = self.inputs["endpoint"]["endpointProperties"]["apiAppId"] 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}/' uri = f'https://{hostname}/api/{apiAppId}/'
auth = (username, password) auth = (username, password)
@ -64,10 +66,12 @@ def do_get_ip_ranges(self, auth_credentials, cert):
# Request list of subnets # Request list of subnets
subnet_uri = f'{uri}/subnets/' subnet_uri = f'{uri}/subnets/'
if filterPool == "true": if enableFilter == "true":
queryFilter = 'filter_by=isPool&filter_value=1' queryFilter = f'filter_by={filterField}&filter_value={filterValue}'
logging.info(f"Searching for subnets matching filter: {queryFilter}")
else: else:
queryFilter = '' queryFilter = ''
logging.info(f"Searching for all known subnets")
ipRanges = [] ipRanges = []
subnets = requests.get(f'{subnet_uri}?{queryFilter}', headers=token, verify=cert) subnets = requests.get(f'{subnet_uri}?{queryFilter}', headers=token, verify=cert)
subnets = subnets.json()['data'] subnets = subnets.json()['data']

View file

@ -1,3 +1,6 @@
# v1.0.7
Enable optional custom subnet filter
# v1.0.6 # 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. Fix for [an error](https://github.com/jbowdre/phpIPAM-for-vRA8/issues/3) when a subnet doesn't have a defined gateway.

View file

@ -25,8 +25,32 @@
"display":"textField" "display":"textField"
}, },
{ {
"id":"filterPool", "id":"enableFilter",
"display": "checkbox" "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 "required":true
} }
}, },
"filterPool":{ "enableFilter":{
"type":{ "type":{
"dataType":"boolean" "dataType":"boolean"
}, },
"label":"Only find ranges marked as Pools", "label":"Subnets must match filter",
"signpost":"If enabled, vRA will only retrieve subnets marked as pools in phpIPAM", "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 "default":true
},
"filterField":{
"type":{
"dataType":"string"
},
"label":"Field for filter",
"signpost":"'isPool' to match subnets marked as IP Pools. See the <a href='https://phpipam.net/api/api_documentation/'>phpIPAM API documentation</a>.",
"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":{ "options":{