class Apic(object): def __init__(self, apic_policy): self._policy = apic_policy self._session = None def login(self): url = self._policy.ip_address if str(self._policy.use_https).lower() == 'true': url = 'https://' + url else: url = 'http://' + url self._session = Session(url, self._policy.user_name, self._policy.password) resp = self._session.login() return resp def logged_in(self): return self._session.logged_in() def get_name(self): return self._policy.ip_address def get_session(self): return self._session
#! /usr/bin/env python """ Learning Series: Network Programmability Basics Module: Network Controllers Lesson: ACI Programmability Part 2 Author: Hank Preston <*****@*****.**> toolkit_getting_started.py Illustrate the following concepts: - Import ACI Toolkit library - Connect to APIC Controller - Print list of tenants - Intended to be entered into an interactive interpreter """ from device_info import apic from acitoolkit.acitoolkit import Session, Tenant session = Session(apic['host'], apic['username'], apic['password']) session.login() session.logged_in() tenants = Tenant.get(session) for tenant in tenants: print(tenant.name) if tenant.name == "Heroes": heroe_tenant = tenant