""" Simple application that logs on to the APIC and displays all of the Endpoints. """ import acitoolkit.acitoolkit as aci from tabulate import tabulate def main(): """ Main Show Endpoints Routine :return: None """ # Take login credentials from the command line if provided # Otherwise, take them from your environment variables file ~/.profile description = ('Simple application that logs on to the APIC' ' and displays all of the Endpoints.') creds = aci.Credentials('apic', description) args = creds.get() # Login to APIC session = aci.Session(args.url, args.login, args.password) resp = session.login() if not resp.ok: print('%% Could not login to APIC') return # Download all of the interfaces # and store the data as tuples in a list data = [] endpoints = aci.Endpoint.get(session) for ep in endpoints: epg = ep.get_parent() app_profile = epg.get_parent() tenant = app_profile.get_parent() data.append((ep.mac, ep.ip, ep.if_name, ep.encap, tenant.name, app_profile.name, epg.name)) # Display the data downloaded print tabulate(data, headers=["MACADDRESS", "IPADDRESS", "INTERFACE", "ENCAP", "TENANT", "APP PROFILE", "EPG"]) if __name__ == '__main__': try: main() except KeyboardInterrupt: pass
I have just managed to do a CSV version..
""" Simple application that logs on to the APIC and displays all of the Endpoints. """ import acitoolkit.acitoolkit as aci import csv def main(): """ Main Show Endpoints Routine :return: None """ # Take login credentials from the command line if provided # Otherwise, take them from your environment variables file ~/.profile description = ('Simple application that logs on to the APIC' ' and displays all of the Endpoints.') creds = aci.Credentials('apic', description) args = creds.get() # Login to APIC session = aci.Session(args.url, args.login, args.password) resp = session.login() if not resp.ok: print('%% Could not login to APIC') return # Download all of the interfaces # and store the data as tuples in a list data = [] endpoints = aci.Endpoint.get(session) for ep in endpoints: epg = ep.get_parent() app_profile = epg.get_parent() tenant = app_profile.get_parent() data.append((ep.mac, ep.ip, ep.if_name, ep.encap, tenant.name, app_profile.name, epg.name)) # Display the data downloaded myFile = open('ACI-Endpoints.csv', 'w') with myFile: writer = csv.writer(myFile) writer.writerows(data) print("Writing complete") if __name__ == '__main__': try: main() except KeyboardInterrupt: pass