File size: 2,980 Bytes
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
84
85
86
87
#!/usr/bin/env python3
"""Connect all nodes in the overgrowth CCNA topology"""

import requests
import json

GNS3_API = "http://localhost:3080/v2"
PROJECT_ID = "1f712057-b33d-433f-90bb-2b9b3804a95e"

def get_nodes():
    resp = requests.get(f"{GNS3_API}/projects/{PROJECT_ID}/nodes")
    nodes = resp.json()
    node_dict = {n['name']: n for n in nodes}
    return node_dict

def create_link(node1_id, adapter1, port1, node2_id, adapter2, port2, desc=""):
    data = {
        "nodes": [
            {"node_id": node1_id, "adapter_number": adapter1, "port_number": port1},
            {"node_id": node2_id, "adapter_number": adapter2, "port_number": port2}
        ]
    }
    resp = requests.post(f"{GNS3_API}/projects/{PROJECT_ID}/links", json=data)
    if resp.status_code in [200, 201]:
        print(f"  ✓ {desc}")
        return True
    else:
        print(f"  ✗ {desc} - Error: {resp.status_code}")
        return False

nodes = get_nodes()
print("Connecting CCNA Topology Links...\n")

links = 0

# PC2 -> SW1 (all switch ports use adapter 0)
if 'PC2-Sales' in nodes and 'SW1-Access' in nodes:
    if create_link(nodes['PC2-Sales']['node_id'], 0, 0,
                  nodes['SW1-Access']['node_id'], 0, 1,
                  "PC2-Sales <-> SW1-Access (Port 1)"):
        links += 1

# SW1 -> SW2 (Trunk)
if 'SW1-Access' in nodes and 'SW2-Core' in nodes:
    if create_link(nodes['SW1-Access']['node_id'], 0, 7,
                  nodes['SW2-Core']['node_id'], 0, 0,
                  "SW1-Access <-> SW2-Core (Trunk Port 7-0)"):
        links += 1

# PC3 -> SW2
if 'PC3-Engineering' in nodes and 'SW2-Core' in nodes:
    if create_link(nodes['PC3-Engineering']['node_id'], 0, 0,
                  nodes['SW2-Core']['node_id'], 0, 1,
                  "PC3-Engineering <-> SW2-Core (Port 1)"):
        links += 1

# PC4 -> SW2
if 'PC4-Engineering' in nodes and 'SW2-Core' in nodes:
    if create_link(nodes['PC4-Engineering']['node_id'], 0, 0,
                  nodes['SW2-Core']['node_id'], 0, 2,
                  "PC4-Engineering <-> SW2-Core (Port 2)"):
        links += 1

# SW2 -> SW3 (Trunk)
if 'SW2-Core' in nodes and 'SW3-Access' in nodes:
    if create_link(nodes['SW2-Core']['node_id'], 0, 7,
                  nodes['SW3-Access']['node_id'], 0, 7,
                  "SW2-Core <-> SW3-Access (Trunk Port 7-7)"):
        links += 1

# PC6 -> SW3
if 'PC6-Guest' in nodes and 'SW3-Access' in nodes:
    if create_link(nodes['PC6-Guest']['node_id'], 0, 0,
                  nodes['SW3-Access']['node_id'], 0, 1,
                  "PC6-Guest <-> SW3-Access (Port 1)"):
        links += 1

# Internet -> SW2
if 'Internet' in nodes and 'SW2-Core' in nodes:
    if create_link(nodes['Internet']['node_id'], 0, 0,
                  nodes['SW2-Core']['node_id'], 0, 15,
                  "Internet Cloud <-> SW2-Core (Port 15)"):
        links += 1

print(f"\n✓ Created {links} new links!")
print(f"Total links should now be: {links + 2} (2 existing + {links} new)")