Skip to content

Instantly share code, notes, and snippets.

@cpswan
Created July 23, 2015 20:46
Show Gist options
  • Save cpswan/faa4748227dde29379d3 to your computer and use it in GitHub Desktop.
Save cpswan/faa4748227dde29379d3 to your computer and use it in GitHub Desktop.
VNS3 IPsec tunnel example
#!/bin/bash
# Set credentials and address for VNS3 manager
VNS3_PW=pa55Word
VNS3_IP=10.11.22.33
# Use IPsec connection 2
VNS3_EP=2
# Clear out any existing IPsec tunnels
while true; do
TUNNEL=$(curl -s -k -X GET -u api:"$VNS3_PW" \
https://"$VNS3_IP":8000/api/ipsec | python -mjson.tool \
| grep -A1 "tunnels" | tail -n 1 | grep -oP '(?<=").*(?=")')
if [[ "$TUNNEL" != 'type": "ipsec' ]]; then
echo Deleting "$TUNNEL"
curl -s -k -X DELETE -u api:"$VNS3_PW" \
https://"$VNS3_IP":8000/api/ipsec/endpoints/"$VNS3_EP"/subnets/"$TUNNEL"
else
echo No more tunnels
break
fi
done
# Bring up tunnel
curl -s -k -X POST -u api:"$VNS3_PW" -H 'Content-Type: application/json' \
https://"$VNS3_IP":8000/api/ipsec/endpoints/"$VNS3_EP"/tunnels \
-d '{"local_subnet":"123.45.67.89/32","remote_subnet":"124.56.78.90/23","description":"A_new_tunnel"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment