Creating Virtual Services via a Linux Bash script using RESTful API.

A Bash script can be used to create multiple Virtual Services quickly via the RESTful API from a Linux host.

In this example, the Bash script will be used to create multiple Virtual Services - each with a different Virtual IP address but with the same Real Servers.

 Step 1. Create an IP Address List File

In this example a file called iplist is created. This contains a list of the Virtual IP addresses that will be used. 

2. Create a Script to Add the Required Virtual Services

The following script will create a new Virtual Service for every IP address in the IP list file with properties as can be seen in the RESTfulAPI command. These properties can be changed to suit requirements. Please refer to the RESTFul API Guide for available parameters.

In this example the IP address of the Loadmaster is 10.140.0.103 and password for the bal user is PASSWORD. This should be changed to suit the relevant setup.

Note: To enable the Virtual Services on creation, refer to Step 6 for the additional text to add.

 

The example script text is below:

#! /bin/bash

for IP in `cat iplist`
do
wget "https://bal:PASSWORD@10.140.0.103/access/addvs?vs=$IP&port=80&prot=tcp&AddVia=0&ForceL7=Y&CheckType=http&CheckHost=hostname.com&CheckUrl=/&CheckUse1.1=Y&CheckPort=80&Enable=N&VStype=http&VSPort=80&Protocol=tcp&Transparent=Y&Verify=3&VSAddress=$IP&StartTLSMode=0" --no-check-certificate

wget "https://bal:PASSWORD@10.140.0.103/access/addrs?vs=$IP&port=80&prot=tcp&rs=10.140.0.20&rsport=80" --no-check-certificate

wget "https://bal:PASSWORD@10.140.0.103/access/addrs?vs=$IP&port=80&prot=tcp&rs=10.140.0.21&rsport=80" --no-check-certificate
done

 

3. Make the File Executable

Change the permission of the script file to make it executable by running the chmod command:

4. Enable the API Interface on the LoadMaster

In the main menu of the LoadMaster Web User Interface (WUI), go to System Configuration > Miscellaneous Options > Remote Access.

Select the Enable API Interface check box.

 

5. Run Script

 Execute the script by running the following command:

 

The Virtual Services are now created on the LoadMaster containing the appropriate Real Servers.

 

6. Enabling the Virtual Services

Depending on the situation, you may want to enable the Virtual Services when creating them. This can be done by inserting a line with the following syntax to the script before the done line. The Virtual Service being enabled is referenced by the IP address, port and protocol. So, following the syntax of the script above:

wget "https://bal:PASSWORD@10.140.0.103/access/modvs?vs=$IP&port=80&prot=tcp&Enable=Y"  --no-check-certificate

Alternatively, if you would like to do this separately you can create another script, for example enableVS.sh, and run it as a separate script.

 

Example script to enable the Virtual Service:

#! /bin/bash

for IP in `cat iplist`
do

wget "https://bal:PASSWORD@10.140.0.103/access/modvs?vs=$IP&port=80&prot=tcp&Enable=Y"  --no-check-certificate

done

 

Was this article helpful?

0 out of 0 found this helpful

Comments