-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.sh
More file actions
executable file
·80 lines (68 loc) · 2.55 KB
/
cleanup.sh
File metadata and controls
executable file
·80 lines (68 loc) · 2.55 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
#!/bin/bash
echo "========================================="
echo "VPC CLI - Cleanup Script"
echo "========================================="
echo ""
echo "Cleaning up all VPC peering connections..."
if [ -d "/tmp/vpc_peering" ]; then
for peering_file in /tmp/vpc_peering/*.json; do
if [ -f "$peering_file" ]; then
# Extract VPC names from filename (format: vpc1-vpc2.json)
basename=$(basename "$peering_file" .json)
vpc1=$(echo "$basename" | cut -d'-' -f1)
vpc2=$(echo "$basename" | cut -d'-' -f2-)
echo "Deleting peering: $vpc1 <-> $vpc2"
sudo python3 vpcctl.py delete-peering "$vpc1" "$vpc2" 2>/dev/null || true
fi
done
else
echo "No peering directory found"
fi
echo ""
echo "Deleting test VPCs..."
sudo python3 vpcctl.py delete-vpc vpc-test 2>/dev/null || echo "VPC vpc-test not found"
echo ""
echo "Deleting VPC 'vpc-test2'..."
sudo python3 vpcctl.py delete-vpc vpc-test2 2>/dev/null || echo "VPC vpc-test2 not found"
echo ""
echo "Deleting demo VPC..."
sudo python3 vpcctl.py delete-vpc demo-vpc 2>/dev/null || echo "VPC demo-vpc not found"
echo ""
echo "Cleaning up config directories..."
sudo rm -rf /tmp/vpc_config
sudo rm -rf /tmp/vpc_peering
sudo rm -f /tmp/firewall_rules.json
echo ""
echo "Cleaning up any orphaned namespaces..."
for ns in $(sudo ip netns list 2>/dev/null | awk '{print $1}'); do
if [[ "$ns" == ns-vpc-* ]] || [[ "$ns" == ns-demo-* ]]; then
echo "Deleting namespace: $ns"
sudo ip netns delete "$ns" 2>/dev/null || true
fi
done
echo ""
echo "Cleaning up orphaned veth interfaces..."
# Clean up peering veth pairs first
for iface in $(ip link show | grep -oE "peer-[^:@]+" | sort -u); do
echo "Deleting peering interface: $iface"
sudo ip link delete "$iface" 2>/dev/null || true
done
# Clean up other veth interfaces
for iface in $(ip link show | grep -oE "(veth-|v-|vb-|ve)[^:@]+" | awk '{print $1}' | sort -u); do
echo "Deleting veth interface: $iface"
sudo ip link delete "$iface" 2>/dev/null || true
done
echo ""
echo "Cleaning up orphaned bridges..."
for br in $(ip link show | grep "br-vpc-\|br-demo-" | awk -F: '{print $2}' | awk '{print $1}'); do
sudo ip link set "$br" down 2>/dev/null || true
sudo ip link delete "$br" 2>/dev/null || true
done
echo ""
echo "Flushing iptables NAT rules..."
sudo iptables -t nat -F 2>/dev/null || true
sudo iptables -F FORWARD 2>/dev/null || true
echo ""
echo "========================================="
echo "Cleanup Complete!"
echo "========================================="