VMware Aria Automation Tools

 View Only

 iaas/api/networks endpoint tag filters not working but iaas/api/fabric-networks seem to work

Jump to  Best Answer
qc4vmware's profile image
qc4vmware posted Jul 29, 2024 03:07 PM

Just curious if anyone knows if tag filtering is not supported on the iaas/api/networks endpoint?  If I use the same filter on tags on the fabric-networks endpoint it seems to work.  Other filters work on the "networks" endpoint like name for example but the tags return zero hits everytime.  No error but no results.  Seems like a bug?  Would be cool if someone can test in their environment and confirm.

Ozhk's profile image
Ozhk  Best Answer

Hi,

Sorry, I see I have omitted the asterisk yesterday, I guess it was too late and too hot ;)

That should work in your case:

/iaas/api/networks?$top=100&$skip=0&$filter=expandedTags.item.tag%20eq%20'placement*TESTIT'

if your key=placement

value=TESTIT

For me it works on vra 8.16.2.

If you have a different version of vra can you test it please and let me know, I am curious.

Kind regards,

O.

Stefan Schnell's profile image
Stefan Schnell

Hello @qc4vmware,

as far as I can say the filter parameter works with iaas/api/networks. I tried it with the following Python approach and it delivers the expected result.

import json
import ssl
import urllib.request

def getAllNetworks(bearerToken):
    returnValue = {}
    try:
        requestNetworks = urllib.request.Request(
            url = "https://myUrl/iaas/api/networks?apiVersion=2021-07-15&$filter=name%20eq%20'*AntZ*'"
        )
        requestNetworks.add_header(
            "Authorization", "Bearer " + bearerToken
        )
        requestNetworks.add_header(
            "Content-Type", "application/json"
        )
        responseNetworks = urllib.request.urlopen(
            requestNetworks,
            context = ssl._create_unverified_context()
        )
        if responseNetworks.getcode() == 200:
            returnValue = json.loads(responseNetworks.read())
    except Exception as err:
        raise Exception("An error occurred at detecting all networks" + str(err)) \
            from err
    return returnValue

def handler(context, inputs):
    bearerToken = context["getToken"]()
    returnValue = getAllNetworks(bearerToken)
    print(returnValue)
    outputs = {
      "status": "done",
      "return": returnValue
    }
    return outputs

Best regards
Stefan

qc4vmware's profile image
qc4vmware

Hey @Stefan Schnell thanks for taking the time to test.  I may have not been totally clear but I did mention that some filters like "name" seem to work.  I was attempting to filter on "tags".  If you have the time can you add a couple of tags and see if you can get an expected result?  When I use a filter on tags to the fabric-networks the query returns expected results but the /networks only returns an empty set.  Same tags and same filter set.  My filter was set to the following:

tags.item.key%20eq%20'placement'%20and%20tags.item.value%20eq%20'TESTTAG'

Stefan Schnell's profile image
Stefan Schnell

Hello @qc4vmware,

I tried it on the way as your example and it is described here.

url = "https://aria-auto.corp.vmbeans.com/iaas/api/networks?apiVersion=2021-07-15&$filter=tags.item.value%20eq%20'*vsphere*'"

but without success.

Unless I have overlooked something, I would expect a result here.

Best regards
Stefan

Ozhk's profile image
Ozhk

Hi!
Try adding this filter to the URL (needs to be url encoded first):

$filter=(expandedTags.item.tag eq 'vsphere')
Kind regards,
O.
qc4vmware's profile image
qc4vmware

@Ozhk I tried that example and no results returned... also the key is not specified so that is only a partial filter on a tag so not sure where it would be applied but likely only on a key only tag.

My filter string was: expandedTags.item.key%20eq%20'placement'%20and%20expandedTags.item.value%20eq%20'TESTIT'

Stefan Schnell's profile image
Stefan Schnell

Hello @Ozhk,

thanks for sharing the solution, in my case it works also with Aria Automation 8.17.0.

Best regards
Stefan

qc4vmware's profile image
qc4vmware

Cool that worked for me and I'm on version 16.0 .  I've not come across this in any documentation all of the examples I've seen are as I outlined in my original post.  @Ozhk do you know if this method should work for filters in all the api calls that support filters and would have a tagged inventory?

Thanks again @Stefan Schnell for taking the time to test this!

Paul

Ozhk's profile image
Ozhk

Hi, 

I am glad it worked for you too.

@qc4vmware I dont know tbh, the documentation is unfortunately not too extensive ;).

https://docs.vmware.com/en/VMware-Aria-Automation/8.18/automation-extensibility-migration/GUID-22A9EEE8-7145-476C-AC18-7CE1411BCCF4.html

Kind regards,

O.