Example #1
0
function control_pool_node($lb, $username, $password, $pool_name, $server_name, $server_port, $action, $force = 1)
{
    /* initialize client */
    $wsdl_poolmember = "https://{$lb}/iControl/iControlPortal.cgi?WSDL=LocalLB.PoolMember";
    $location = "https://{$lb}/iControl/iControlPortal.cgi?";
    $client = new SoapClient($wsdl_poolmember, array('location' => $location, 'login' => $username, 'password' => $password, "trace" => 0));
    /* -------------------------------------------------------------------------
       Per this thread
       http://devcentral.f5.com/Forums/tabid/1082223/asg/51/showtab/groupforums/aff/1/aft/84952/afv/topic/Default.aspx
       Enabled (All traffic allowed):
       set_monitor_state : STATE_ENABLED
       set_session_enabled_state : STATE_ENABLED
    
       Disabled (Only persistent or active connections allowed):
       set_monitor_state : STATE_ENABLED
       set_session_enabled_state : STATE_DISABLED
    
       Forced Offline (Only active connections allowed):
       set_monitor_state : STATE_DISABLED
       set_session_enabled_state : STATE_DISABLED
       ------------------------------------------------------------------------- */
    try {
        $pool_list = array($pool_name);
        print "LB: {$lb} Pool: {$pool_name} Action: {$action} Server: {$server_name} Port: {$server_port}\n";
        $request->member->address = $server_name;
        $request->member->port = $server_port;
        if ($action == "enable") {
            $request->session_state = "STATE_ENABLED";
            $request->monitor_state = "STATE_ENABLED";
        }
        if ($action == "disable") {
            $request->session_state = "STATE_DISABLED";
            if ($force == 1) {
                $request->monitor_state = "STATE_DISABLED";
            } else {
                $request->monitor_state = "STATE_ENABLED";
            }
        }
        /* Don't ask why we have to wrap it in two arrays but we do */
        $full_request = array(array($request));
        $result = $client->set_session_enabled_state($pool_list, $full_request);
        $result = $client->set_monitor_state($pool_list, $full_request);
        //     if ( $debug == 1 ) {
        //       print "<pre>\n";
        //       print "Request :\n".($client->__getLastRequest()) ."\n";
        //       print "Response:\n".($client->__getLastResponse())."\n";
        //       print "</pre>";
        //     }
    } catch (SoapFault $fault) {
        trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
    }
}