-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.sh
More file actions
193 lines (168 loc) · 5.96 KB
/
quickstart.sh
File metadata and controls
193 lines (168 loc) · 5.96 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
# Multi-DC EVPN Fabric - Quick Start Script
# Automates containerlab deployment and validation
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLAB_DIR="$SCRIPT_DIR/containerlab"
ANSIBLE_DIR="$SCRIPT_DIR/ansible"
TESTS_DIR="$SCRIPT_DIR/tests"
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ Multi-Datacenter VXLAN EVPN Fabric Deployment ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
# Check dependencies
check_deps() {
echo "[*] Checking dependencies..."
if ! command -v containerlab &> /dev/null; then
echo "❌ containerlab not found. Install: bash -c \"\$(curl -sL https://get.containerlab.dev)\""
exit 1
fi
if ! command -v ansible &> /dev/null; then
echo "❌ ansible not found. Install: pip3 install -r requirements.txt"
exit 1
fi
if ! command -v pytest &> /dev/null; then
echo "❌ pytest not found. Install: pip3 install -r requirements.txt"
exit 1
fi
echo "✓ All dependencies found"
echo ""
}
# Fix graphite topology data format
fix_graphite() {
local topo_json="$CLAB_DIR/clab-multi-dc-evpn/topology-data.json"
if [ -f "$topo_json" ]; then
echo "[*] Fixing graphite topology data format..."
python3 -c "
import json
with open('$topo_json', 'r') as f:
data = json.load(f)
data['links'] = [l.get('endpoints', l) for l in data['links']]
with open('$topo_json', 'w') as f:
json.dump(data, f, indent=2)
"
docker restart clab-multi-dc-evpn-graphite 2>/dev/null && \
echo "✓ Graphite restarted" || true
fi
}
# Deploy topology
deploy_topology() {
echo "[*] Deploying containerlab topology..."
cd "$CLAB_DIR"
if containerlab deploy --topo clab-topology.yml; then
echo "✓ Topology deployed successfully"
else
echo "❌ Failed to deploy topology"
exit 1
fi
fix_graphite
echo "✓ Graphite topology viewer: http://localhost:8080/graphite/"
echo "[*] Waiting for devices to stabilize (30 seconds)..."
sleep 30
echo ""
}
# Verify topology
verify_topology() {
echo "[*] Verifying topology..."
cd "$CLAB_DIR"
if containerlab inspect -t clab-topology.yml; then
echo "✓ Topology verification passed"
else
echo "❌ Topology verification failed"
exit 1
fi
echo ""
}
# Deploy configurations
deploy_configs() {
echo "[*] Deploying network configurations..."
cd "$ANSIBLE_DIR"
if ansible-playbook -i inventory.yml deploy.yml --tags deploy -v; then
echo "✓ Configuration deployment completed"
else
echo "⚠ Configuration deployment encountered issues (this is expected in lab)"
fi
echo ""
}
# Run tests
run_tests() {
echo "[*] Running network validation tests..."
cd "$TESTS_DIR"
if pytest test_fabric.py -v --tb=short; then
echo "✓ All tests passed!"
else
echo "⚠ Some tests failed (expected if devices not fully configured)"
fi
echo ""
}
# Destroy topology
destroy_topology() {
echo "[*] Destroying containerlab topology..."
cd "$CLAB_DIR"
if containerlab destroy --topo clab-topology.yml --cleanup; then
echo "✓ Topology destroyed"
fi
echo ""
}
# Main menu
main_menu() {
echo "Select action:"
echo " 1) Deploy everything (topology + configs + tests)"
echo " 2) Deploy topology only"
echo " 3) Deploy configs only"
echo " 4) Run tests only"
echo " 5) Verify topology"
echo " 6) Destroy topology"
echo " 7) Exit"
echo ""
read -p "Enter choice [1-7]: " choice
case $choice in
1)
check_deps
deploy_topology
verify_topology
deploy_configs
run_tests
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ Deployment Complete! Ready for testing ║"
echo "║ ║"
echo "║ Access devices: ║"
echo "║ ssh admin@172.20.20.2 # dc1-spine1 ║"
echo "║ ssh admin@172.20.20.4 # dc1-leaf1 ║"
echo "║ ssh admin@172.20.20.8 # dc2-spine1 ║"
echo "║ ║"
echo "║ Run tests anytime: ║"
echo "║ cd tests && pytest test_fabric.py -v ║"
echo "║ ║"
echo "║ Destroy when done: ║"
echo "║ ./quickstart.sh -> option 6 ║"
echo "╚════════════════════════════════════════════════════════════╝"
;;
2)
check_deps
deploy_topology
verify_topology
;;
3)
deploy_configs
;;
4)
run_tests
;;
5)
verify_topology
;;
6)
destroy_topology
;;
7)
echo "Goodbye!"
exit 0
;;
*)
echo "Invalid choice"
;;
esac
}
# Run main menu
main_menu