Forum Discussion
JamesSevedge_23
Historic F5 Account
The post removed my comment symbols out, below should be correct as it is in a code block.
!/bin/bash
This script will create an application service using the f5.http template. Commandline arg... -a is iapp name, -v is virtual server ip, -m is for pool member ip,
-b is the big ip address, -u is for username, -p for password (defaults of admin/admin if flags not present) -d is an optional paramater if you would like to delete the iapp.
Full Command would look like: ./createiapp_http.sh -b 2.2.2.2 -a httpapp -v 1.1.1.1 -m 1.1.1.2 -u admin -p admin
Full Command to delete would add the delete flag: ./createiapp_http.sh -b 2.2.2.2 -a httpapp -v 1.1.1.1 -m 1.1.1.2 -u admin -p admin -d
delete=false
user=admin
pwd=admin
while getopts a:v:b:u:p:m:d option
do case "$option" in
a) appname=$OPTARG;;
v) vsip=$OPTARG;;
m) pmember=$OPTARG;;
b) bigip=$OPTARG;;
u) user=$OPTARG;;
p) pwd=$OPTARG;;
d) delete=true;;
esac
done
echo "Delete equals: $delete"
echo "Connecting to BIG IP: $bigip as $user"
echo "iAPP Name: $appname"
echo "VS IP: $vsip"
echo "Pool Member: $pmember"
if [ $delete == false ] ; then
curl -sk -u $user:$pwd https://$bigip/mgmt/tm/sys/application/service/ -H 'Content-Type: application/json' -X POST -d '{"kind":"tm:sys:application:service:servicestate",
"name":'\"$appname\"',
"partition":"Common",
"execute-action":"definition",
"template":"/Common/f5.http",
"templateReference":{"link":"https://localhost/mgmt/tm/sys/application/template/~Common~f5.http?ver=12.0.0"},
"templateModified":"no",
"trafficGroup":"/Common/traffic-group-1",
"trafficGroupReference":{"link":"https://localhost/mgmt/tm/cm/traffic-group/~Common~traffic-group-1?ver=12.0.0"},
"tables":[{"name":"basic__snatpool_members"},
{"name":"net__snatpool_members"},
{"name":"optimizations__hosts"},
{"name":"pool__hosts",
"columnNames":["name"],"rows":[{"row":["test.test.com"]}]},
{"name":"pool__members",
"columnNames":["addr","port","connection_limit"],
"rows":[{"row":['\"$pmember\"',"80","0"]}]},
{"name":"server_pools__servers"}],
"variables":[{"name":"client__http_compression",
"encrypted":"no",
"value":"/create_new"},
{"name":"monitor__monitor",
"encrypted":"no","value":"/create_new"},
{"name":"monitor__response","encrypted":"no","value":"none"},
{"name":"monitor__uri","encrypted":"no","value":"/"},
{"name":"net__client_mode","encrypted":"no","value":"wan"},
{"name":"net__server_mode","encrypted":"no","value":"lan"},
{"name":"pool__addr","encrypted":"no","value":'\"$vsip\"'},
{"name":"pool__pool_to_use","encrypted":"no","value":"/create_new"},
{"name":"pool__port","encrypted":"no","value":"80"},
{"name":"asm__use_asm","value":"/do_not_use"},
{"name":"ssl__mode","encrypted":"no","value":"no_ssl"},
{"name":"ssl_encryption_questions__advanced","encrypted":"no","value":"no"},
{"name":"ssl_encryption_questions__help","encrypted":"no","value":"hide"}]}' | jq .
fi
if [ $delete == true ] ; then
curl -sk -u admin:admin https://$bigip/mgmt/tm/sys/application/service/~Common~$appname.app~$appname -H 'Content-Type: application/json' -X DELETE | jq .
echo "iAPP $appname deleted"
fi
JamesSevedge_23
Mar 07, 2016Historic F5 Account
Ok, I just tested this with my script. I had to manually modify the POST line though to include the app service path and change to PUT. You could expand the script to write that logic in. Basically it is exactly the same as creation except you change the POST to PUT and append the application service path onto the URI, as well as make the change to pool member, etc...
"curl -sk -u $user:$pwd https://$bigip/mgmt/tm/sys/application/service/~Common~$appname.app~$appname -H 'Content-Type: application/json' -X PUT -d "