File size: 8,024 Bytes
74f2bea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# NetBox Integration Guide

Overgrowth now uses NetBox/Nautobot as the authoritative Source of Truth for network designs. This replaces YAML files with a proper IPAM/DCIM system used by enterprises worldwide.

## Why NetBox?

- **Industry Standard**: Used by Netflix, DigitalOcean, Dropbox, and thousands of organizations
- **Rich Data Model**: Devices, racks, cables, VLANs, IPs, circuits, power, and more
- **API-First**: RESTful API for automation
- **Extensible**: Custom fields, webhooks, plugins
- **Multi-Vendor**: Cisco, Juniper, Arista, HPE, Dell - all supported
- **Open Source**: Free and actively maintained

## Quick Start (Local Development)

### 1. Start NetBox with Docker Compose

```bash
cd overgrowth

# Copy environment template
cp netbox.env.example netbox.env

# Start NetBox stack
docker-compose -f docker-compose-netbox.yml up -d

# Wait for services to start (30-60 seconds)
docker-compose -f docker-compose-netbox.yml logs -f netbox
```

### 2. Access NetBox

Open http://localhost:8000 in your browser

- **Username**: admin
- **Password**: admin (from netbox.env)
- **API Token**: 0123456789abcdef0123456789abcdef01234567

### 3. Configure Overgrowth

```bash
# Set environment variables
export NETBOX_URL="http://localhost:8000"
export NETBOX_TOKEN="0123456789abcdef0123456789abcdef01234567"

# Test connection
python test_netbox.py
```

### 4. Run Pipeline with NetBox

```bash
# Pipeline will automatically sync to NetBox
python app.py

# Or test from CLI
python -c "
from agent.pipeline_engine import OvergrowthPipeline, NetworkIntent
p = OvergrowthPipeline(use_netbox=True)
intent = NetworkIntent(
    description='Coffee shop network',
    business_requirements=['Guest WiFi', 'POS systems'],
    constraints=['Budget under $5000']
)
model = p.stage2_generate_sot(intent)
"
```

## Production Deployment

### Option 1: Self-Hosted NetBox

Follow official docs: https://docs.netbox.dev/en/stable/installation/

Requirements:
- PostgreSQL 12+
- Redis 6.2+
- Python 3.8+
- 2GB RAM minimum

### Option 2: Nautobot Cloud

Enterprise-supported hosted NetBox alternative:
- https://www.networktocode.com/nautobot/
- Free tier available
- Fully compatible with NetBox API

Configuration:
```bash
export NAUTOBOT_URL="https://yourinstance.nautobot.cloud"
export NAUTOBOT_TOKEN="your_api_token_here"
```

### Option 3: NetBox Cloud

Official hosted NetBox service:
- https://netboxlabs.com/netbox-cloud/
- 30-day free trial
- Managed infrastructure

## NetBox Configuration

### Initial Setup

1. **Create API Token** (in NetBox UI)
   - User menu → API Tokens → Add
   - Copy token to environment variable

2. **Enable Webhooks** (optional)
   - Admin → Webhooks → Add
   - URL: `http://your-overgrowth-server/webhook/netbox`
   - Events: `dcim.device`, `ipam.vlan`, `ipam.prefix`

3. **Import Manufacturers**
   ```bash
   # NetBox has built-in device library
   # Or import custom manufacturers via API
   ```

### Recommended Plugins

Add to `netbox.env`:
```
PLUGINS=['netbox_topology_views', 'netbox_acls', 'netbox_bgp']
```

Install plugins:
```bash
docker-compose -f docker-compose-netbox.yml exec netbox pip install \
  netbox-topology-views \
  netbox-acls \
  netbox-bgp
```

## Architecture

```
┌─────────────────────┐
│   Overgrowth UI     │
│   (Gradio App)      │
└──────────┬──────────┘


┌─────────────────────┐
│  Pipeline Engine    │
│  - Consultation     │
│  - LLM Design       │
│  - BOM Generation   │
└──────────┬──────────┘


┌─────────────────────┐      ┌──────────────────┐
│  NetBox Client      │◄────►│ NetBox/Nautobot  │
│  - Sites            │      │  - PostgreSQL    │
│  - Devices          │      │  - Redis         │
│  - VLANs/IPs        │      │  - REST API      │
│  - Sync Logic       │      └──────────────────┘
└─────────────────────┘


┌─────────────────────┐
│  GNS3 / Real Gear   │
│  (Deployment)       │
└─────────────────────┘
```

## Data Flow

1. **Consultation** → User provides requirements via natural language
2. **LLM Design** → Claude generates VLANs, subnets, device roles
3. **NetBox Sync** → Design written to NetBox via API
4. **YAML Backup** → Local YAML file created for version control
5. **BOM Generation** → Read from NetBox to create shopping list
6. **GNS3 Deploy** → Read from NetBox to generate configs
7. **Validation** → Compare actual network state vs NetBox

## API Usage Examples

### Python SDK (pynetbox)

```python
from agent.netbox_client import NetBoxClient

# Initialize client
nb = NetBoxClient()

# Create a site
site = nb.create_site(
    name="Office HQ",
    description="Main office location"
)

# Create VLANs
vlan = nb.create_vlan(
    vid=10,
    name="Management",
    site="Office HQ",
    description="Network management VLAN"
)

# Create IP prefix
prefix = nb.create_prefix(
    prefix="10.0.10.0/24",
    description="Management subnet",
    site="Office HQ",
    vlan=10
)

# Sync entire network model
network = {
    "name": "retail-store",
    "vlans": [...],
    "subnets": [...],
    "devices": [...]
}
summary = nb.sync_network_model(network)
print(f"Created {summary['devices']} devices, {summary['vlans']} VLANs")
```

### Direct REST API

```bash
# Get all devices
curl -H "Authorization: Token 0123456789abcdef0123456789abcdef01234567" \
     http://localhost:8000/api/dcim/devices/

# Create a VLAN
curl -X POST \
     -H "Authorization: Token 0123456789abcdef0123456789abcdef01234567" \
     -H "Content-Type: application/json" \
     -d '{"vid": 20, "name": "Users"}' \
     http://localhost:8000/api/ipam/vlans/
```

## Troubleshooting

### NetBox not connecting

```bash
# Check NetBox is running
docker-compose -f docker-compose-netbox.yml ps

# View logs
docker-compose -f docker-compose-netbox.yml logs netbox

# Restart services
docker-compose -f docker-compose-netbox.yml restart
```

### Import errors

```bash
# Install pynetbox
pip install pynetbox>=7.0.0

# Verify installation
python -c "import pynetbox; print(pynetbox.__version__)"
```

### API token issues

```bash
# Regenerate token in NetBox UI
# Update environment variable
export NETBOX_TOKEN="new_token_here"

# Test connection
python test_netbox.py
```

## Fallback Mode

If NetBox is unavailable, Overgrowth automatically falls back to YAML files:

```python
pipeline = OvergrowthPipeline(use_netbox=True)
# If NetBox connection fails, pipeline.use_netbox becomes False
# All operations continue using local YAML files
```

## Migration from YAML

To migrate existing YAML network models to NetBox:

```python
from agent.pipeline_engine import OvergrowthPipeline, NetworkModel

# Load existing YAML
pipeline = OvergrowthPipeline(use_netbox=True)
yaml_content = open("infra/network_model.yaml").read()
model = NetworkModel.from_yaml(yaml_content)

# Sync to NetBox
pipeline.netbox.sync_network_model(model.to_dict())
```

## Next Steps

- [ ] Configure NetBox webhooks for real-time updates
- [ ] Set up Batfish for pre-deployment validation (Stage 0)
- [ ] Integrate SuzieQ for drift detection (Stage 7b)
- [ ] Add GitOps workflow for NetBox changes
- [ ] Enable digital twin simulation (Stage 6b)

## Resources

- NetBox Docs: https://docs.netbox.dev/
- Nautobot Docs: https://docs.nautobot.com/
- pynetbox SDK: https://pynetbox.readthedocs.io/
- NetBox Community: https://netbox.dev/community/
- Overgrowth Issues: https://huggingface.co/spaces/MCP-1st-Birthday/overgrowth/discussions