Description

Contrail API provides many query parameters which allows flexibility while running a query with a curl command. This article explains how this works. 

Symptoms

Listing all VNs in Contrail is easy. However, VNs from all projects are mixed. When the configuration data grows, it is difficult to count VNs by project names.

user@testABC:~# curl -su admin:Juniper "localhost:8095/virtual-networks" | python -mjson.tool
{
    "virtual-networks": [
        {
            "fq_name": [
                "default-domain",
                "demo",
                "demo-vn"
            ],
            "href": "http://localhost:8095/virtual-network/19a47c0e-6b40-4ff6-9e1a-8c7c21af4c8e",
            "uuid": "19a47c0e-6b40-4ff6-9e1a-8c7c21af4c8e"
        },
        {
            "fq_name": [
                "default-domain",
                "default-project",
                "ip-fabric"
            ],
            "href": "http://localhost:8095/virtual-network/6f68790a-a6cd-4c5b-8649-5040d0d5d095",
            "uuid": "6f68790a-a6cd-4c5b-8649-5040d0d5d095"
        },
        {
            "fq_name": [
                "default-domain",
                "default-project",
                "default-virtual-network"
            ],
            "href": "http://localhost:8095/virtual-network/73058b51-9e49-4305-ba0f-941f57ee896e",
            "uuid": "73058b51-9e49-4305-ba0f-941f57ee896e"
        },
        {
            "fq_name": [
                "default-domain",
                "default-project",
                "__link_local__"
            ],
            "href": "http://localhost:8095/virtual-network/79e4eae3-aa83-4e1a-9530-bdd374fc1620",
            "uuid": "79e4eae3-aa83-4e1a-9530-bdd374fc1620"
        },
        {
            "fq_name": [
                "default-domain",
                "demo",
                "shared-vn"
            ],
            "href": "http://localhost:8095/virtual-network/805a59f8-53d0-4e20-958e-921df7860e38",
            "uuid": "805a59f8-53d0-4e20-958e-921df7860e38"
        }
    ]
}

Solution

Add 'parent_fq_name_str' and 'parent_type' parameters into a query to filter the output. Then VNs can be seen under specific projects.

The value of parameter ' parent_fq_name_str' should be fqname of the project, and the value of 'parent_type' should be 'project' .

Example:

user@testABC:~# curl -su admin:Juniper "localhost:8095/virtual-networks?parent_fq_name_str=default-domain:demo&parent_type=project" | python -mjson.tool
{
    "virtual-networks": [
        {
            "fq_name": [
                "default-domain",
                "demo",
                "demo-vn"
            ],
            "href": "http://localhost:8095/virtual-network/19a47c0e-6b40-4ff6-9e1a-8c7c21af4c8e",
            "uuid": "19a47c0e-6b40-4ff6-9e1a-8c7c21af4c8e"
        },
        {
            "fq_name": [
                "default-domain",
                "demo",
                "shared-vn"
            ],
            "href": "http://localhost:8095/virtual-network/805a59f8-53d0-4e20-958e-921df7860e38",
            "uuid": "805a59f8-53d0-4e20-958e-921df7860e38"
        }
    ]
}