vADC Docs

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

by ricknelson on ‎02-27-2013 11:01 AM (934 Views)

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