#!/usr/bin/env python3 import subprocess import time import sys # This script removes a route and adds it again to address a timing issue # for L2GRE tunnels # # Adapt to your needs # -Benny # Destination destination = "1.1.1.1" # Mask e.g. /32 mask = "32" # Gateway gateway = "192.168.2.1" # Maximum uptime until which this script will run after a coldStart/warmStart trap # This avoids running on "trap-replay" situations, sometimes triggered by NMS # Make sure to specify this as a float 300.0 for 5 minutes max_uptime = 300.0 # # Do not modify below this line # print("restore-route.py: Script was started via event-action following a reboot, resetting route to help L2GRE tunnels") uptime = time.clock_gettime(time.CLOCK_BOOTTIME) print(f"restore-route.py: System uptime is at {uptime} seconds") if uptime > max_uptime: sys.exit("restore-route.py: Reached maximum uptime to apply this workaround.") subprocess.run(['no', 'ip', 'static-route', f'{destination}/{mask}', 'gateway', f'{gateway}'], capture_output=False) print(f"restore-route.py: Removed route to {destination}/{mask} via {gateway}") subprocess.run(['ip', 'static-route', f'{destination}/{mask}', 'gateway', f'{gateway}'], capture_output=False) print(f"restore-route.py: Added route to {destination}/{mask} via {gateway}")