Created
January 15, 2019 19:56
-
-
Save jrussett/8cfd72ea29424e8883b8cb71e6296d82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# NOTE: | |
# "It's not a backup, and it's not a complete NSX-T configuration" | |
# This shell-script hits the NSX-T API to download the configuration | |
# of small subset of the NSX-T infrastructure changed by the | |
# NCP (NSX-T tile) agent. | |
# | |
# For example, it downloads the configuration of the Routers and Switches, but | |
# not NAT, Load Balancers, nor Trust Management, etc... | |
if [ $# -ne 2 ]; then | |
echo "need two args: first arg is 'haas-xxx', second is nsxmgr password" | |
exit 1 | |
fi | |
ENV=$1 | |
PASSWD=$2 | |
curl -k "https://admin:$PASSWD@nsxmgr-01.$ENV.pez.pivotal.io/api/v1/logical-routers" > logical-routers.json | |
if grep -q "error_code.*403" logical-routers.json; then | |
echo "Wrong password! Bailing to avoid 15 minute account lockout" >&2 | |
exit 1 | |
fi | |
curl -k "https://admin:$PASSWD@nsxmgr-01.$ENV.pez.pivotal.io/api/v1/logical-switches" >logical-switches.json | |
curl -k "https://admin:$PASSWD@nsxmgr-01.$ENV.pez.pivotal.io/api/v1/ns-groups" > ns-groups.json | |
curl -k "https://admin:$PASSWD@nsxmgr-01.$ENV.pez.pivotal.io/api/v1/pools/ip-pools" > ip-pools.json | |
curl -k "https://admin:$PASSWD@nsxmgr-01.$ENV.pez.pivotal.io/api/v1/ip-sets" > ip-sets.json | |
curl -k "https://admin:$PASSWD@nsxmgr-01.$ENV.pez.pivotal.io/api/v1/logical-ports" > logical-ports.json | |
for firewall_section in $(curl -k "https://admin:$PASSWD@nsxmgr-01.$ENV.pez.pivotal.io/api/v1/firewall/sections" | jq -r '.results[].id'); do | |
curl -k "https://admin:$PASSWD@nsxmgr-01.$ENV.pez.pivotal.io/api/v1/firewall/sections/$firewall_section/rules" > firewall-rules-$firewall_section.json | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment