Reply
Highlighted
Accepted Solution

Delete subnet with wAPI python and JSON

[ Edited ]
Anonymous
Not applicable
Posts: 9
2995     0

Hello,

 

I'm trying to schedule a subnet for deletion for the next day using JSON encoding but I'm not even able to delete the subnet using DELET the JSON:

https://ip.ip.ip.ip/wapi/v1.4.1/network

Body:

{

    "_ref": "network/ZG5zLm5ldHdvcmskMTAuMTQyLjIwMy4xOTIvMjYvMA:10.142.203.192/26/default"

}

 

The response I get is:

{
"Error": "AdmConProtoError: Object ref must be given for DELETE: network"
"code": "Client.Ibap.Proto"
"text": "Object ref must be given for DELETE: network"
}
 
Is there any tutorial in how to use the documentation ? I'm a beginner and I'm finding it difficult to follow or understand. It would be nice to know what's required when bulding the json body.

I'm using requests module for wapi cals.

Re: Delete subnet with wAPI python and JSON

Adviser
Posts: 353
2996     0
You may want to check out https://pypi.python.org/pypi/infoblox-client rather than using requests directly. John

Re: Delete subnet with wAPI python and JSON

[ Edited ]
Anonymous
Not applicable
Posts: 9
2996     0
import datetime
import time
import requests
import json

# Infoblox Credentials
ip = "https://ip.ip.ip.ip"
user = 'admin'
passwd = 'infoblox'

validCert = False  # True, if a signed cert used.
url = ip + "/wapi/v1.4.1/"

def del_subnet(ib_list): del_date = datetime.datetime.now() + datetime.timedelta(days=1) unix_time = time.mktime(del_date.timetuple()) d = "" try: with requests.Session() as s: for ib_net in ib_list: # full_url = url + ib_net['_ref'] + "?_schedinfo.scheduled_time=%s" % int(unix_time) # print("DEBUG: URL -->", full_url) d = s.delete(url + ib_net["_ref"], params={"_schedinfo.scheduled_time": str(int(unix_time))}, auth=(user, passwd), verify=validCert) if d.status_code == requests.codes.ok: print("INFO: ", json.loads(d.content)) # print("DEBUG: ", d.content) else: print("ERROR: ", json.loads(d.content)['text']) print("DEBUG: ", d.content)

That's how I got it working.

Showing results for 
Search instead for 
Do you mean 

Recommended for You