Loading ...
Sorry, an error occurred while loading the content.

5454Re: SOAP::Lite, WSDL and execution loops/delays

Expand Messages
  • Scott Francis
    Jun 23, 2006
    • 0 Attachment
      On 6/19/06, Scott Francis <darkuncle@...> wrote:
      > So I'm using SOAP::Lite to build a Perl interface to a NetScaler load
      > balancer (end goal is to have servers added and removed from a pool in
      > an automated fashion). The interface is via WSDL[0], and my code[1]
      > successfully connects (uses HTTP::Cookies for authentication),
      > executes a command and parses the response.

      Following up with code inline, in hopes of soliciting some comments:

      #!/usr/bin/perl -w

      # use Perl and NetScaler's SOAP API service - primarily useful
      # for scripted activity, since NS already has a java-based GUI and runs sshd

      use strict;
      use SOAP::Lite;
      use Data::Dumper;

      # uncomment the following to dump complete SOAP::Lite output
      # this is EXCEEDINGLY verbose - you have been warned!
      #SOAP::Lite->import(+trace => [ "all", "-objects" ]);

      # NetScaler SOAP API uses cookie-based authentication
      use HTTP::Cookies;

      # non-HTTP debugging - if enabled, debug("foo") prints "foo\n" to stderr
      # set to 1 to enable, 0 to disable
      use constant DEBUG => 1 ;
      sub debug { print STDERR "@_\n" if DEBUG; }

      # take CLI argument for operation, or default to getnsversion()
      my $operation = shift @ARGV || "getnsversion";
      my @arguments = @ARGV;

      debug("operation: $operation");
      debug("arguments: @arguments");

      # login credentials
      my $username = 'user';
      my $password = 'pass';

      debug("username: $username");
      debug("password: $password");

      # location of WSDL file and SOAP proxy
      my $ns_wsdl = 'file:./NSConfig.wsdl';
      my $ns_proxy = '';

      debug("ns_wsdl: $ns_wsdl");
      debug("ns_proxy: $ns_proxy");

      # instantiate SOAP object - this is where our 563K create/destroy loop begins
      my $soapobj = SOAP::Lite
      cookie_jar => HTTP::Cookies->new(ignore_discard => 1),
      timeout => 5)

      # print perl object we'll be sending to the proxy
      DEBUG && print "dumping request - \$soapobj perl object:\n", Dumper($soapobj);

      # login
      my $login = $soapobj->login("$username", "$password") or die "login
      failure: $@\n";

      # use SOAP object to create $soapres object that actually performs our
      my $soapres = $soapobj->$operation(@arguments) or die "$operation
      failure: $@\n";

      # Data::Dumper++ - we can see the output that's returned as Perl sees it!
      DEBUG && print "dumping response - \$soapres perl object:\n", Dumper($soapres);

      # the name and type of object returned varies with each $operation
      # our code is not yet smart enough to automagically PTRT (print the right thing)

      if ($operation eq "getnsversion") {
      # getnsversion()->version returns scalar
      print "version string: ", $soapres->{List}->[0]->{version}, "\n";
      } elsif ($operation eq "getlbvserver") {
      # getlbvserver()->serviceName returns array
      local $" = "\n ";
      print "getlbvserver list:\n @{$soapres->{List}->[0]->{serviceName}}\n";

      DEBUG && print "return code: ", $soapres->{rc}, "\n";
      DEBUG && print "message: ", $soapres->{message}, "\n";

      unless ($soapres->{rc} == 0) {
      print "an error occurred: ", $soapres->{message}, "\n";

      thanks for any comments, folks.
      darkuncle@{gmail.com,darkuncle.net} || 0x5537F527
      encrypted email to the latter address please
      http://darkuncle.net/pubkey.asc for public key
    • Show all 3 messages in this topic