Reply
Highlighted

Using WAPI to create Network container and networks

RYoung
Techie
Posts: 8
7163     0

Hi,

I am just getting started using the WAPI API and would like to know how to create a network container and the networks inside the conatiner. I was able to create the network container, but have not been successful in determining the correct URL to create the networks inside the container. I have a requirement that will not permit me to use the Perl interface. Any help on this is greatly appreciated. Thanks.

Ray

 

Re: Using WAPI to create

I-Team Employee
Employee
Posts: 186
7164     0

If you take a look at this piece of sample code, it shows a way to create a network and do some simple manipulations. That's a starting point for what you want.

http://www.infoblox.com/community/content/overview-wapi-multiple-action-sample-code

 

 

Re: Using WAPI to create

RYoung
Techie
Posts: 8
7164     0

Thanks for your reply.

When I tried to add a network to a previously created network container with the following URL

https://infoblox_host/wapi/v1.0/network?_return_type=xml&_method=POST&network_container=x.x.x.x/16&_...

 

I get the following error:

{ "Error": "AdmConProtoError: Unknown argument/field: 'network_container'",   "code": "Client.Ibap.Proto",   "text": "Unknown argument/field: 'network_container'"}

If I change 'network_container' to network, I get the same error, except it says 'network' is unknown. These fields are documented but don't seem to exist. The documentation is from the same machine as where the Infobox grid manager is running. I know we have beta code for WAPI, so is this a case of needing updated code? How can I check what version I have?

Re: Using WAPI to create

I-Team Employee
Employee
Posts: 186
7164     0

next_available_network is not defined for a networkcontainer. It's only defined for a network. So for what you want to do, you'd need to create a networkcontainer and also a network object, and use the latter to find and create the next_available_network, then insert it into a networkcontainer. 

 

 

Re: Using WAPI to create

RYoung
Techie
Posts: 8
7164     0

I have the network container created (x.x.x.x/16). I need to create 10 (for example) /29 networks in the x.x.x.x/16 container. How do I do that? I am having problems trying to create networks under a specific network container. Can you provide an example? Thanks.

Re: Using WAPI to create

I-Team Employee
Employee
Posts: 186
7164     0

I don't have sample code that covers that case right now, but let me see if I can put something together. 

Re: Using WAPI to create

RYoung
Techie
Posts: 8
7164     0

Thanks!

Re: Using WAPI to create

RYoung
Techie
Posts: 8
7164     0

Hi,

Have you had a chance to put together the sample code? Thanks.

Also, I need to handle this scenario:  after the initial 10 (for example) networks have been created in the network container, how do I add another 10 networks to the same network container at a lter time?

Thanks,

Ray

 

Example

CCappelen
Techie
Posts: 1
7164     0

Hi, have you had the chance to put something together?
The API doc is sadly not very well documented compared to many other enterprise solutions, some help would be MUCH appreciated. Smiley Very Happy


 

 

Creating network container and networks with WAPI

Adviser
Posts: 132
7164     0

To create a network container you basically do a POST with a '.../networkcontainer' URL; the POST parameters would include the 'network' field (in CIDR format) and optionally other fields as well, such as the desired network view (if you have more than one). Creating a network works the same way, except the POST is done with a '.../network' URL. You do not need to reference the network container when creating a network; NIOS figures out which network container the network should go into.

Here is an example Python script that creates a /24 network container and then creates four /26 subnets within it.

#!/usr/bin/python
# Create a network container and networks within it.

"""
Create a network container and networks within it.

This script should work on NIOS 6.6 and later (WAPI 1.0 and later).
"""

# Import the required Python modules.
import sys
import requests
import json

# Set parameters to access the Infoblox WAPI for your own grid master.
url = 'https://gm.example.com/wapi/v1.0/'
id = 'admin'
pw = 'infoblox'
valid_cert = True  # False if self-signed certificate

# Network container, list of networks to create within it, and network view.
net_container = '192.168.250.0/24'
nets = ['192.168.250.0/26', '192.168.250.64/26',
        '192.168.250.128/26', '192.168.250.192/26']
net_view = 'default'

# Create the network container.
container_data = {'network': net_container, 'network_view': net_view}
r = requests.post(url + 'networkcontainer',
                  data=json.dumps(container_data),
                  auth=(id, pw),
                  verify=valid_cert)
if r.status_code != requests.codes.created:
    error_msg = 'Error {} creating network container {}: {}'
    sys.exit(error_msg.format(r.status_code, net_container, r.reason))
else:
    success_msg = 'Created network container {}'
    print success_msg.format(net_container)

# Create subnets within the network container.
for net in nets:
    net_data = {'network': net, 'network_view': net_view}
    r = requests.post(url + 'network',
                      data=json.dumps(net_data),
                      auth=(id, pw),
                      verify=valid_cert)
    if r.status_code != requests.codes.created:
        error_msg = 'Error {} creating network {}: {}'
        sys.exit(error_msg.format(r.status_code, net, r.reason))
    else:
        success_msg = 'Created network {}'
        print success_msg.format(net)

This script explicitly specifies the network view, but you don't need to include that if you have only one network view or if you want to use the default network view.

Also, at least in recent versions of NIOS there is a way to return the next available network(s) within a network container. I have not tried this variation yet, but it might be a simpler way to do what I did above.

Showing results for 
Search instead for 
Do you mean 

Recommended for You