Use the OpenContrail API client

Use the OpenContrail API client

The contrail-api-cli command-line utility interacts with the OpenContrail API server that allows searching for or modifying API resources as well as supports the unix-style commands. For more information, see the Official contrail-api-cli documentation.

This section contains the following topics:

Install the OpenContrail API client

To install contrail-api-cli:

  1. Log in to any OpenContrail controller node. For example, ntw01.

  2. Install the Python virtual environment for contrail-api-cli:

    apt-get install python-pip python-dev -y &&\
    pip install virtualenv && \
    virtualenv contrail-api-cli-venv && \
    source contrail-api-cli-venv/bin/activate && \
    git clone && \
    cd contrail-api-cli;sudo python install

Access the OpenContrail API client

To access the OpenContrail API:

  1. Use the keystonerc file with credentials and endpoints:

    source /root/keystonerc
    source /root/keystonercv3
  2. Connect to the OpenContrail API using the following command:

    contrail-api-cli --host --port 9100 shell

    Or you can use your OpenStack credentials. For example:

    contrail-api-cli --os-user-name admin --os-password workshop  \
    --os-auth-plugin v2password --host --port 8082 --protocol http \
    --insecure --os-auth-url --os-tenant-name admin shell


  • MCP uses the 9100 port by default, whereas the OpenContrail API standard port is 8082.

  • For the ln command, define a schema in the --schema-version 3.1 parameter. The known versions are the following: 2.21, 3.2, 3.0, 1.10, 3.1.

The contrail-api-cli-extra package

The contrail-api-cli-extra package contains the contrail-api-cli commands to make the OpenContrail installation and operation process easier.

The commands are grouped in different sub-packages and have different purposes:

  • clean: detect and remove bad resources

  • fix: detect and fix bad resources

  • migration: handle data migration when upgrading OpenContrail to a major version

  • misc: general-purpose commands

  • provision: provision and configure an OpenContrail installation

To install the contrail-api-cli-extra package:

Run the following command:

pip install contrail-api-cli-extra

The most used contrail-api-cli-extra sub-packages are the following:

  • contrail-api-cli_extra.clean - since the sub-package allows removing resources, you must explicitly load the contrail_api_cli.clean namespace to run the commands of this sub-package.

    Example of usage:

    contrail-api-cli --ns contrail_api_cli.clean <command>
    # usage
    contrail-api-cli --host --port 9100 --ns contrail_api_cli.clean shell

    This package includes the clean-<type> command. Replace type with the required type of cleaning process. For example:

    • clean-route-target

    • clean-orphaned-acl

    • clean-si-scheduling

    • clean-stale-si

  • contrail_api_cli_extra.fix - allows you to verify and fix misconfigured resources. For example, fix multiple security groups or association of a subnet with a virtual network (VN) in a key-value store.

    If this sub-package is installed, it launches with contrail-api-cli automatically.

    Example of usage:

    fix-vn-id virtual-network/600ad108-fdce-4056-af27-f07f9faa5cae --zk-server
    fix-zk-ip --dry-run --zk-server vitrual-network/xxxxxx-xxxxxxx-xxxxxx