File size: 2,180 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
#!/usr/bin/env python3
"""Add the final 2 missing links"""

import requests
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")

def get_project_id(name):
    resp = requests.get(f"{GNS3_API}/projects")
    projects = resp.json()
    project = next((p for p in projects if p['name'] == name), None)
    return project['project_id'] if project else None

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

def create_link(project_id, 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} - {resp.status_code}: {resp.text[:150]}")
        return False

project_id = get_project_id(PROJECT_NAME)
nodes = get_nodes(project_id)

print("Adding final 2 links...\n")

# PC2 -> SW1 (find available port on SW1)
pc2 = nodes.get('PC2-Sales')
sw1 = nodes.get('SW1-Access2')
if pc2 and sw1:
    # Try different ports on SW1 (0 and 2 are used, try 1, 3, 4, 5...)
    for port_num in [1, 3, 4, 5, 6, 7]:
        if create_link(project_id, pc2['node_id'], 0, 0, sw1['node_id'], port_num, 0,
                      f"PC2-Sales β†’ SW1 e{port_num}"):
            break

# PC3 -> SW2 (find available port on SW2)
pc3 = nodes.get('PC3-Engineering')
sw2 = nodes.get('SW2-Core2')
if pc3 and sw2:
    # Try different ports on SW2 (1, 2, 3, 4 are used, try 0, 5, 6, 7...)
    for port_num in [0, 5, 6, 7, 8, 9]:
        if create_link(project_id, pc3['node_id'], 0, 0, sw2['node_id'], port_num, 0,
                      f"PC3-Engineering β†’ SW2 e{port_num}"):
            break

print("\nβœ… Done! Run verify_ccna_status.py to confirm.")