Forum Discussion

GavinW_29074's avatar
GavinW_29074
Icon for Nimbostratus rankNimbostratus
Feb 15, 2012

iApp management using iControl and Perl...

Hi there,

 

 

I'm trying to write a Perl iControl client to manage the creation/amendment of iApp application services on our v11 F5's...

 

 

Currently, I've got the following script:

 

!/usr/bin/perl
use Getopt::Long;
use Switch;
use SOAP::Lite;
use MIME::Base64;
use Math::BigInt;
use Data::Dumper;
use FindBin;
use lib "$FindBin::Bin/../lib";
use iControlTypeCast;
 Disable SSL Certificate Verification
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
----------------------------------------------------------------------------
 Validate Arguments
----------------------------------------------------------------------------
 Define varaibles
my ($sHost, $sPort, $sUID, $sPWD, $sMode, $action, $filename );
 Pickup Run-Time Options
GetOptions (
    "sHost=s" => \$sHost,
    "sPort:i" => \$sPort,
    "sUID=s" => \$sUID,
    "sPWD=s" => \$sPWD,
    "$sMode:s" => \$sMode,
    "action:s" => \$action,
    "filename:s" => \$filename
    );
 Assume always HTTPS
my $sProtocol = "https";
if ( ("80" eq $sPort) or ("8080" eq $sPort) )
{
  $sProtocol = "http";
}
if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq "") )
{
  &usage();
}
sub usage()
{
  my ($sCmd) = @_;
  print "Usage: CertInfo.pl --sHost host --sPort port --sUID username --sPWD password --action [script action] \n";
  exit();
}
----------------------------------------------------------------------------
 Transport Information
----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
  return "$sUID" => "$sPWD";
}
$AppServiceHandler = SOAP::Lite
  -> uri('urn:iControl:Management/ApplicationService')
  -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
eval { $Pool->transport->http_request->header
(
  'Authorization' => 
    'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
 Action Code
switch ($action) {
    case 'ci' { &GetCertInfo($sMode) }
    case 'im' { &ImportCert($mode, $filename) }
    case 'ial' { &GetiAppList }
    else { print "Specified check not found ($action) \n" }
}
;
sub GetiAppList()
{
    
    
    $soapResponse = $AppServiceHandler->get_list ();
    
    &checkResponse($soapResponse);
    
    @AppListA = @{$soapResponse->result};
  
    print "Received Application Services list";
    print Dumper(@AppListA);
  
    foreach $AppList (@AppListA)
      {
          print "Application Service...";
      }
    
}
----------------------------------------------------------------------------
 checkResponse
----------------------------------------------------------------------------
sub checkResponse()
{
  my ($soapResponse) = (@_);
  if ( $soapResponse->fault )
  {
    print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
    exit();
  }
}

 

 

However all i'm getting printed out is:

 

D:\Workspace\F5_iControl>perl bin/f5_icontrol.pl --sHost f501 --sPort 443 --sUID xxx --sPWD xxx --a

 

ction ial

 

Received Application Services list

 

 

Any ideas where I'm going wrong?

 

 

Cheers

 

Gavin

 

1 Reply

  • Is your question why you aren't seeing any iApp Services returned from the get_list() method? If so, it could be for a couple of reasons.

     

     

    1. Are you in the correct partition? If the iApp was created in a different partition than "/Common" then you will have to make a call to change your context.

     

     

    2. Are you in the correct folder? By default, queries will be returned based on the current folder. /Common is both a partition (from previous versions) and a folder (from v11 on). iApp Services are created in subfolders in the form of servicename.app. The easiest way to find everything is to set the recursive query flag to true to return all objects in or below the current folder. This is done with the System.Session.set_recursive_query_state method. I discuss the ins and outs of folders in this article:

     

     

    https://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1086495/iControl-101-24--Folders.aspx

     

     

    Hope this helps...

     

     

    -Joe