Skip to main content

Posts

Showing posts with the label Python

Fixing Cisco ACI API Token Expiration: Auto-Refreshing APIC Sessions

  You trigger a massive data center automation workflow using Python. The script begins provisioning new tenants, configuring bridge domains, and binding Endpoint Groups (EPGs). Halfway through the orchestration process, the script crashes, throwing an HTTP 403 Forbidden error. The cause is not a permissions issue. Your Cisco ACI API token expired mid-execution. When building resilient infrastructure-as-code pipelines, handling API session state is critical. The Cisco Application Policy Infrastructure Controller (APIC) enforces strict token lifetimes. If your Python scripts rely on static, fire-and-forget authentication, long-running orchestration tasks will inevitably fail. This guide details how to build a self-healing Python HTTP session that automatically handles Cisco APIC token refresh cycles, ensuring uninterrupted data center automation. The Architecture of APIC Session Expiration To engineer a proper fix, you must understand how the APIC REST API handles stateful authentic...

How to Parse Cisco IOS-XR Show Commands using Python TextFSM and Genie

  Network Reliability Engineers routinely face the challenge of extracting structured data from legacy CLI interfaces. While modern network operating systems support NETCONF, RESTCONF, and gRPC telemetry, legacy environments and troubleshooting workflows still rely heavily on traditional   show   commands. Extracting structured JSON data from raw, unstructured CLI output for complex routing states is notoriously difficult. Relying on custom regex scripts leads to fragile automation that breaks during minor firmware upgrades. Solving this requires robust parsing engines like the Cisco Genie parser and Python TextFSM. The Root Cause: Why Naive Regex Fails in IOS-XR Automation Command-line interfaces are optimized for human readability, not machine consumption. When you execute a command like  show bgp ipv4 unicast summary  on an IOS-XR device, the router formats the output using arbitrary whitespace padding, pagination, and dynamic column widths. Naive regex patte...