-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
236 lines (201 loc) · 6.13 KB
/
Copy pathdeploy.sh
File metadata and controls
236 lines (201 loc) · 6.13 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash
# Quick deployment script for multi-DC EVPN fabric
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"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Helper functions
print_header() {
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}$1${NC}"
echo -e "${GREEN}========================================${NC}"
}
print_info() {
echo -e "${YELLOW}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[✓]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check prerequisites
check_prerequisites() {
print_header "Checking Prerequisites"
# Check Docker
if ! command -v docker &> /dev/null; then
print_error "Docker not found. Please install Docker."
exit 1
fi
print_success "Docker found"
# Check containerlab
if ! command -v containerlab &> /dev/null; then
print_error "Containerlab not found. Installing..."
bash -c "$(curl -sL https://get.containerlab.dev)"
fi
print_success "Containerlab available"
# Check Ansible
if ! command -v ansible &> /dev/null; then
print_error "Ansible not found. Please install: pip3 install ansible"
exit 1
fi
print_success "Ansible found"
# Check Python packages
if ! python3 -c "import netmiko" 2>/dev/null; then
print_info "Installing Python dependencies..."
pip3 install -r "$SCRIPT_DIR/requirements.txt"
fi
print_success "Python dependencies installed"
}
# Fix graphite topology data format
# Newer containerlab versions wrap links in {"endpoints": {...}} but graphite expects flat {"a": ..., "z": ...}
fix_graphite() {
local topo_json="$CLAB_DIR/clab-multi-dc-evpn/topology-data.json"
if [ -f "$topo_json" ]; then
print_info "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)
print(f'Fixed {len(data[\"links\"])} links')
"
docker restart clab-multi-dc-evpn-graphite 2>/dev/null && \
print_success "Graphite restarted with fixed topology data" || true
fi
}
# Deploy topology
deploy_topology() {
print_header "Deploying Containerlab Topology"
cd "$CLAB_DIR"
print_info "Starting containerlab topology..."
containerlab deploy --topo clab-topology.yml
fix_graphite
print_success "Topology deployed successfully"
print_info "Graphite topology viewer: http://localhost:8080/graphite/"
print_info "Waiting 30 seconds for devices to stabilize..."
sleep 30
}
# Deploy configurations
deploy_configs() {
print_header "Deploying Network Configurations"
cd "$ANSIBLE_DIR"
print_info "Running Ansible deployment playbook..."
# Check if inventory is reachable
ansible-inventory -i inventory.yml --graph
print_info "Deploying to DC1 and DC2..."
ansible-playbook -i inventory.yml deploy.yml \
-k \
--tags "configure" \
-v
print_success "Configurations deployed"
}
# Run validation tests
run_tests() {
print_header "Running Network Validation Tests"
cd "$TESTS_DIR"
print_info "Executing pytest suite..."
if pytest test_fabric.py -v --tb=short; then
print_success "All tests passed!"
else
print_error "Some tests failed. Check output above."
return 1
fi
}
# Display topology info
show_topology() {
print_header "Topology Information"
cd "$CLAB_DIR"
containerlab inspect -t clab-topology.yml
print_info "Device credentials:"
echo " Username: admin"
echo " Password: admin"
echo ""
print_info "Access devices:"
echo " DC1-Spine1: ssh admin@172.20.20.2"
echo " DC1-Leaf1: ssh admin@172.20.20.4"
echo " DC2-Spine1: ssh admin@172.20.20.8"
echo " DC2-Leaf1: ssh admin@172.20.20.10"
}
# Cleanup
cleanup() {
print_header "Cleaning Up"
cd "$CLAB_DIR"
print_info "Destroying containerlab topology..."
containerlab destroy --topo clab-topology.yml --cleanup
print_success "Cleanup complete"
}
# Main menu
show_menu() {
echo ""
echo "Multi-DC EVPN Fabric Management"
echo "=================================="
echo "1. Check prerequisites"
echo "2. Deploy topology"
echo "3. Deploy configurations"
echo "4. Run validation tests"
echo "5. Show topology info"
echo "6. Full deployment (1-5)"
echo "7. Cleanup (destroy topology)"
echo "8. Exit"
echo ""
}
# Main logic
main() {
if [ $# -eq 0 ]; then
# Interactive mode
while true; do
show_menu
read -p "Select option: " choice
case $choice in
1) check_prerequisites ;;
2) deploy_topology ;;
3) deploy_configs ;;
4) run_tests ;;
5) show_topology ;;
6)
check_prerequisites
deploy_topology
show_topology
;;
7) cleanup ;;
8)
print_info "Exiting..."
exit 0
;;
*)
print_error "Invalid option. Please try again."
;;
esac
done
else
# Command line mode
case "$1" in
check) check_prerequisites ;;
deploy) deploy_topology ;;
config) deploy_configs ;;
test) run_tests ;;
info) show_topology ;;
full)
check_prerequisites
deploy_topology
show_topology
;;
cleanup) cleanup ;;
*)
echo "Usage: $0 [check|deploy|config|test|info|full|cleanup]"
exit 1
;;
esac
fi
}
# Run main
main "$@"