Forum Discussion

Brian_Moore_603's avatar
Brian_Moore_603
Icon for Nimbostratus rankNimbostratus
Aug 29, 2007

bringing multiple sites in and out of service

I need a way for a group of users in my network to force a group of servers offline in the F5 with a script? I am needing this so that we can roll out code changes to those servers and then put them back into production we may have 25 servers to this to and therefore clicking in the gui doesn't seem to be good plan?

 

 

 

Thanks

6 Replies

  • A quick and dirty solution would be to use bigpipe commands via the command line to disable the nodes. You can check the 'b pool help' or 'b node help' pages for details.

     

     

    The syntax to disable a single pool member is:

     

     

    b pool my_http_pool member 1.2.3.4:80 session disable

     

     

    You could use a shell script to read in a list of nodes and run the command for them.

     

     

    To disable nodes, you can use a list:

     

     

    b node 1.2.3.4 1.2.3.5 session disable

     

     

    To save the changes from memory to file, run 'b save'.

     

     

     

    An elegant solution would be to use iControl to programmatically disable the nodes. You can check the iControl page for more info:

     

     

    http://devcentral.f5.com/wiki/Default.aspx/iControl.HomePage

     

    Click here

     

     

    Aaron
  • Here's a script Joe helped me with many moons ago to disable/enable pool members:

    
    use SOAP::Lite;
    ------------------------------------------------------------------------
     Validate Arguments
    ------------------------------------------------------------------------
    my $sHost = $ARGV[0];
    my $sPort = $ARGV[1];
    my $sUID = $ARGV[2];
    my $sPWD = $ARGV[3];
    my $sPool = $ARGV[4];
    my $desired_pool_state = $ARGV[5];
    my $sProtocol = "https";
    sub usage()
    {
       die ("Usage: PoolMember.pl host port uid pwd ([pool] AND [enable|disable])\n");
    }
    if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq "") or (($sPool ne "") and ($desired_pool_state eq "")) )
    {
       usage();
    }
    ------------------------------------------------------------------------
     Transport Information
    ------------------------------------------------------------------------
    sub SOAP::Transport::HTTP::Client::get_basic_credentials
    {
       return "$sUID" => "$sPWD";
    }
    $Pool = SOAP::Lite
       -> uri('urn:iControl:LocalLB/Pool')
       -> readable(1)
       -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
    $PoolMember = SOAP::Lite
       -> uri('urn:iControl:LocalLB/PoolMember')
       -> readable(1)
       -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
    ------------------------------------------------------------------------
     Attempt to add auth headers to avoid dual-round trip
    ------------------------------------------------------------------------
    eval { $Pool->transport->http_request->header
    (
       'Authorization' =>
       'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
    ); };
    eval { $Pool->transport->http_request->header
    (
       'Authorization' =>
       'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
    ); };
    ------------------------------------------------------------------------
     support for custom enum types
    ------------------------------------------------------------------------
    sub SOAP::Deserializer::typecast
    {
       my ($self, $value, $name, $attrs, $children, $type) = @_;
       my $retval = undef;
       if ( "{urn:iControl}Common.EnabledState" == $type )
    {
           $retval = $value;
    }
       return $retval;
    }
    ------------------------------------------------------------------------
     Main logic
    ------------------------------------------------------------------------
    if ( "" eq $sPool )
    {
       ------------------------------------------------------------------
        No pool supplied.  Query pool list and display members for given pool
       ------------------------------------------------------------------
       $soapResponse = $Pool->get_list();
       &checkResponse($soapResponse);
       @pool_list = @{$soapResponse->result};
       &showPoolMembers(@pool_list);
    }
    elsif ( "" ne $sPool )
    {
       ------------------------------------------------------------------
        Pool supplied, but no member so disable all pools members
       ------------------------------------------------------------------
       if ( $desired_pool_state eq "enable" )
       {
    &enablePoolMembers($sPool);
       }
       elsif ( $desired_pool_state eq "disable" )
       {
    &disablePoolMembers($sPool);
       }
       else 
       {
    die ("If pool supplied, you must state enable or disable\n");
       }
    }
    else
    {
       print "No conditions defined yet\n";
    }
    ------------------------------------------------------------------------
     Show list of pools and members
    ------------------------------------------------------------------------
    sub showPoolMembers()
    {
       my (@pool_list) = @_;
       my @member_state_lists = &getPoolMemberStates(@pool_list);
       print "Pool Members Enabled State\n";
       print "==========================\n";
       $i = 0;
       foreach $pool (@pool_list)
       {
    print "pool $pool\n{\n";
    @member_state_list = @{@member_state_lists[$i]};
    foreach $member_state (@member_state_list)
    {
       $member = $member_state->{"member"};
       $addr = $member->{"address"};
       $port = $member->{"port"};
       $session_state = $member_state->{"session_state"};
          print "    $addr:$port ($session_state)\n";
    }
    print "}\n";
    $i++;
       }
    }
    ------------------------------------------------------------------------
     returns the status structures for the members of the specified pools
    ------------------------------------------------------------------------
    sub getPoolMemberStates()
    {
       my (@pool_list) = @_;
       $soapResponse = $PoolMember->get_session_enabled_state
       (
    SOAP::Data->name(pool_names => [@pool_list])
       );
       &checkResponse($soapResponse);
       @member_state_lists = @{$soapResponse->result};
       return @member_state_lists;
    }
    ------------------------------------------------------------------------
     Sets state to Enabled
    ------------------------------------------------------------------------
    sub enablePoolMembers()
    {
      my ($pool) = (@_);
      &setPoolMemberStates($pool, "STATE_ENABLED");
    }
    ------------------------------------------------------------------------
     Sets state to Disabled
    ------------------------------------------------------------------------
    sub disablePoolMembers()
    {
      my ($pool) = (@_);
      &setPoolMemberStates($pool, "STATE_DISABLED");
    }
    ------------------------------------------------------------------------
     Takes state information and applies to pool member session and monitor
    ------------------------------------------------------------------------
    sub setPoolMemberStates()
    {
      my ($pool, $state) = (@_);
       Get a list of pool members
      $soapResponse = $Pool->get_member
      (
        SOAP::Data->name(pool_names => [$pool])
      );
      &checkResponse($soapResponse);
      @member_lists = @{$soapResponse->result};
       Extract the 1st list for the single pool passed in.
      @member_list = @{@member_lists[0]};
       build parameters for set_session_enabled_state();
      foreach $member_def (@member_list)
      {
        $address = $member_def->{"address"};
        $port = $member_def->{"port"};
        $member = { address => $address, port => $port };
        $MemberSessionState =
        {
          member => $member,
          session_state => $state
        };
        push @MemberSessionStateList, $MemberSessionState;
      }
      push @MemberSessionStateLists, [@MemberSessionStateList];
       Set the session enabled state
      $soapResponse = $PoolMember->set_session_enabled_state
      (
        SOAP::Data->name(pool_names => [$pool]),
        SOAP::Data->name(session_states => [@MemberSessionStateLists])
      );
      &checkResponse($soapResponse);
       build parameters for set_monitor_state();
      foreach $member (@member_list)
      {
        $MemberMonitorState =
        {
          member => $member,
          monitor_state => $state
        };
        push @MemberMonitorStateList, $MemberMonitorState;
      }
      push @MemberMonitorStateLists, [@MemberMonitorStateList];
       set the monitor state
      $soapResponse = $PoolMember->set_monitor_state
      (
        SOAP::Data->name(pool_names => [$pool]),
        SOAP::Data->name(monitor_states => [@MemberMonitorStateLists])
      );
      &checkResponse($soapResponse);
    }
    ------------------------------------------------------------------------
     checkResponse makes sure the error isn't a SOAP error
    ------------------------------------------------------------------------
    sub checkResponse()
    {
       my ($soapResponse) = (@_);
       if ( $soapResponse->fault )
       {
          print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
          exit();
       }
    }
  • Darned brackets!!! I attached the script to the previous post...
  • Whew... that script is a dozey, how do you make sense of all that... keep in mind that I am just a network nerd no script or coding required?

     

     

    Oh, btw thanks very much for the quick reply, this helps a ton.

     

     

     

  • The BigIP becomes a very powerful piece of the architecture if you invest the time to understand how to make iRules and iControl work for you. I am not a coder either, but thankfully this site is loaded with gifted individuals that have been very patient and encouraging as I've begun to unwrap the layers of complexity...

     

     

    I would encourage you to experiment with the iControl and iRules examples in codeshare. They have been key in furthering my understanding of the many ways you can manipulate your bigIP.
  • Great info, Citizen. I think melloyellowmoore might also be looking for basic info on how to use the script...

     

     

    It's Perl-based, so you can run it on any host with Perl installed (including a BIG-IP). You need the SOAP::Lite package installed.

     

     

    Save the text to a file. Make the file executable. Then run it with no options to get the usage printed out: ./script_name.pl

     

     

    Usage: PoolMember.pl host port uid pwd ([pool] AND [enable|disable])

     

     

    host is the IP or hostname of the BIG-IP. Port should be 443. The uid/pwd are the BIG-IP username and password.

     

     

    The script is clearly commented, so you can see what it's doing by checking the Main subroutine ( Main logic).

     

     

    Aaron