APIs and programmatically delivering network function is the impetus to change from older networking thought processes into the modern and future architectures. For some time now many networking vendors have been providing API function. NETCONF configuration via Python allows Juniper configurations. RESTful XML for NSX which can be wrapped in Python. All of this allows the notion of deployment via API. Dig behind Cloud Management Platforms such as vCloud Automation Center or Openstack and you will find the orchestration component uses many APIs to be consumed. They will consume lower tiered or southbound API.

Whilst this isn’t new for many people the idea of chaining multiple commands together in a Python construct could be. This snippet is taken from a template made by fellow co-worker from the NSBU – Thomas Kraus. This is one subset instruction that is part of a script that deploys 3 logical switches, connects the segments do a logical distributed router, deploys a NSX-edge and configures OSPF between the uplink interface of the LDR and the NSX-edge.

Below is the creation of transport zone between clusters within a vCenter administrative domain. Remember there is a current relationship of NSX manager and vCenter which is 1:1. The code is the following:

def create_tz(tz_name):
    url='https://' + nsx_ip + '/api/2.0/vdn/scopes'
    xml_string ='Transport-Zone-1Compute-1Compute-2Compute-3MGMT-EDGE-1'
    req=urllib2.Request(url=url,data=xml_string, headers=headers)
    return tz_id

The actions of the code – remembering this is a subset in a larger script – does the following.


  • Points to the URL https://nsx_ip/api/2.0/vdn/scopes
  • note nsx_ip=”″ is defined as a variable at the top.
  • Places the xml_string which references the compute clusters. This instructs NSX manager to inject the following information.
  • It will then return the transport zone ID.


Here is just a small sample of what you can do with rather static information. I can do what could take a bit of time to configure by hand or via GUI in a way that could draw dynamic information and potentially touch many domains. You could have it draw from a list of NSX managers to prepare a cluster for NSX. Imagine having to only dump NSX manager IP’s and have a script go off and do a repetitive task for you across many domains. This is the value of APIs. Wait until I show you how we can configure OSPF and routing! I can’t wait to share.

Disclaimer – I apologise if my Python terminology is wrong. I also don’t apologise for being an absolute hack or writing ugly code! 🙂

2 thoughts on “Using an API

Leave a Reply

Your email address will not be published. Required fields are marked *