Sample Program - Multiple Functions

Sample Program - Multiple Functions

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

We value your feedback.
If you have questions, suggestions, or feedback on our documentation, contact the Campus Product Documentation team.
For general product inquiries or technical support, please contact the global Barracuda Support team.