# Datacenter Generator - Visual Diagrams ## 1. Generator Concept - High Level ```mermaid graph TB subgraph Input["📥 INPUT"] DC1[Datacenter: DC1
---
dc_id: 1
bays: 2
dci_enabled: false] DC2[Datacenter: DC2
---
dc_id: 2
bays: 2
dci_enabled: false] DCI_Config[DCI Configuration
---
Manual/External
IP: 10.253.254.x] end subgraph Logic["⚙️ DATACENTER GENERATOR"] Gen1[DC1 Generator:
Create 11 devices
Border eth12: shutdown] Gen2[DC2 Generator:
Create 11 devices
Border eth12: shutdown] end subgraph Output1["📤 DC1 OUTPUT"] Dev1[11 Device Objects] Int1[~50 Interface Objects] IP1[~30 IP Addresses] end subgraph Output2["📤 DC2 OUTPUT"] Dev2[11 Device Objects] Int2[~50 Interface Objects] IP2[~30 IP Addresses] end subgraph Manual["🔧 MANUAL DCI SETUP"] DCIDevice[DCI Device
Loopback: 10.253.0.1
ASN: 65000] UpdateDC1[Update DC1:
dci_enabled: true
dci_remote_dc_id: 2] UpdateDC2[Update DC2:
dci_enabled: true
dci_remote_dc_id: 1] end DC1 --> Gen1 DC2 --> Gen2 Gen1 --> Dev1 Gen1 --> Int1 Gen1 --> IP1 Gen2 --> Dev2 Gen2 --> Int2 Gen2 --> IP2 Output1 --> Manual Output2 --> Manual DCI_Config --> DCIDevice DCIDevice --> UpdateDC1 DCIDevice --> UpdateDC2 style DC1 fill:#e1f5ff style DC2 fill:#e1f5ff style Manual fill:#fff9c4 style DCIDevice fill:#ffccbc ``` ## 2. Datacenter Hierarchy ```mermaid graph TB Org[Organization] Site[Site: Paris-DC1
Location: Paris, France] DC[Datacenter: DC1
dc_id: 1
bays: 2
spines: 3] Org --> Site Site --> DC DC --> SpineLayer[Spine Layer] DC --> LeafLayer[Leaf Layer] DC --> BorderLayer[Border Layer] DC --> BayLayer[Bay Layer] DC --> Subnets[IP Subnets] SpineLayer --> S1[spine1-DC1
ASN: 65100] SpineLayer --> S2[spine2-DC1
ASN: 65100] SpineLayer --> S3[spine3-DC1
ASN: 65100] LeafLayer --> LP1[Leaf Pair 1
ASN: 65101] LeafLayer --> LP2[Leaf Pair 2
ASN: 65102] LP1 --> L1[leaf1-DC1
10.1.0.21] LP1 --> L2[leaf2-DC1
10.1.0.22] LP2 --> L3[leaf3-DC1
10.1.0.23] LP2 --> L4[leaf4-DC1
10.1.0.24] BorderLayer --> BP[Border Pair
ASN: 65103] BP --> B1[borderleaf1-DC1] BP --> B2[borderleaf2-DC1] BayLayer --> Bay1[Bay 1] BayLayer --> Bay2[Bay 2] Bay1 --> A1[access1-DC1] Bay2 --> A2[access2-DC1] Subnets --> Sub1[10.1.0.0/24
Loopback0] Subnets --> Sub2[10.1.1.0/24
Loopback1] Subnets --> Sub3[10.1.10.0/24
Spine-Leaf P2P] Subnets --> Sub4[10.1.20.0/24
Leaf-Access P2P] style DC fill:#ffecb3 style LP1 fill:#b3e5fc style LP2 fill:#b3e5fc style Bay1 fill:#c8e6c9 style Bay2 fill:#c8e6c9 ``` ## 3. Bay-to-Leaf Assignment Logic ```mermaid graph LR subgraph Bays["🏢 Bays"] Bay1[Bay 1
access1-DC1] Bay2[Bay 2
access2-DC1] Bay3[Bay 3
access3-DC1] Bay4[Bay 4
access4-DC1] end subgraph LeafPairs["🔀 Leaf Pairs - MLAG"] LP1[Leaf Pair 1
leaf1-DC1 ↔ leaf2-DC1
ASN: 65101] LP2[Leaf Pair 2
leaf3-DC1 ↔ leaf4-DC1
ASN: 65102] end subgraph Spines["⬆️ Spine Layer"] S1[spine1-DC1] S2[spine2-DC1] S3[spine3-DC1] end Bay1 -.2 uplinks.- LP1 Bay2 -.2 uplinks.- LP1 Bay3 -.2 uplinks.- LP2 Bay4 -.2 uplinks.- LP2 LP1 --> S1 LP1 --> S2 LP1 --> S3 LP2 --> S1 LP2 --> S2 LP2 --> S3 style Bay1 fill:#c8e6c9 style Bay2 fill:#c8e6c9 style Bay3 fill:#ffccbc style Bay4 fill:#ffccbc style LP1 fill:#b3e5fc style LP2 fill:#b3e5fc ``` ## 4. Complete DC1 Physical Topology ```mermaid graph TB subgraph DCI["DCI LAYER - Inter-DC"] DCID[DCI Switch
10.253.0.1
ASN: 65000] end subgraph Border["BORDER LEAF - DCI Gateway"] B1[borderleaf1-DC1
10.1.0.31
eth12: shutdown or active] B2[borderleaf2-DC1
10.1.0.32
eth12: shutdown or active] end subgraph Spine["SPINE LAYER - L3 Core"] S1[spine1-DC1
10.1.0.11
ASN: 65100] S2[spine2-DC1
10.1.0.12
ASN: 65100] S3[spine3-DC1
10.1.0.13
ASN: 65100] end subgraph Leaf["LEAF LAYER - Aggregation + VXLAN"] subgraph Pair1["MLAG Pair 1 - ASN: 65101"] L1[leaf1-DC1
10.1.0.21
VTEP: 10.1.1.21] L2[leaf2-DC1
10.1.0.22
VTEP: 10.1.1.21] end subgraph Pair2["MLAG Pair 2 - ASN: 65102"] L3[leaf3-DC1
10.1.0.23
VTEP: 10.1.1.23] L4[leaf4-DC1
10.1.0.24
VTEP: 10.1.1.23] end end subgraph Access["ACCESS LAYER - Rack/Bay ToR"] A1[access1-DC1
Bay 1
L2 Switch] A2[access2-DC1
Bay 2
L2 Switch] end subgraph Hosts["HOST LAYER"] H1[host1-DC1
172.16.100.10] H2[host2-DC1
172.16.200.10] end DCID -.Optional DCI.- B1 DCID -.Optional DCI.- B2 S1 -.eBGP.- L1 S1 -.eBGP.- L2 S1 -.eBGP.- L3 S1 -.eBGP.- L4 S1 -.eBGP.- B1 S1 -.eBGP.- B2 S2 -.eBGP.- L1 S2 -.eBGP.- L2 S2 -.eBGP.- L3 S2 -.eBGP.- L4 S2 -.eBGP.- B1 S2 -.eBGP.- B2 S3 -.eBGP.- L1 S3 -.eBGP.- L2 S3 -.eBGP.- L3 S3 -.eBGP.- L4 S3 -.eBGP.- B1 S3 -.eBGP.- B2 L1 ---|MLAG| L2 L3 ---|MLAG| L4 B1 ---|MLAG| B2 L1 -->|eth7| A1 L2 -->|eth7| A1 L3 -->|eth7| A2 L4 -->|eth7| A2 A1 -->|eth10| H1 A2 -->|eth10| H2 style DCID fill:#ffccbc style S1 fill:#ffccbc style S2 fill:#ffccbc style S3 fill:#ffccbc style L1 fill:#b3e5fc style L2 fill:#b3e5fc style L3 fill:#b3e5fc style L4 fill:#b3e5fc style A1 fill:#c8e6c9 style A2 fill:#c8e6c9 style B1 fill:#f8bbd0 style B2 fill:#f8bbd0 ``` ## 5. IP Address Generation Flow ```mermaid graph TB Start[Datacenter Object
dc_id: 1, bays: 2] Start --> GenSubnets[Generate Subnets
from dc_id] GenSubnets --> Sub1[10.1.0.0/24
Loopback0] GenSubnets --> Sub2[10.1.1.0/24
Loopback1] GenSubnets --> Sub3[10.1.10.0/24
Spine-Leaf P2P] GenSubnets --> Sub4[10.1.20.0/24
Leaf-Access P2P] GenSubnets --> Sub5[10.1.255.0/24
MLAG Peer] GenSubnets --> Sub6[10.255.0.0/24
Management] Sub1 --> AllocLo0[Allocate Loopback0
to Spines & Leafs] Sub2 --> AllocLo1[Allocate Loopback1
to Leafs - shared in pairs] Sub3 --> AllocP2P1[Allocate /31s
for Spine-Leaf links] Sub4 --> AllocP2P2[Allocate /31s
for Leaf-Access links] Sub5 --> AllocMLAG[Allocate /30s
for MLAG peers] Sub6 --> AllocMgmt[Allocate Management IPs
to all devices] AllocLo0 --> Spine1IP[spine1: 10.1.0.11/32] AllocLo0 --> Leaf1IP[leaf1: 10.1.0.21/32] AllocLo1 --> Leaf1VTEP[leaf1-2: 10.1.1.21/32 - shared] AllocP2P1 --> Link1[spine1-leaf1: 10.1.10.0/31] AllocP2P2 --> Link2[leaf1-access1: 10.1.20.0/31] AllocMLAG --> MLAG1[leaf1-2 peer: 10.1.255.1-2/30] AllocMgmt --> Mgmt1[spine1: 10.255.0.11] style Start fill:#ffecb3 style Sub1 fill:#e1f5ff style Sub2 fill:#e1f5ff style Sub3 fill:#e1f5ff style Sub4 fill:#e1f5ff style Sub5 fill:#e1f5ff style Sub6 fill:#e1f5ff ``` ## 6. Device Generation Flow ```mermaid graph TB DC[Datacenter: DC1
bays: 2] DC --> CalcLeafs[Calculate:
leaf_pairs = ceil - bays / 2 - = 1
total_leafs = 1 * 2 = 2] CalcLeafs --> GenSpines[Generate Spines
count: 3 - fixed] CalcLeafs --> GenLeafs[Generate Leafs
count: 4 - computed] CalcLeafs --> GenBorders[Generate Border Leafs
count: 2 - fixed] CalcLeafs --> GenAccess[Generate Access
count: 2 - from bays] GenSpines --> S1[spine1-DC1] GenSpines --> S2[spine2-DC1] GenSpines --> S3[spine3-DC1] GenLeafs --> LP1[Create MLAG Pair 1] GenLeafs --> LP2[Create MLAG Pair 2] LP1 --> L1[leaf1-DC1] LP1 --> L2[leaf2-DC1] LP2 --> L3[leaf3-DC1] LP2 --> L4[leaf4-DC1] GenBorders --> BP[Create Border Pair] BP --> B1[borderleaf1-DC1] BP --> B2[borderleaf2-DC1] GenAccess --> AssignBays[Assign Bays to Leaf Pairs] AssignBays --> A1Config[Bay 1 → Leaf Pair 1
access1-DC1] AssignBays --> A2Config[Bay 2 → Leaf Pair 1
access2-DC1] A1Config --> A1[access1-DC1] A2Config --> A2[access2-DC1] style DC fill:#ffecb3 style LP1 fill:#b3e5fc style LP2 fill:#b3e5fc style BP fill:#f8bbd0 ``` ## 7. Scaling Scenario - Adding Bay 3 ```mermaid graph LR subgraph Current["📦 Current State - 2 Bays"] CurDC[Datacenter: DC1
bays: 2
leaf_pairs: 1] CurLP1[Leaf Pair 1
leaf1-2] CurBay1[Bay 1 → access1] CurBay2[Bay 2 → access2] CurDC --> CurLP1 CurLP1 --> CurBay1 CurLP1 --> CurBay2 end subgraph Action["⚙️ User Action"] AddBay[Add Bay 3
number_of_bays: 2 → 3] end subgraph Generator["🔄 Generator Logic"] Check[Check:
bays=3 > pairs*2=2?
YES → Need new pair] CreatePair[Create Leaf Pair 2
leaf3-DC1, leaf4-DC1] CreateAccess[Create access3-DC1] AssignBay[Assign Bay 3 → Pair 2] AllocIPs[Allocate IPs] CreateLinks[Create Interfaces] ConfigBGP[Configure BGP
ASN: 65102] end subgraph Result["✅ New State - 3 Bays"] NewDC[Datacenter: DC1
bays: 3
leaf_pairs: 2] NewLP1[Leaf Pair 1
leaf1-2
ASN: 65101] NewLP2[Leaf Pair 2
leaf3-4
ASN: 65102] NewBay1[Bay 1 → access1] NewBay2[Bay 2 → access2] NewBay3[Bay 3 → access3] NewDC --> NewLP1 NewDC --> NewLP2 NewLP1 --> NewBay1 NewLP1 --> NewBay2 NewLP2 --> NewBay3 end Current --> AddBay AddBay --> Check Check --> CreatePair CreatePair --> CreateAccess CreateAccess --> AssignBay AssignBay --> AllocIPs AllocIPs --> CreateLinks CreateLinks --> ConfigBGP ConfigBGP --> Result style AddBay fill:#fff59d style Check fill:#ffccbc style Result fill:#c8e6c9 ``` ## 8. Infrahub Generator Workflow ```mermaid sequenceDiagram participant User participant Infrahub participant Generator participant Validator participant GraphQL participant Devices User->>Infrahub: Create Datacenter Object
(name, dc_id, bays, etc.) Infrahub->>Validator: Pre-Generation Validation Validator-->>Infrahub: ✅ Valid Input Infrahub->>Generator: Trigger Generator Generator->>Generator: Compute Derived Values
(leaf_pairs, subnets, etc.) loop For Each Layer Generator->>Devices: Create Spine Devices Generator->>Devices: Create Leaf Devices Generator->>Devices: Create Access Devices end loop For Each Device Generator->>Devices: Create Interfaces Generator->>Devices: Allocate IP Addresses Generator->>Devices: Generate BGP Config end Generator->>Validator: Post-Generation Validation Validator-->>Generator: ✅ All Objects Valid Generator->>GraphQL: Commit All Objects GraphQL-->>Infrahub: Objects Created Infrahub-->>User: ✅ Datacenter Generated
27 devices, 150 interfaces, 90 IPs ``` ## 9. Configuration Generation Flow ```mermaid graph TB subgraph Infrahub["📊 Infrahub - Source of Truth"] DeviceDB[(Device Objects
Interfaces
IPs
BGP Sessions)] end subgraph Generator["⚙️ Config Generator"] Templates[Jinja2 Templates
by Device Role] RenderEngine[Template Renderer] end subgraph Output["📄 Generated Configs"] SpineConfig[spine1-DC1.cfg] LeafConfig[leaf1-DC1.cfg] AccessConfig[access1-DC1.cfg] end subgraph Deployment["🚀 Deployment"] Validation[Config Validation] Push[Push to Devices
via eAPI/NETCONF] end DeviceDB -->|Query Device Data| RenderEngine Templates --> RenderEngine RenderEngine --> SpineConfig RenderEngine --> LeafConfig RenderEngine --> AccessConfig SpineConfig --> Validation LeafConfig --> Validation AccessConfig --> Validation Validation --> Push Push --> Devices[Physical Devices] style Infrahub fill:#e1f5ff style Generator fill:#fff9c4 style Output fill:#c8e6c9 style Deployment fill:#ffccbc ``` ## 10. Complete Data Model Relationships ```mermaid erDiagram ORGANIZATION ||--o{ SITE : contains SITE ||--o{ DATACENTER : contains SITE ||--o{ IP_PREFIX : manages DATACENTER ||--|{ SUBNET : generates DATACENTER ||--|{ DEVICE : generates DATACENTER ||--|{ MLAG_PAIR : generates DEVICE ||--|{ INTERFACE : has INTERFACE ||--o| IP_ADDRESS : assigned INTERFACE ||--o| BGP_SESSION : endpoint DEVICE }|--|| ROLE : has DEVICE }o--o| MLAG_PAIR : member_of MLAG_PAIR ||--|| DEVICE : primary MLAG_PAIR ||--|| DEVICE : secondary BGP_SESSION }o--|| INTERFACE : local BGP_SESSION }o--|| INTERFACE : remote SUBNET ||--|{ IP_ADDRESS : contains IP_PREFIX ||--|{ SUBNET : parent ORGANIZATION { string name } SITE { string name string location } DATACENTER { string name int dc_id int number_of_bays int spine_count string parent_subnet } DEVICE { string hostname string role string mgmt_ip } INTERFACE { string name string type int mtu } IP_ADDRESS { string address int prefix_length } BGP_SESSION { int local_asn int remote_asn } ```