Forum Discussion

hassar10_35518's avatar
hassar10_35518
Icon for Nimbostratus rankNimbostratus
Feb 25, 2008

Node's availabilty

Hi all

 

I have 35 nodes in my F5. How do find if a Particular node is currently a member of a pool or Not

 

If it is already a meber of a pool, I would like to leave it alone and if it not a memeber, I would like to have option to add it to my available pools

 

 

is this do able

 

Thanks a lot

2 Replies

  • There's not a single method to call to determine whether a given node is a member of a pool. The most straightforward way is to call the Pool::get_membert() passing in the results from Pool::get_list(). This will return you a 2-d array containing pool members from all the input pools. Iterate through these arrays and if you don't find a match, it's not in there.

     

     

    Here's a perl sample that takes as input a node address and iterates through all the pool members of all pools and prints out matches. Hopefully it will give you something to get started with.

     

     

    !/usr/bin/perl
    ----------------------------------------------------------------------------
     The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
     Software Development Kit for iControl"; you may not use this file except in
     compliance with the License. The License is included in the iControl
     Software Development Kit.
     Software distributed under the License is distributed on an "AS IS"
     basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
     the License for the specific language governing rights and limitations
     under the License.
     The Original Code is iControl Code and related documentation
     distributed by F5.
     The Initial Developer of the Original Code is F5 Networks,
     Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks,
     Inc. All Rights Reserved.  iControl (TM) is a registered trademark of F5 Networks, Inc.
     Alternatively, the contents of this file may be used under the terms
     of the GNU General Public License (the "GPL"), in which case the
     provisions of GPL are applicable instead of those above.  If you wish
     to allow use of your version of this file only under the terms of the
     GPL and not to allow others to use your version of this file under the
     License, indicate your decision by deleting the provisions above and
     replace them with the notice and other provisions required by the GPL.
     If you do not delete the provisions above, a recipient may use your
     version of this file under either the License or the GPL.
    ----------------------------------------------------------------------------
    use SOAP::Lite + trace => qw(method debug);
    use SOAP::Lite;
    use MIME::Base64;
    BEGIN {push (@INC, "..");}
    use iControlTypeCast;
    ----------------------------------------------------------------------------
     Validate Arguments
    ----------------------------------------------------------------------------
    my $sHost = $ARGV[0];
    my $sPort = $ARGV[1];
    my $sUID = $ARGV[2];
    my $sPWD = $ARGV[3];
    my $sNode = $ARGV[4];
    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 "") )
    {
      die ("Usage: NodeInPools.pl host port uid pwd [node_addr]\n");
    }
    ----------------------------------------------------------------------------
     Transport Information
    ----------------------------------------------------------------------------
    sub SOAP::Transport::HTTP::Client::get_basic_credentials
    {
      return "$sUID" => "$sPWD";
    }
    $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", '')
    ); };
    &findNodeInPool($sNode);
    ----------------------------------------------------------------------------
     checkResponse
    ----------------------------------------------------------------------------
    sub checkResponse()
    {
      my ($soapResponse) = (@_);
      if ( $soapResponse->fault )
      {
        print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
        exit();
      }
    }
    ----------------------------------------------------------------------------
     findNodeInPool
    ----------------------------------------------------------------------------
    sub findNodeInPool()
    {
      my ($node_addr) = (@_);
       Get the list of pools
      $soapResponse = $Pool->get_list();
      &checkResponse($soapResponse);
      my @pool_list = @{$soapResponse->result};
       Get the list of pool members for all the pools
      $soapResponse = $Pool->get_member
      (
        SOAP::Data->name(pool_names => [@pool_list])
      );
      &checkResponse($soapResponse);
      @member_lists = @{$soapResponse->result};
       Loop over pools
      for $i (0 .. $pool_list)
      {
        $bFound = 0;
        $pool = @pool_list[$i];
        if ( "" == $node_addr )
        {
           if no node given, print out full list
          print "Pool $pool : ";
          foreach $member ($member_lists[$i][$j])
          {
            $addr = $member->{"address"};
            $port = $member->{"port"};
            
            print "$addr, ";
          }
          print "\n";
        }
        else
        {
           else, only print out where matches are found.
          foreach $member ($member_lists[$i][$j])
          {
            $addr = $member->{"address"};
            $port = $member->{"port"};
            if ( $node_addr eq $addr )
            {
              $bFound = 1;
            }
          }
          if ( $bFound )
          {
            print "Pool $pool : $node_addr\n";
          }
        }
      }
    }

     

     

    -Joe
  • Hi Joe,

     

     

    This only seems to work if the node is the first member of the pool.

     

     

    Is there are way to change it to look at all members in a pool?