cancel
Showing results for 
Search instead for 
Did you mean: 

Tech Tip: Using the RESTful Control API with Python - deletepool

The following code uses Stingray's RESTful API to delete a pool.  The code is written in Python.  This program deletes the "pytest" pool created by the addpool.py 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.py

 

#! /usr/bin/env python
import requests
import sys

poolName = 'pytest'
url = 'https://stingray.example.com:9070/api/tm/1.0/config/active/pools/' + poolName

client = requests.Session()
client.auth = ('admin', 'admin')
client.verify = False

try:
    response = client.delete(url)
except requests.exceptions.ConnectionError:
    print "Error: Unable to connect to " + url
    sys.exit(1)

if response.status_code == 204:
    print 'Pool %s deleted' %(poolName)
else:
    if response.status_code == 404:
        print 'Pool %s not found' %(poolName)
    else:
        print 'Error: Status=%d URL=%s' %(response.status_code, url)

 

Running the example

 

This code was tested with Python 2.7.3 and version 1.1.0 of the requests library.

 

Run the Python script as follows:

 

$ delelepool.py

Pool pytest deleted

 

Read More

 

 

 

Version history
Revision #:
3 of 3
Last update:
‎01-06-2021 04:42:PM
Updated by:
 
Labels (1)
Contributors