mirror of
https://github.com/jbowdre/phpIPAM-for-vRA8.git
synced 2024-11-21 06:22:19 +00:00
allow for custom filters instead of just 'isPool' (#3)
This commit is contained in:
parent
ec67aff7fa
commit
cfd083dae0
2 changed files with 68 additions and 7 deletions
|
@ -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']
|
||||
|
|
|
@ -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 <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":{
|
||||
|
||||
|
|
Loading…
Reference in a new issue