Forum Discussion

Todd_Rosenberge's avatar
Todd_Rosenberge
Icon for Nimbostratus rankNimbostratus
Mar 05, 2014

Issue with Perl iControl script to get Enable State of GTM Virtual Server

I am trying use Perl with iControl to determin the Enable State of a Server/Virtual server (not pool members). The sample code below results in the error:

 

SOAP-ENV:Server Could not find element by name: virtual_servers

 

I am note very fluent in Perl, but this seems straight forward. I am obviously missing something. I hacked the code together based on success with a similar script for VirtualServer::get_list, which I was able to use to print a list of Virtual Server names, IP's and ports. The two appear to use the same VirtualServerDefinition type.

 

The GTM is version 10.x so I am using the VirtualServer::get_enabled_state (Not VirtualServerV2::get_enabled_state)

 

=== Current "Bad" script to get Enable State === !/usr/local/bin/perl

 

$ENV{PERL_LWPSSL_VERIFY_HOSTNAME}=0;

use SOAP::Lite;
use MIME::Base64;

my $BIGIP = 'gtmname';  
my $User = 'admin';  
my $Pass = 'admin';
my %VServers = ( 
    name => "VS_Name_in_GTM",
    address => "VS_IP_in_GTM",
    port => "443"
    );

sub SOAP::Transport::HTTP::Client::get_basic_credentials  {  
    return "$User" => "$Pass"; 
}

&getVsState();

sub GetInterface()  {  
        print "In GetInterface with BigIP $BIGIP \n";
    my ($module, $name) = @_;  

    $interface = SOAP::Lite  
        -> uri("urn:iControl:$module/$name")  
        -> readable(1)  
        -> proxy("https://$BIGIP/iControl/iControlPortal.cgi");  
    eval { $interface->transport->http_request->header  
    ( 'Authorization' => 'Basic ' . MIME::Base64::encode("$User:$Pass", '') ); };

    return $interface;  
}

sub getVsState () {
    print "In VsState\n";

    $VSSTATE = &GetInterface("GlobalLB", "VirtualServer");
    $soapResponse = $VSSTATE->get_enabled_state(%VServers
       SOAP::Data->name (virtual_server => %VServers)
        );
    &checkResponse($soapResponse);
    @vsstate = @{$soapResponse->result};
    print "\n\n\nVS State = $vsstate";
    print "End VsState";
}

sub checkResponse()  {  
    print "in checkResponse\n";
    my ($soapResponse) = (@_);  
    if ( $soapResponse->fault )  {  
        die $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";  
    }  
} 

2 Replies

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    First thought, is that it's complaining because you're not passing the list of virtual servers (Using the virtual_servers parameter to the get_enabled_state() call) that you want to get...

     

    In the script, you've commented out why LOOKS like a parameter for it, except the parameter is MISSING the 's' off the end of virtual_server....

     

    H

     

  • With SOAP::Lite, you need to pass your parameters in using the SOAP::Data with the parameter name and value as you have commented out. Under the seams, the code gets converted to SOAP/XML across the wire and the server needs to determine elements by name for the case when methods take multiple parameters. You've omitted the "virtual_servers" so the server doesn't know how to extract that parameters content. Thus the "could not find element by name" error.

     

    For an example, you can see the Perl Virtual Show example in the CodeShare at https://devcentral.f5.com/wiki/iControl.PerlVirtualShow.ashx. It uses the LocalLB.VirtualServer.get_enabled_state() method, but the parameter names are the same.

     

    The definition for that method is:

     

    EnabledState [] GlobalLB.VirtualServer.get_enabled_state(
        in GlobalLB.VirtualServerDefinition [] virtual_servers
    );

    Something like this should work for you...

     

    $VirtualServerDefinition = {
        name => "VS_Name_in_GTM",
        address => "VS_IP_in_GTM",
        port => "443"
    };
    
    $soapResponse = $VSSTATE->get_enabled_state(
      SOAP::Data->name(virtual_servers => [$VirtualServerDefinition])
    );
    
    parse response here

    Hope this helped...

     

    -Joe