cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1521
Views
0
Helpful
1
Replies

Python rest api to manupilate apic

Mary
Level 1
Level 1

can any one show me a example that using python rest api to add a EPG or BD in APIC automatically, thanks

1 Reply 1

gkumark
Cisco Employee
Cisco Employee

Hi Jolin,

 

I have attached a text file which has python code for creating a tenant. There is a simple way to get this done using ACI SDK and a tool called arya. Let me share some details on how you can do it. 

 

1. Install ACI Python SDK. You need to install this based on the ACI version you are running. There is a document available in your APIC which guides you through the installation. IN your APIC GUI -> Gear Symbol in top right corner -> Documentation - Python SDK Documentation. In versions prior to 3.0, it is available if you expand the dropdown under your username in top right corner of GUI

2. Install arya from git. Just run the command 'pip install arya' . Refer to https://github.com/datacenter/arya for more details.

3. Create a test tenant (BD or EPG based on what you need). Go to the tenant and right click - save as to download the configuration xml file. 

 

Download_xml.jpg

 

4. From your command prompt use your arya to convert this xml file to a python script. Use below command

# arya -i <apic IP> -u <username> -p <Password> -f <your xml file> > <your_python_script_name.py>

example:

# arya -i x.x.x.x -u admin -p ***** -f create_tenant.xml > create_tenant.py

This creates a new python script using python SDK for you. 

 

5. Open the python script using any editor and remove all unwanted comments and print statements. This would give you a python script what you want.

 

5. To create multiple objects, you can copy paste the same set of commands in the same file or based on how many objects you can use different python loop statements.

 

Hope this helps.

 

-GK

 

 

 

 

Save 25% on Day-2 Operations Add-On License