Python Fundamentals
SECTION
  • Introduction
  • Ansible and ACI
  • Cisco ACI API
  • Python Basics
  • Python ReST w/Requests
  • Javascript
  • Config ACI Programatically
  • Finished
  • References

For this section we are going to work in a different virtual environment than the one Ansible setup we previously created. This is very common practice amongst Python users. You might have a virtual environment that you setup specifically with one Ansible version, one Python version that you know works. You can then reference this base software version combination going forward, giving you confidence that you can use a base code of software going forward without having to update/fix.

Step 1 - Close All Open Ansible Tabs

To avoid confusion please close all the open file tabs you have open in the editor

Step 2 - Create new virtual environment in Python3

For this portion of the lab you are going to create a different python virtual environment that is separate from the work that was done for Ansible.


pyenv virtualenv 3.9.11 requests


cd ~/ltrdcn-3225/requests

Setup local pyenv as we did before.


pyenv local requests

With the environment active, any python packages are now install in the virtual environment directory that was specified in ~/envsand don't affect the system or any other applications. This is very important as you could be developing various applications and you don't want to break another application by upgrading a requirement unnecesarily.

Step 3 - Install wheel


    pip install wheel

Step 4 - Install requests

The request library makes it possible to easily have Python make requests to a REST interface.


    pip install requests

Step 5 - Install ptable

Ptable will help us with showing structured data from the ACI fabric in a way that is easier to read for humans.


    pip install ptable

Step 6 - Install Pretty Print

Pprint will also help us with showing structured data from the ACI fabric in a way that is easier to read for humans.


    pip install pprintpp