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

Using Python to get next available network

New Member
Posts: 2
3407     0

I have a container, 10.132.0.0/16, with 2 subnets (10.132.0.0/24 and 10.132.1.0/24).
I want to get the next available subnet (10.132.2.0/24).  I have this python-kode:

import requests
import json
import urllib3
import secrets

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

IB_IP = "my.infoblox"

def next_available_network():
url = f'https://{IB_IP}/wapi/v2.12/network'
headers = {'Content-Type': 'application/json'}
data = {
"network": {
"_object_function": "next_available_network",
"_result_field": "networks",
"_object": "networkcontainer",
"_object_parameters": {
"network": "10.132.0.0/16",
"network_view": "PROD"
},
"_parameters": {
"exclude": ["10.128.0.0/14", "10.140.0.0/14"],
"cidr": 24
},
}
}

response = requests.post(url, auth=(secrets.username, secrets.password), headers=headers, data=json.dumps(data), verify=False)
print(response.text)

next_available_network()

This works getting the next available network (10.132.2.0/24), but it is not put under the 10.132.0.0/16 container and the network_view PROD.  Instead, it is created under default.

Re: Using Python to get next available network

[ Edited ]
New Member
Posts: 1
3408     0

To get this work, you should define network_view outside of the "next_avaiable_network" function call as well. Based on your code, you should add as following:
---
"cidr": 24
}
},

"network_view": "PROD"
}

 

response = 
----

As from the WAPI document (https://<gm>/wapidoc), the default value for network_view is the "default" network view. Hence, if this is not being defined, then it will use the default network view instead. 

Re: Using Python to get next available network

New Member
Posts: 2
3408     0

Thanks, that worked!
I have another question about making the first 5 ip addresses marked as used/reserved.
How can I do that?  I have googled and read to find the solution, but I don't get it to work.
I tried this:
def mark_ip_used():
url = f'https://{IB_IP}/wapi/v2.12/fixedaddress'
headers = {'Content-Type': 'application/json'}
data = {
"name": "Reserved_name",
"comment": "Reserved_comment",
"mac": "00:00:00:00:00:00",
"ipv4addr": {
"_object_function": "next_available_ip",
"_object": "network",
"_object_parameters": {
"network": "10.132.2.0/24"},
"_result_field": "ips"
}
}

But that gives me an error:
{ "Error": "AdmConDataError: None (IBDataConflictError: IB.Data.Conflict:Cannot find the parent network for the fixed address 10.132.2.1.)",
"code": "Client.Ibap.Data.Conflict",
"text": "Cannot find the parent network for the fixed address 10.132.2.1."
}

What I want is when a subnet is created, I want to make the first 5 ip addresse as used/reserved.  If I have the input to make 1, I can change the code to make the first 5 to marked as used/reserved.

Re: Using Python to get next available network

New Member
Posts: 3
3408     0

You must first read what the _ref number is for the network where you want to find the first five IP addresses.
Then use the query by modifying the query address to https://baseulr/_ref

Do not use
https://baseurl/fixedaddress
Greetings
Roman

Showing results for 
Search instead for 
Did you mean: 

Recommended for You