mirror of
https://github.com/dtzp555-max/aci-sim.git
synced 2026-07-21 21:15:12 +00:00
Initial public release — aci-sim v0.16.0
aci-sim is a stateful REST simulator of a 2-site Cisco ACI fabric (per-site APIC + ND/NDO management planes) — for testing ACI automation (Ansible cisco.aci / cisco.mso, aci-py, custom REST clients) and CI gates without real hardware. Highlights: APIC + NDO REST surface served from one in-memory MIT built from a declarative topology.yaml; port mode + sandbox (real per-device IPs on :443) run modes; LLDP/CDP neighbor visibility; NDO->APIC deploy mirror (multi-site templates materialize onto the target sites' APIC stores); real-APIC fvBD default attributes; file-backed state save/restore; an `aci-sim` CLI (validate/show/graph/run/new/init/lldp); and an 888-test suite. History squashed for the public release. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""Topology YAML loader.
|
||||
|
||||
Usage::
|
||||
|
||||
from aci_sim.topology.loader import load_topology
|
||||
topo = load_topology("topology.yaml")
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import yaml
|
||||
|
||||
from .schema import Topology
|
||||
|
||||
|
||||
def load_topology(path: Union[str, Path]) -> Topology:
|
||||
"""Read *path*, parse YAML, validate, and return a :class:`~schema.Topology`.
|
||||
|
||||
Raises
|
||||
------
|
||||
FileNotFoundError
|
||||
If *path* does not exist.
|
||||
ValueError
|
||||
If the YAML is syntactically invalid.
|
||||
pydantic.ValidationError
|
||||
If the topology fails schema or cross-reference validation; the error
|
||||
message lists every violation found.
|
||||
"""
|
||||
path = Path(path)
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(f"Topology file not found: {path}")
|
||||
|
||||
try:
|
||||
raw = yaml.safe_load(path.read_text(encoding="utf-8"))
|
||||
except yaml.YAMLError as exc:
|
||||
raise ValueError(f"Failed to parse YAML from {path}: {exc}") from exc
|
||||
|
||||
if not isinstance(raw, dict):
|
||||
raise ValueError(
|
||||
f"Topology YAML must be a mapping at the top level, got {type(raw).__name__}"
|
||||
)
|
||||
|
||||
# Let ValidationError propagate naturally — callers inspect it directly.
|
||||
return Topology.model_validate(raw)
|
||||
Reference in New Issue
Block a user