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.
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);