Support Support Downloads Knowledge Base Juniper Support Portal Community

Knowledge Base

Search our Knowledge Base sites to find answers to your questions.

Ask All Knowledge Base Sites All Knowledge Base Sites JunosE Defect (KA)Knowledge BaseSecurity AdvisoriesTechnical BulletinsTechnotes Sign in to display secure content and recently viewed articles

[Contrail] Example Configuration - Creating Virtual Networks using Library API



Article ID: KB34952 KB Last Updated: 30 Aug 2019Version: 1.0

This article shows a configuration example for creating a Virtual Network (VN) using library API.


In the example below, the VN to be created is named "VN-C", with a single subnet of, in project "demo". The Contrail version is

  1. Import the vnc_api module from vnc_api package and provide the authentication information from within python interactive shell. The vnc_api module is used to interact with the Contrail configuration API server.

    from vnc_api import vnc_api  
    vnc_lib = vnc_api.VncApi(api_server_host='', auth_host = '', username = 'admin', password = 'Juniper', tenant_name = 'demo')
  2. Then the project "demo" is referred and used as an input to the VN object. The specific NetworkIpam with the desired subnet information is also created and attached to the VN object.

    prj = vnc_lib.project_read(fq_name=['default-domain', 'demo'])
    VN_C_obj = vnc_api.VirtualNetwork('VN-C',prj)
    VN_C_obj.add_network_ipam(vnc_api.NetworkIpam(), vnc_api.VnSubnetsType([vnc_api.IpamSubnetType(subnet = vnc_api.SubnetType('', 24))]))

  3. The last step is to create "VN_C" with the specific VN object. The output will be the UUID assigned to "VN_C".

    vnc_lib.virtual_network_create(VN_C_obj) u'f6bd92fb-ace1-4de9-a34a-d5e991cc5df2'

Verification of VN-C creation:

root@aio32:~# neutron net-show f6bd92fb-ace1-4de9-a34a-d5e991cc5df2

| Field                   | Value                                |
| admin_state_up          | True                                 |
| contrail:fq_name        | default-domain                       |
|                         | demo                                 |
|                         | VN-C                                 |
| contrail:instance_count | 0                                    |
| contrail:subnet_ipam    | {"subnet_cidr": "",      | 
|                         |  "ipam_fq_name": ["default-domain",  | 
|                         |  "default-project",                  |
|                         |  "default-network-ipam"]}            |
| id                      | f6bd92fb-ace1-4de9-a34a-d5e991cc5df2 |
| name                    | VN-C                                 |
| port_security_enabled   | True                                 |
| router:external         | False                                |
| shared                  | False                                |
| status                  | ACTIVE                               |
| subnets                 | 138fd8c2-e394-4612-bb02-9f5514b3c1b5 |
| tenant_id               | 9e4232ef20534bdeb07134b094351f0f     |
Comment on this article > Affected Products Browse the Knowledge Base for more articles related to these product categories. Select a category to begin.

Getting Up and Running with Junos

Getting Up and Running with Junos Security Alerts and Vulnerabilities Product Alerts and Software Release Notices Problem Report (PR) Search Tool EOL Notices and Bulletins JTAC User Guide Customer Care User Guide Pathfinder SRX High Availability Configurator SRX VPN Configurator Training Courses and Videos End User Licence Agreement Global Search