How andykool-py/ospf_cfg_rest works
Project type and purpose
• This is a network-automation toolkit (full-stack in the sense of automation orchestration) written in Python.
• Its goal is to configure and validate OSPF on Juniper vMX routers via REST API (and NETCONF via PyEZ), using YAML-driven device metadata and Jinja2/ XML templates.
File structure
• Top‐level scripts:
• main.py: the entry point
• orchestrator.py: pulls together configuration, pushing, waiting, verification
• Payload/template management:
• config.yaml: device metadata (IP, ports, interfaces, areas)
• payloads.yaml: Jinja2/XML templates for REST RPC calls
• build_device_payloads.py: merges config + templates → XML payloads
• REST communication:
• rest_client.py: HTTP POST, commit, RPCs, ping over REST
• rest_runner.py (if present): orchestrates client calls
• Verification & parsing:
• verify_ping.py: pings loopbacks and parses results
• verify_ospf_config.py: invokes OSPF diagnostics
• xml_parser.py: parses REST/NETCONF XML for neighbors, routes, LSDB
• Device reset:
• reset_device_configs.py / rollback_initial.py: uses PyEZ to clear configs
• Utilities:
• wait_with_progress.py: blocker/progress bar
• test_1.py: smoke test for modules
Key insights from README
• Uses requests, jinja2, PyYAML, jnpr.junos (PyEZ), lxml
• Workflow: build payloads → push REST configs → wait convergence → verify ping → gather/print OSPF status
• Orchestrator ties everything into a single automation run (main.py → orchestrator.py)
a. Configuration layer
b. Payload builder
c. Orchestrator & entrypoint
d. Communication client
e. Verification modules
f. External systems
g. User/CLI
• Operator’s console / terminal invoking python main.py [actor]
Relationships & data flow
1. Operator → main.py → orchestrator
2. orchestrator reads config.yaml & payloads.yaml → calls build_device_payloads
3. build_device_payloads produces REST XML payloads → returns to orchestrator
4. orchestrator calls rest_client to POST interface + OSPF payloads → Juniper devices
5. rest_client commits config → device config is applied
6. orchestrator waits (wait_with_progress) for OSPF convergence
7. orchestrator invokes rest_client ping → receives XML ping results
8. verify_ping parses and reports reachability
9. orchestrator invokes xml_parser & verify_ospf_config → pulls neighbors, routes, LSDB
10. orchestrator aggregates & prints results to operator console
11. Optional: orchestrator or reset script calls PyEZ client to rollback/reset configs
Architectural patterns & principles
• Pipeline/orchestrator pattern: distinct phases (build → deploy → verify)
• Template-driven design: separation of data (config.yaml), templates (payloads.yaml), and code
• Modular separation: payload builder, client, parser, verifier each in own module
• External dependencies abstracted via rest_client and PyEZ client modules
Technologies & frameworks
• Python 3.8+
• requests (HTTP REST)
• Jinja2 (templating)
• PyYAML (config parsing)
• jnpr.junos (PyEZ NETCONF)
• lxml / xml.etree for XML parsing
• Blue rectangles for Python modules
• Green documents for YAML/templates