overgrowth / mcp-server /verify_ccna_status.py
Graham Paasch
Fix: Use environment variables for GNS3 server URL
c7576e1
raw
history blame
2.65 kB
#!/usr/bin/env python3
"""Verify CCNA topology status"""
import requests
import json
import os
GNS3_SERVER = os.getenv("GNS3_SERVER", "http://localhost:3080")
GNS3_API = f"{GNS3_SERVER}/v2"
PROJECT_NAME = os.getenv("GNS3_PROJECT_NAME", "overgrowth")
# Get project ID
resp = requests.get(f"{GNS3_API}/projects")
projects = resp.json()
project = next((p for p in projects if p['name'] == PROJECT_NAME), None)
if not project:
print(f"Project '{PROJECT_NAME}' not found!")
exit(1)
project_id = project['project_id']
# Get nodes
resp = requests.get(f"{GNS3_API}/projects/{project_id}/nodes")
nodes = {n['node_id']: n for n in resp.json()}
# Get links
resp = requests.get(f"{GNS3_API}/projects/{project_id}/links")
links = resp.json()
print("="*70)
print("CCNA TOPOLOGY STATUS")
print("="*70)
print(f"\nπŸ“Š Devices: {len(nodes)}")
for node in sorted(nodes.values(), key=lambda n: n['name']):
status = "🟒" if node['status'] == 'started' else "πŸ”΄"
print(f" {status} {node['name']:20} ({node['node_type']})")
print(f"\nπŸ”— Links: {len(links)}")
for i, link in enumerate(links, 1):
link_nodes = link.get('nodes', [])
if len(link_nodes) >= 2:
n1_id = link_nodes[0]['node_id']
n2_id = link_nodes[1]['node_id']
n1_name = nodes.get(n1_id, {}).get('name', 'Unknown')
n2_name = nodes.get(n2_id, {}).get('name', 'Unknown')
n1_port = f"{link_nodes[0]['adapter_number']}/{link_nodes[0]['port_number']}"
n2_port = f"{link_nodes[1]['adapter_number']}/{link_nodes[1]['port_number']}"
print(f" {i}. {n1_name:20} {n1_port:5} ↔ {n2_port:5} {n2_name}")
print("\n" + "="*70)
# Check what's missing
expected_links = [
("PC1-Sales", "SW1"),
("PC2-Sales", "SW1"),
("SW1", "SW2"),
("PC3-Engineering", "SW2"),
("PC4-Engineering", "SW2"),
("SW2", "SW3"),
("PC5-Guest", "SW3"),
("PC6-Guest", "SW3"),
]
actual_connections = set()
for link in links:
link_nodes = link.get('nodes', [])
if len(link_nodes) >= 2:
n1_id = link_nodes[0]['node_id']
n2_id = link_nodes[1]['node_id']
n1_name = nodes.get(n1_id, {}).get('name', '')
n2_name = nodes.get(n2_id, {}).get('name', '')
# Normalize names
for exp_n1, exp_n2 in expected_links:
if (exp_n1 in n1_name and exp_n2 in n2_name) or (exp_n1 in n2_name and exp_n2 in n1_name):
actual_connections.add((exp_n1, exp_n2))
print("\nπŸ“‹ Expected Connections:")
for exp in expected_links:
status = "βœ…" if exp in actual_connections else "⚠️ MISSING"
print(f" {status} {exp[0]} ↔ {exp[1]}")
print("\n" + "="*70)