File size: 2,818 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
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
"""
Wait for Cisco switches to fully boot and become accessible
Tests console connectivity until switches respond
"""

import socket
import time
import sys

switches = {
    "SW-HQ-Core": 5046,
    "SW-West": 5059,
    "SW-East": 5069
}

def test_console(port):
    """Try to connect to console port"""
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(2)
        result = sock.connect_ex(('localhost', port))
        sock.close()
        return result == 0
    except:
        return False

print("="*70)
print("🔌 CHECKING SWITCH CONSOLE AVAILABILITY")
print("="*70)
print("\nCisco IOSvL2 switches take 2-5 minutes to fully boot...")
print("Checking console port connectivity...\n")

max_wait = 300  # 5 minutes
start_time = time.time()
ready_switches = set()

while (time.time() - start_time) < max_wait:
    all_ready = True
    
    for switch_name, port in switches.items():
        if switch_name in ready_switches:
            continue
            
        if test_console(port):
            ready_switches.add(switch_name)
            elapsed = int(time.time() - start_time)
            print(f"✅ {switch_name:20} port {port} is READY! (after {elapsed}s)")
        else:
            all_ready = False
    
    if len(ready_switches) == len(switches):
        break
    
    time.sleep(5)

elapsed = int(time.time() - start_time)

print("\n" + "="*70)
if len(ready_switches) == len(switches):
    print(f"✅ ALL SWITCHES READY after {elapsed} seconds!")
    print("="*70)
    print("\n📋 How to access consoles:")
    print("\n  From GNS3 GUI:")
    print("    • Right-click switch → Console")
    print("    • Opens telnet session automatically")
    
    print("\n  From command line:")
    for switch_name, port in switches.items():
        print(f"    • {switch_name:20}: telnet localhost {port}")
    
    print("\n  From Python/MCP (next step!):")
    print("    • Use paramiko SSH after configuring switch IPs")
    print("    • Or use telnetlib for initial config")
    
    print("\n🎯 NEXT STEPS:")
    print("  1. Console into switches via GNS3 GUI")
    print("  2. Configure VLANs and management IPs")
    print("  3. Enable SSH for remote automation")
    print("  4. Use MCP server to automate configs!")
    
else:
    print(f"⚠️  TIMEOUT: Only {len(ready_switches)}/{len(switches)} switches ready after {elapsed}s")
    print("="*70)
    print("\nStill booting:")
    for switch_name in switches:
        if switch_name not in ready_switches:
            print(f"  • {switch_name}")
    
    print("\n💡 Options:")
    print("  1. Wait longer - switches may still be booting")
    print("  2. Check GNS3 GUI console for boot errors")
    print("  3. Restart switches if stuck")

print("="*70)