It seems like your browser didn't download the required fonts. Please revise your security settings and try again.
Barracuda Load Balancer

Sample Program - Multiple Functions

  • Last updated on

This program uses most of the API calls described in the article API Descriptions. It performs the following functions:

  • Adds a Service and a Real Server;
  • Shows the Service and Real Server state before and after setting the state of the Real Server to maintenance mode;
  • Deletes the Real Server and the Service.

You can copy and paste this code into a file and save it as sample.pl. Edit the IP addresses – 10.5.126.63 should be the WAN IP address of the Barracuda Load Balancer, 192.168.132.214 is the VIP address of a Service, and 15.15.15.11 is the IP address of a Real Server. Change the password to the API password for the Barracuda Load Balancer.

To run sample.pl, at a command prompt type:
perl sample.pl

sample.pl

#!/usr/bin/perl
use strict;
use warnings;

use XML::RPC;
use LWP::UserAgent;
use Data::Dumper;

my $ua = LWP::UserAgent->new ;

$ua->timeout( 60 ) ;

# Create the XML::RPC object
my $xmlrpc = XML::RPC->new (
            'https://10.5.126.63/cgi-mod/api.cgi?password=admin',
            'lwp_useragent' => $ua );
my $result;

#Add a Service
$result = $xmlrpc->call('service.add',
      {name=>'xml_rpc_test',
      vip=>'192.168.132.214',
      protocol=>'TCP',
      port=>'21',
      type=>'L4'});
print Dumper ($result);

#Add a Real Server
$result = $xmlrpc->call('server.add',
      {vip=>'192.168.132.214:21:TCP',ip => '15.15.15.11',port => '21'});
print Dumper ($result);

my $service_show = 'status/state' ;
#Show all Services and Real Servers state
$result = $xmlrpc->call('service.show', {show=> $service_show});

print Dumper ($result);

#Change Real Server status to maintenance mode (could be one of disable/enable/maintenance)
$result = $xmlrpc->call('server.change_state',
    {vip=>'192.168.132.214:21:TCP',
    port=>'21',
    ip => '15.15.15.11',
    action=>'maintenance'});
print Dumper ($result);

#Show Service status and Real Server state

$result = $xmlrpc->call('service.show',
    {vip=>'192.168.132.214:21:TCP',
    port=> '21', ip=> '15.15.15.11',
    show=> $service_show});
print Dumper ($result);

#Delete the Real Server
$result = $xmlrpc->call('server.delete',
    {vip=>'192.168.132.214:21:TCP',
    ip => '15.15.15.11',
    port => '21'});
print Dumper ($result);

#Delete the Service
$result = $xmlrpc->call('service.delete',
    {vip=>'192.168.132.214',
    port=>'21',
    protocol=>'TCP'});
print Dumper ($result);

 

Related Articles