For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Curl script for F5 Cloud DNS

Problem this snippet solves:

Deploy new zones on F5 Cloud secondary DNS

How to use this snippet:

Curl / bash

Code :

if [ -z $1 ] ; then
echo "Requires a domain to deploy to F5 cloud DNS"
echo "Domain should already exist on the master "
exit 2
fi



echo "Getting an API token"
token=`curl -s --data '{"username":"YOUR_USERNAME_HERE,"password":"YOUR_PASSWORD_HERE"}'  --header "Content-Type:application/json" https://api.cloudservices.f5.com//v1/svc-auth/login|grep access_token|awk -F: '{print $2}'|awk -F\" '{print $2}'`

if [ $? != 0 ] ; then
echo "Problem getting token"
exit 2
fi





echo "Getting account id"
accountid=`curl -s --header "Authorization:Bearer $token" -X GET https://api.cloudservices.f5.com//v1/svc-account/user|awk -F"primary_account_id\":" '{print $2}'|awk -F\" '{print $2}'`
if [ $? != 0 ] ; then
echo "Problem getting account id"
exit 2
fi




domain=$1
echo "Adding the domain and getting the new subscription id"
subscriptionid=`curl -s --header "Authorization:Bearer $token" --data "{\"account_id\":\"$accountid\",\"catalog_id\":\"c-aaxBJkfg8u\",\"service_instance_name\":\"Domain_Service\",\"service_type\":\"adns\",\"configuration\":{\"adns_service\":{\"enable\":true,\"zone\":\"$domain\",\"master_servers\":[\"YOUR_MASTER_IP_ADDRESS_HERE\"]}}}"  --header "Content-Type:application/json" https://api.cloudservices.f5.com//v1/svc-subscription/subscriptions|awk -F"subscription_id\":" '{print $2}'|awk -F\" '{print $2}'`

echo $subscriptionid

if [ $? != 0 ] ; then
echo "Problem adding the domain or getting the subscription id"
exit 2
fi

echo "Enabling new domain"
curl -s -X POST --header "Authorization:Bearer $token" --header "Content-Type:application/json" https://api.cloudservices.f5.com//v1/svc-subscription/subscriptions/$subscriptionid/activate

if [ $? != 0 ] ; then
echo "Problem enabling the new domain/subscription"
exit 2
fi

echo
echo "Success - new domain $domain is added"

Tested this on version:

13.0
Published Oct 29, 2019
Version 1.0
No CommentsBe the first to comment