Cisco ACI and NX-OS Automation with APIs and Scripting
Cisco ACI and NX-OS Automation with APIs and Scripting is the largest domain: the ACI object model and APIC REST API, plus NX-OS surfaces such as NX-API, the Python SDK, on-box scripting and model-driven interfaces.
ACI: model first, then API
ACI is built on the Management Information Tree. Every object is an MO of a class (fvTenant, fvBD, fvAEPg, vzBrCP), has a distinguished name (uni/tn-Prod/ap-App/epg-Web), and can carry relations such as fvRsCons. Configuration is a POST of JSON to /api/mo/<dn>.json or /api/class/<class>.json; queries are GETs with filters like ?query-target-filter=eq(fvTenant.name,'Prod') and ?rsp-subtree=children&rsp-subtree-class=fvBD.
Authentication: POST /api/aaaLogin.json with an aaaUser object containing name and password, then send the returned token as the APIC-Cookie cookie. Tokens expire; renew with /api/aaaRefresh.json. The Cobra SDK wraps this with LoginSession and ConfigRequest.
NX-OS automation surfaces
- NX-API (enable with
feature nxapi) exposes JSON-RPC athttps://<switch>/ins; the body carriesins_apiwithtype(cli_show,cli_conf,bash),inputandoutput_format. Multiple config lines are separated by;. - The NX-OS Python SDK wraps NX-API for scripts; Guestshell runs Python on the device itself.
- NETCONF/YANG and gNMI telemetry provide model-driven access; EEM triggers actions on device events.
Worked example
Create a tenant, bridge domain and EPG in one request.
Reasoning: build imdata as a single nested body - an fvTenant with fvBD and fvAEPg children - and POST it to /api/mo/uni.json. APIC creates the hierarchy in dependency order, so no second call is required; verify with a GET on /api/mo/uni/tn-Prod.json?rsp-subtree=children. If a script must re-run safely, query the objects first and only POST what is missing.
Traps that cost marks
- GETting
/api/mo/uni.jsonwith no filter on a production APIC - enormous, slow response. - Confusing DN (absolute path) with RN (relative name) when composing URLs.
- Using GET to configure, or omitting the JSON content type.
- Ignoring token lifetime, or scripting NX-API with the wrong
typefor configuration.