Forum Discussion

Paul_Lavoie_724's avatar
Paul_Lavoie_724
Icon for Nimbostratus rankNimbostratus
Dec 27, 2006

Trouble with PoolMember->get_session_enabled_state in perl

Hi!

 

 

I'm starting to write perl scripts using the iControl API to replace some bigpipe shell scripts, and seem to have run into a problem.

 

 

The following application:

 

 

!/usr/bin/perl -w

 

 

use SOAP::Lite;

 

use MIME::Base64;

 

 

Variables for

 

our $sUID = 'user';

 

our $sPWD = 'password';

 

our $sProtocol = 'https';

 

our $sPort = 443;

 

 

initSOAPtoLB('devbigip1');

 

 

sub initSOAPtoLB ($) {

 

 

my ($sHost) = shift; Name of load balancer...

 

 

my $Pool = SOAP::Lite->uri('urn:iControl:LocalLB/Pool')

 

->proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");

 

eval { $Pool->transport->http_request->header(

 

'Authorization' => 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')

 

); };

 

 

my $PoolMember = SOAP::Lite->uri('urn:iControl:LocalLB/PoolMember')

 

->proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");

 

eval { $PoolMember->transport->http_request->header(

 

'Authorization' => 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')

 

); };

 

 

my $resp = $Pool->get_list;

 

checkResponse($resp);

 

my @poolList = @{$resp->result};

 

 

 

my @sess = undef;

 

foreach my $p (@poolList) {

 

print "$p\n";

 

my $resp2 = $PoolMember->get_session_enabled_state

 

(

 

SOAP::Data->name(pool_names => [$p])

 

);

 

eval {

 

checkResponse($resp2);

 

push(@sess, @{$resp2->result});

 

};

 

}

 

foreach my $s (@sess) {

 

print "$s\n";

 

}

 

 

return ($Pool, $PoolMember, \@poolList);

 

 

}

 

 

does not seem to handle the get_session_enabled_state method properly. The error output from the script is:

 

 

news_thin

 

Unrecognized type '{urn:iControl}Common.EnabledState'

 

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:LocalLB/PoolMember">

 

s:type="A:Array"

 

A:arrayType="iControl:LocalLB.PoolMember.MemberSessionState[][1]">

 

A:arrayType="iControl:LocalLB.PoolMember.MemberSessionState[1]">

 

s:type="iControl:LocalLB.PoolMember.MemberSessionState">

 

s:type="iControl:Common.IPPortDefinition">

 

s:type="y:string">10.72.170.75

 

s:type="y:long">10428

 

 

s:type="iControl:Common.EnabledState">STATE_ENABLED

 

 

 

 

 

 

 

at ./testiCtrl.pl line 136

 

 

which to me looks like a definition error within iControl. Any suggestions?

3 Replies

  • The Common.EnabledState type is one of our enum values. You'll need to include the iControlTypeCast.pm file located in the sdkroot\sdk\samples\soap\perl\soaplite directory. The file contains all of our custom types with the mapping logic. Take a look at the SDK samples for info on how to include it.

     

     

    If you don't want the baggage of this extra file with your scripts, you can cut+paste the sections you need (or the entire thing) into your script.

     

     

    Good luck and let us know if you get stuck on anything else!

     

     

    -Joe
  • The only thing I can think of is that you put some print statements in the iControlTypeCast.pm file in the subroutine to find out the type that is passed in and whether it's getting pulled from the hash correctly. Could be that the deserialize subroutine isn't getting called.

     

     

    If you see no print output then I would next try to embed the code directly into your script and then see if the subroutine is then getting called.

     

     

    I do know that this is the way to include your own custom types. Have you tried any of the SDK examples in the LocalLB Pool directory? Are they having the same issues?

     

     

    -Joe
  • Well, your suggestion got me to a point that I got it to work. The redefinition of the serialize command which was plucked from one of the sample scripts was to blame. The version in the header file does need some cleanup in order to work with the perl '-w' flag, however. I suggest:

     

     

    Implement Typecast for iControl enumeration Elements

     

    no warnings qw(redefine);

     

    sub SOAP::Deserializer::typecast

     

    {

     

    my ($self, $value, $name, $attrs, $children, $type) = @_;

     

    my $retval = undef;

     

    if (defined($type) && exists($urnMap->{$type}) && $urnMap->{$type} == 1)

     

    {

     

    $retval = $value;

     

    }

     

    return $retval;

     

    }

     

    use warnings qw(redefine);

     

     

    Thanks for the help...