is used in Example 9-7. The script was tested successfully
with Python 3.7.4.
First, the acitoolkit library is imported; it will be
referenced in the script using the short name aci. Three
variables are defined next: APIC_URL contains the
URL for the APIC instance that will be queried (in this
case, the Cisco DevNet always-on APIC sandbox), and
USERNAME and PASSWORD contain the login
credentials for the APIC instance. Next, using the
Session method of the aci class, a connection is
established with the APIC. The Session method takes as
input the three variables defined previously: the
APIC_URL, USERNAME, and PASSWORD. Next,
the success of the login action is verified. If the response
to the login action is not okay, a message is displayed to
the console (“Could not login to APIC”), and the script
execution ends. If the login was successful, all the
endpoints in the ACI fabric instance are stored in the
ENDPOINTS variable. This is done by using the get
method of the aci.Endpoint class and passing in the
current session object. Next, the headers of the table—
with the information that will be extracted—are
displayed to the console. As mentioned previously, the
MAC address, the IP address, the encapsulation, the
tenant, the application profile, and the EPG will be
retrieved from the APIC for all the endpoints in the
fabric. The for iterative loop will go over one endpoint at
a time and, using the get_parent() method, will go one
level up in the MIT and retrieve the parent MO of the
endpoint, which is the EPG. Recall that all endpoints in
an ACI fabric are organized in EPGs. The parent object
for an endpoint is hence the EPG of which that endpoint
is a member. Going one level up in the MIT, the parent
object of the EPG is the application profile, and going
one more level up, the parent object of the application
profile is the tenant object. The epg, app_profile, and
tenant variables contain the respective EPG, application
profile, and tenant values for each endpoint in the fabric.