Forum Discussion
Disable Multiple Pools Members At Once
Okay, this is a very rough attempt, but it mostly gets the job done. The below script requires three parameters:
* pool name
* enable or disable
* a comma-delimited list of pool members defined by IP:port
So for example:
./update-pool.sh test-pool disable 10.10.10.10:80,10.10.10.11:80
So based on the entered list of pool members, the script will loop through the existing pool members and create a new update string, then launch a cURL to update the pool. As it stands, if the (existing) pool member isn't listed in the argument it'll be marked up. To get around that you'd need to enumerate the current status of all of the pool existing pool members, and I didn't want to do that. I also didn't parameterize the server host/IP so there's two places in the below script where you have to change that.
!/bin/bash
if [ -z "$1" ]
then
bad arguments - quit
echo "Syntax: update-pool.sh "
else
build member list from arguments
args=($(echo $3 |tr "," "\n"))
set pool
thispool=$1
set enabled/disabled
action=$2
build pool list
pool=($(curl -sk -u 'admin:password' -H "Content-Type: application/json" -X GET https://x.x.x.x/mgmt/tm/ltm/pool/${thispool}?expandSubcollections=true | sed 's/,/\'$'\n/g' | grep name | grep -v ${thispool} | awk -F"\"" '{ print $4 }'))
establish the memberstring
memberstring="{\"members\":["
loop through the pool members to see if any are one of the arguments
for i in "${pool[@]}"
do
notin=0
loop through the argument member list
for j in "${args[@]}"
do
if [ "$i" == "$j" ]
then
notin=1
fi
done
if the argument member was in the pool - update the memberstring value
if [ $notin -eq 1 ]
then
if [ "$action" == "disable" ]
then
memberstring="${memberstring}{\"name\":\"$i\",\"state\":\"user-up\",\"session\":\"user-disabled\"},"
elif [ "$action" == "enable" ]
then
memberstring="${memberstring}{\"name\":\"$i\",\"state\":\"user-up\",\"session\":\"user-enabled\"},"
fi
else
memberstring="${memberstring}{\"name\":\"$i\",\"state\":\"user-up\",\"session\":\"user-enabled\"},"
fi
done
remove the last comma and add the end of the POST characters
memberstring="${memberstring%?}]}"
prints completed memberstring - enable for testing
echo "executing: $memberstring"
execute the cURL PATCH to update the pool
curl -sk -u 'admin:password' -H "Content-Type: application/json" -X PATCH https://x.x.x.x/mgmt/tm/ltm/pool/${thispool} -d $memberstring
fi
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com