Reply

How to release a DHCP lease by IP address via WAPI (Python)

tubescreamer
Techie
Posts: 2
2283     0

Hi,

 

I'm looking for python code to release a DHCP lease by IP address.
The GUI allows me too be only per IP address, using the WAPI it's easier to release multiple leases.
I have search the documentation but I couldn't find a way to do so.
I'm not that familiar with python either so I could use some help here.

 

First I need to know the exact URL (WAPI call) for this action with of course the IP address as a variable so I can use it for multiple IP addresses.

Any help is appreciated.

Thanks in advance.

Re: How to release a DHCP lease by IP address via WAPI (Python)

Adviser
Posts: 70
2284     0

Hi,

 

I got this working with the below code. I am not very savvy with Python, I am sure this could be improved.

 

 

 

#!/usr/bin/python

import requests
from requests.auth import HTTPBasicAuth
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

ip = raw_input("enter IP address for the lease: ")
user = ('admin')
password = ('infoblox')
url = ('https://10.192.32.240/wapi/v2.5/')
obj= ('lease?address='+ip)
func=('&_return_fields=')
state = ('&_return_fields=binding_state')
getresponse = requests.get(url+obj+func,auth=HTTPBasicAuth(user,password), verify = False)
getstate = requests.get(url+obj+state,auth=HTTPBasicAuth(user,password), verify = False)
print getstate.text
ref = getresponse.text[25:-9]
requests.delete(url+ref,auth=HTTPBasicAuth(user,password), verify = False)
print "The lease has been removed"
getstate = requests.get(url+obj+state,auth=HTTPBasicAuth(user,password), verify = False)
print getstate.text

Showing results for 
Search instead for 
Do you mean 

Recommended for You