# andykool-py/ospf_cfg_rest architecture

> Architecture diagram of the GitHub repository andykool-py/ospf_cfg_rest, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andykool-py/ospf_cfg_rest
- Repository: https://github.com/andykool-py/ospf_cfg_rest

## Overview

##### 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 conver­gence → 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

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Configuration & Templates"
    config[/"config.yaml"/]:::yaml
    templates["payloads.yaml + Jinja2 templates"]:::yaml
  end

  subgraph "Core Modules"
    entry["main.py"]:::python
    orch["orchestrator.py"]:::python
    builder["build_device_payloads.py"]:::python
    restRunner["rest_runner.py"]:::python
    restClient["rest_client.py"]:::python
    wait["wait_with_progress.py"]:::python
    ping["verify_ping.py"]:::python
    ospfDiag["verify_ospf_config.py"]:::python
    parser["xml_parser.py"]:::python
    reset["reset_device_configs.py"]:::python
    test["test_1.py"]:::python
  end

  subgraph "External & CLI"
    operator(("Operator CLI")):::external
    devices(("Juniper vMX Devices")):::device
  end

  operator -->|"invoke python main.py"| entry
  entry -->|"calls"| orch
  orch -->|"reads"| config
  orch -->|"reads"| templates
  orch -->|"calls"| builder
  builder -->|"returns XML payloads"| orch
  orch -->|"delegates calls"| restRunner
  restRunner -->|"uses"| restClient
  orch -->|"calls REST POST"| restClient
  restClient -->|"HTTP POST/commit RPC"| devices
  orch -->|"calls"| wait
  orch -->|"calls RPC ping"| restClient
  restClient -->|"XML ping results"| orch
  orch -->|"calls"| ping
  ping -->|"reports reachability"| orch
  orch -->|"calls"| parser
  parser -->|"parsed neighbors/routes/LSDB"| orch
  orch -->|"calls"| ospfDiag
  ospfDiag -->|"OSPF diagnostics"| orch
  orch -->|"aggregates & prints results"| operator

  orch -.->|"optional rollback"| reset
  reset -->|"NETCONF via PyEZ"| devices

  test -->|"smoke test modules"| builder
  test -->|"smoke test modules"| restClient
  test -->|"smoke test modules"| orch

  click config "https://github.com/andykool-py/ospf_cfg_rest/blob/main/config.yaml"
  click templates "https://github.com/andykool-py/ospf_cfg_rest/blob/main/payloads.yaml"
  click builder "https://github.com/andykool-py/ospf_cfg_rest/blob/main/build_device_payloads.py"
  click entry "https://github.com/andykool-py/ospf_cfg_rest/blob/main/main.py"
  click orch "https://github.com/andykool-py/ospf_cfg_rest/blob/main/orchestrator.py"
  click restClient "https://github.com/andykool-py/ospf_cfg_rest/blob/main/rest_client.py"
  click restRunner "https://github.com/andykool-py/ospf_cfg_rest/blob/main/rest_runner.py"
  click ping "https://github.com/andykool-py/ospf_cfg_rest/blob/main/verify_ping.py"
  click ospfDiag "https://github.com/andykool-py/ospf_cfg_rest/blob/main/verify_ospf_config.py"
  click parser "https://github.com/andykool-py/ospf_cfg_rest/blob/main/xml_parser.py"
  click reset "https://github.com/andykool-py/ospf_cfg_rest/blob/main/reset_device_configs.py"
  click wait "https://github.com/andykool-py/ospf_cfg_rest/blob/main/wait_with_progress.py"
  click test "https://github.com/andykool-py/ospf_cfg_rest/blob/main/test_1.py"

  classDef python fill:#8dd3c7,stroke:#333,stroke-width:1px
  classDef yaml fill:#b3de69,stroke:#333,stroke-width:1px
  classDef device fill:#fb8072,stroke:#333,stroke-width:1px
  classDef external fill:#d9d9d9,stroke:#333,stroke-width:1px
```
