The following code uses Stingray's RESTful API to delete a pool. The code is written in PHP and uses STMRESTClient. This program deletes the "phptest" pool created by the addpool.php example. To delete a resource you do a HTTP DELETE on the URI for the resource. If the delete is successful a 204 HTTP status code will be returned.
deletepool.php
<?php # Delete a pool require_once 'stmrestclient.inc'; $poolName = 'phptest'; try { # Set up the connection $client = new STMRestClient(); /* Check to see if the pool exists. If it doesn't exist, then a * ResourceNotFoundException exception will be thrown. */ $response = $client->get("pools/$poolName"); $client->delete("pools/$poolName"); print("Pool $poolName deleted"); } catch (STMResourceNotFoundException $e) { # The pool doesn't exist print("Pool $poolName not found"); } catch (STMConnectException $e) { print ("Error connecting to the REST API: " . $e->getMessage()); } catch (STMAuthException $e) { print ("Error logging into the REST API: " . $e->getMessage()); } catch (Exception $e) { print ('Error: ' . $e->getMessage()); } print("</body></html>\n"); ?>
Running the example
This code was tested with PHP 5.3.3 and uses the STMRestClient class that can be found here: Tech Tip: A Stingray Traffic Manager REST Client for PHP
To run this program, Make it available via a web server and the output should be:
Pool phptest deleted
Read More