Reply

High-Level Infoblox API for getting NextAvalialbleNetwork

New Member
Posts: 3
7619     1

We are trying to use high-level Infoblox API ( https://github.com/infobloxopen/infoblox-client ) for API calls to Infoblox. 

Would you help me figure out how to use "next available network" with high-level API ?

For example, I've got desired container based on ea attributes

>>> res=objects.NetworkContainerV4.search(conn,search_extattrs=nc)
>>> nc                                                 
EAs:DC=DC1,POD=4
>>> res  
NetworkContainerV4: extattrs="EAs:DC=DC1,POD=4", network="10.200.0.0/16", network_view="default", _ref="networkcontainer/ZG5zLm5ldHdvcmtfY29udGFpbmVyJDEwLjIwMC4wLjAvMTYvMA:10.200.0.0/16/default"

but how to get ( and reserve ) next_available_network from it ?

 

Thank you !

Re: High-Level Infoblox API for getting NextAvalialbleNetwork

[ Edited ]
Superuser
Posts: 115
7619     1

That function is not in the infoblox-client.

Also, check out https://sifbaksh.com

I've told my customers to use the following: /request

 

https://gm/wapi/v2.11.1/request

Body

[
    {
        "method": "GET",
        "object": "networkcontainer",
        "data": {
            "*SifLoc:": "Texas",
            "network_view": "default"
        },
        "assign_state": {
            "netw_ref": "_ref"
        },
        "discard": true
    },
    {
        "method": "POST",
        "object": "network",
        "data": {
            "network": {
                "_object_function": "next_available_network",
                "_result_field": "networks",
                "_parameters": {
                    "cidr": 20
                },
                "_object_ref": "##STATE:netw_ref:##"
            },
            "network_view": "default",
            "extattrs": {
                "Test1": {
                    "value": "dg11"
                },
                "Test2": {
                    "value": "vince"
                }
            }
        },
        "enable_substitution": true
    }
]

 

Python Code:

import requests

url = "https://gm/wapi/v2.11.1/request"

payload = "[\n    {\n        \"method\": \"GET\",\n        \"object\": \"networkcontainer\",\n        \"data\": {\n            \"*SifLoc:\": \"Texas\",\n            \"network_view\": \"default\"\n        },\n        \"assign_state\": {\n            \"netw_ref\": \"_ref\"\n        },\n        \"discard\": true\n    },\n    {\n        \"method\": \"POST\",\n        \"object\": \"network\",\n        \"data\": {\n            \"network\": {\n                \"_object_function\": \"next_available_network\",\n                \"_result_field\": \"networks\",\n                \"_parameters\": {\n                    \"cidr\": 20\n                },\n                \"_object_ref\": \"##STATE:netw_ref:##\"\n            },\n            \"network_view\": \"default\",\n            \"extattrs\": {\n                \"Test1\": {\n                    \"value\": \"dg11\"\n                },\n                \"Test2\": {\n                    \"value\": \"vince\"\n                }\n            }\n        },\n        \"enable_substitution\": true\n    }\n]"
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload, verify=False, auth=("admin", "infoblox"))

print(response.text.encode('utf8'))

 

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: High-Level Infoblox API for getting NextAvalialbleNetwork

New Member
Posts: 3
7619     1

Thank you for replying ! Indeed, the WAPI call with python requests works as charm. However I have a trouble understanding how to implement it with high/low level API calls.

 

As per our SE , the functionality is implemented , but I cant find any meaningful configuration examples. 

Re: High-Level Infoblox API for getting NextAvalialbleNetwork

New Member
Posts: 1
7619     1

Hi Gents! I was able to get this to work using the following:

 

    ea = objects.EA({'Region': 'EMEA'})
    res = objects.Network.search(conn, search_extattrs=ea)
    print(res)
    res = res.next_available_network(dict(cidr=27, num=4))
    print(res)

The first part queries the Network object by EA, then gets a ref to the object b/c only one (1) was returned. Then use the ref to call the function w/ it's args... 

NOTE: make sure you have code to handle more than one (1) Network object returned by the first call. 

Happy Hunting!

Re: High-Level Infoblox API for getting NextAvalialbleNetwork

Superuser
Posts: 115
7620     1

Thanks ddiguru, I did miss that in the docs Smiley Happy

 

Here is an example

ea = objects.EA({'SifLoc': 'NY'}) 
res = objects.NetworkContainerV4.search(conn, search_extattrs=ea)
print(res) 
res = res.next_available_network(dict(cidr=27, num=4)) 
print(res)

for x in res['networks']:
    print(x)
    network = objects.Network.create(conn, cidr=x)
    print(network)

Results:

NetworkContainerV4: extattrs="EAs:SifLoc=NY", network="10.20.0.0/20", network_view="default", _ref="networkcontainer/ZG5zLm5ldHdvcmtfY29udGFpbmVyJDEwLjIwLjAuMC8yMC8w:10.20.0.0/20/default"
{'networks': ['10.20.1.0/27', '10.20.1.32/27', '10.20.1.64/27', '10.20.1.96/27']}
10.20.1.0/27
NetworkV4: network="10.20.1.0/27", network_view="default", _ref="network/ZG5zLm5ldHdvcmskMTAuMjAuMS4wLzI3LzA:10.20.1.0/27/default", cidr="10.20.1.0/27"
10.20.1.32/27
NetworkV4: network="10.20.1.32/27", network_view="default", _ref="network/ZG5zLm5ldHdvcmskMTAuMjAuMS4zMi8yNy8w:10.20.1.32/27/default", cidr="10.20.1.32/27"
10.20.1.64/27
NetworkV4: network="10.20.1.64/27", network_view="default", _ref="network/ZG5zLm5ldHdvcmskMTAuMjAuMS42NC8yNy8w:10.20.1.64/27/default", cidr="10.20.1.64/27"
10.20.1.96/27
NetworkV4: network="10.20.1.96/27", network_view="default", _ref="network/ZG5zLm5ldHdvcmskMTAuMjAuMS45Ni8yNy8w:10.20.1.96/27/default", cidr="10.20.1.96/27"
Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: High-Level Infoblox API for getting NextAvalialbleNetwork

New Member
Posts: 3
7620     1

Thanks Sif for the example ! 

 

BTW what docs do you meant ? So far I only came across github Readme , which is quite big, but lack examples like you provided. 

Re: High-Level Infoblox API for getting NextAvalialbleNetwork

Techie
Posts: 9
7620     1

how to do this same with powershell?

Re: High-Level Infoblox API for getting NextAvalialbleNetwork

Superuser
Posts: 115
7620     1

You can find that answer here

 

https://github.com/rmbolger/Posh-IBWAPI

 

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com
Showing results for 
Search instead for 
Did you mean: 

Recommended for You