SDN
How-To: Authenticate requests to the Contrail Python API library
Distinguished Expert
SDN

How-To: Authenticate requests to the Contrail Python API library

by Distinguished Expert on ‎01-08-2016 09:40 AM - edited on ‎09-19-2017 10:46 AM by Administrator Administrator (3,434 Views)

Examples provided in Contrail Configuration API server documentation at:


http://www.juniper.net/techpubs/en_US/release-independent/contrail/information-products/pathway-page...

 

Assume no authentication of the incoming API connection. However recent versions of Contrail (such as 2.21) require authentication of API requests by default.

 

Although one solution is to disable authentication, as described in
http://forums.juniper.net/t5/SDN/How-To-Make-Contrail-Python-API-Library-Work-Without/ta-p/285355
it is possible to just authenticate the requests as presented in example script below.


The tricky part is that both api_server_host and auth_host parameters must be provided, even if their IP addresses are the same. The tenant_name parameter is required as well, together with username and password.

 

 

root@openstack:~/scripts# cat vns.py
#! /usr/bin/python

from vnc_api import vnc_api
from pprint import pprint

vnc_lib = vnc_api.VncApi(api_server_host = '10.10.10.230', 
        auth_host = '10.10.10.230',
        username = 'admin', password = 'contrail', tenant_name = 'admin')

net_list = vnc_lib.virtual_networks_list()

for vn in net_list['virtual-networks']:
    pprint( vn['fq_name'] ) 

	
	
root@openstack:~/scripts# python vns.py 
[u'default-domain', u'default-project', u'__link_local__']
[u'default-domain', u'demo', u'VN-A']
[u'default-domain', u'default-project', u'ip-fabric']
[u'default-domain', u'default-project', u'default-virtual-network']