Forum Discussion
GavinW_29074
Nimbostratus
Apr 26, 2012Struggling with Perl and iControl?!
Hi there,
I'm trying to set-up a perl client for iControl to stream-line some of our processes.
I've got a very simply script which is based on one of the examples already provided. However I'm having issues with the following error:
Can't call method "fault" on an undefined value at f5_icontrol.pl.
Code looks like this. I've snipped some bits out that aren't relevant:
!/usr/bin/perl
use Getopt::Long;
use Switch;
use SOAP::Lite + trace => qw(debug);
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] --filename [filename] \n";
exit();
}
----------------------------------------------------------------------------
Transport Information
----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$sUID" => "$sPWD";
}
Action Code
switch ($action) {
case 'ci' { &GetCertInfo($sMode) }
case 'im' { &ImportCert($sMode, $filename) }
case 'ial' { &GetiAppList }
case 'cf' { &GetCurrentFolder }
else { print "Specified check not found ($action) \n" }
}
;
sub createHandler ($)
{
my ($uri) = shift;
my ($handler) = SOAP::Lite
-> uri($uri)
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
eval { $KeyCertificateHandler->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
return $handler;
}
sub GetCurrentFolder()
{
my ($ws_uri) = 'urn:iControl:System/Session';
my ($ws_handler) = createHandler($ws_uri);
my ($soapResonse) = $ws_handler->get_active_folder();
&checkResponse($soapResponse);
my $folder = $soapResponse->result();
print "Current Folder = $folder \n";
}
With SOAP::Lite debug on, I can see the following output when running the script:
D:\Workspace\F5_iControl\bin>perl f5_icontrol.pl --sHost xxx --sPort 443 --sUID gavinw --sPWD xxx --a
ction cf
SOAP::Transport::HTTP::Client::send_receive: POST https://xxx:443/iControl/iControlPortal.cgi HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 439
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:iControl:System/Sessionget_active_folder"
="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://sch
emas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">lns="urn:iControl:System/Session" xsi:nil="true" />
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
Connection: close
Date: Thu, 26 Apr 2012 09:36:04 GMT
Server: Apache
...
xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:A="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s="http://www.w3.org/2001/XMLSchema-instance"
xmlns:y="http://www.w3.org/2001/XMLSchema"
xmlns:iControl="urn:iControl"
E:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
xmlns:m="urn:iControl:System/Session">
s:type="y:string">/Common
Can't call method "fault" on an undefined value at f5_icontrol.pl line .
That quite clearly shows a valid response being returned...
So where am I going wrong???
Cheers
Gavin
- Ross_79170
Nimbostratus
Your response is fine, but you seem to have a typo? - GavinW_29074
Nimbostratus
Posted By Ross on 04/26/2012 02:57 AM - GavinW_29074
Nimbostratus
Another quick one from me then - Is it necessary/beneficial to close iControl sessions once finished with them? - Ross_79170
Nimbostratus
Hehe, I know what you mean, I've done the same several times. - GavinW_29074
Nimbostratus
Posted By Ross on 04/26/2012 05:34 AMsub createHandler ($$) { my ($urn,$recursive) = (@_); Set-up variable my ($handler); if ($recursive) { $handler = SOAP::Lite -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi"); eval { $handler->transport->http_request->header ( 'Authorization' => 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '') ); }; Set recursive &setRecursive($handler); Correct Handler URI path. $handler->uri($urn); } else { $handler = SOAP::Lite -> uri($urn) -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi"); eval { $handler->transport->http_request->header ( 'Authorization' => 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '') ); }; } return $handler; } ---------------------------------------------------------------------------- setRecursive - Set the Recursive Query State. ---------------------------------------------------------------------------- sub setRecursive ($$) { my ($handler) = (@_); Switch to System/Session and Set recursive $handler->uri('urn:iControl:System/Session') ->set_recursive_query_state( SOAP::Data->name(state => "STATE_ENABLED") ); return $handler; }
- Hi all, there were a couple of questions there so I'll try to hit them all.
- Ross_79170
Nimbostratus
Thanks Joe - Thats really helpful! - GavinW_29074
Nimbostratus
Joe/Ross
Recent Discussions
Related Content
Â
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects