overgrowth / mcp-server /wait_for_switches.py
Graham Paasch
Bundle MCP server with app for HuggingFace deployment
765065a
Raw
History Blame
2.82 kB
#!/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)