01-07-2018 04:55 AM - edited 03-01-2019 05:25 AM
can any one show me a example that using python rest api to add a EPG or BD in APIC automatically, thanks
01-07-2018 05:07 PM
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.
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide