File size: 2,646 Bytes
765065a
 
 
 
 
c7576e1
765065a
c7576e1
 
 
765065a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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)