THE GAME HAS CHANGED

Introducing Infoblox Universal DDI ManagementTM

Watch the launch to discover the new era of management for critical network services. Watch Now

API & Integration, DevOps,NetOps,SecOps

Reply

Add a new fixed address - WAPI API Python requests

New Member
Posts: 1
4120     0

Hello,

 

I am very new to infoblox and the WAPI API. I am trying to create a script that creates fixed addresses for a given network using Python, requests and the WAPI API. I have not been succesful at this and was wondering if anyone has done it or if I could get a clue on how to do it. Here's my code:

 

session = requests.Session()
session.auth = ('admin''password')
session.verify = False

 
r = session.get(url + 'network')

net = r.json()
test = str.split(net[0]['network'], '/')
print(test[0])

data = {    
    'mac':'macAddress',
    '_return_fields':'ipv4addr,mac'
}

response = session.post(f'https://link/wapi/v2.3/fixedaddress'data=data, verify=False)
print(response.status_code)
 
Thank you!

Re: Add a new fixed address - WAPI API Python requests

Moderator
Moderator
Posts: 321
4121     0

You don't need to get the network first, the fixed address will be created in the correct network for the IP address.

 

This will work, given the IP address and the MAC address.

 

 

import requests
import urllib3
import json urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) session = requests.Session() session.auth = ('admin', 'infoblox') session.verify = False url = 'https://link.com/wapi/v2.7.3/' headers = {'Content-type': 'application/json'} data = {
'ipv4addr' : '192.168.123.123',
'mac':'00:12:51:12:34:56',
} r = session.post(url + 'fixedaddress', json=data, headers=headers, verify=False) response = r.json() print(response)

 

 

If you're not particular about the IP address, and you just want to assign it to the next available address in a specific network, you can do this:

 

import requests
import urllib3
import json

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

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

url = 'https://link.com/wapi/v2.7.3/'
headers = {'Content-type': 'application/json'}

data = {
      "ipv4addr": {
        "_object_function": "next_available_ip",
        "_object": "network",
        "_object_parameters": {"network": "192.168.123.0/24"},
        "_result_field": "ips",
      },
    'mac':'00:12:52:12:34:56',
}

r = session.post(url + 'fixedaddress', json=data, headers=headers, verify=False)

response = r.json()

print(response)
Showing results for 
Search instead for 
Did you mean: 

Recommended for You