Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

API & Integration

Accepted Solution

"func:nextavailablenetwork" Not creating a new network

[ Edited ]
Posts: 5
3611     0

I have a three step Python script which does the following:




This returns a list of all the networks in the "Aggregates" view from the /8

(There's a reason I use the ~= instead of here, which is not relevant to the discussion, but needed internally.) 



Retrieve the "_ref" from the above list and then run this:


JSON Data for the GET is:

payload = {
"num": 15,
"cidr": 28


This returns the next 15 available /28 networks from the Grid.

(NOTE - This is mostly a sanity check, and not needed down the road.)



Then I run this:



JSON Data for the POST is:
payload = {
"network" : "func:nextavailablenetwork:,ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMg:,28"

The crux of the matter is - this all works wonderfully the first time I run it.  It creates a list of valid /28 choices (manually verified to make sure that is right) then it creates the first /28 from the list.


My problem is, if I run this is second time, I find the following two issues:

In Step 2:

The newly created subnet is still listed as available.

In Step 3:

I get this error instead of creating the next valid /28 network after the first one:

Select another network.', u'code': u'Client.Ibap.Data.Conflict', u'Error': u'AdmConDataError: None (IBDataConflictError: IB.Data.Conflict:The network already exists.  Select another network.)'}


I did consider that the issue was caused by the fact the network was "empty" - so I added in a fourth step to add some fixed addresses to populate the network, but that did not make a difference in the above errors.


To complicate matters a little, I have two network views, I run the same script in both and, regardless of which _ref I pull and which network I use, the nextavailablenetwork function only wants to create them in the 'default' view.  I have included my 'default' view examples here, since these might be discrete issues.


Anyway, any help or suggestions on why this function is not working would be great.




Re: "func:nextavailablenetwork" Not creating a new network

Community Manager
Community Manager
Posts: 248
3611     0

Yeah, so there there are a few issues going on here, I'm not sure which ones you are seeing, and in what order, but here goes:


1) There are both ',' and ':' delims in the func:nextavailablenetwork. The syntax is:



  func:nextavailablenetwork:<network>[,<network view>],<CIDR>


change the ':,' to ':'


2) func:nextavailablenetwork BYPASSES steps 1 & 2, it is designed so that you don't need the _ref. You use either the _ref or a direct network search string. Try using:






3) Be specific about the network view, otherwise the WAPI is just guessing. Try this




4) When you create a sub-network, it turns the parent network into a 'networkcontainer' and this can sometimes mess up adding additional networks, which can sometimes also break the _ref (because it has changed).


Once you create the first network, if you make the call again, you may have to get the _ref again to check it is still kosher. (but now you will have to search the /networkcontainer objects)


Again, using the network/cidr syntax avoids all this because the system will find the right _ref for you.


5) if you've gone to the trouble to search for the next available networks in steps 1-2, why not just use that info to create a network? If you want to avoid race conditions, then yes, step 3 is the workaround, otherwise don't bother


6) From the WAPI guide:


"...If you specify a network view for automatic network selection, you should also add a network_view field in the object to be inserted with the same network view because the network view for automatic network selection is not used for the actual object insertion..."


Translation, your POST still needs to say what view to put this newly found network into.


If none of that's working, you may have hit a bug with the _ref version of func:nextavailablenetwork, and you should chase that down with support.


Re: "func:nextavailablenetwork" Not creating a new network

Posts: 5
3612     0

Reponses - in order:


1) I wish it had been that easy, but the extra "," was just a bad cut and paste from a variable.

2, 3, & 4) All good to know, but did not 'fix' the problem, since I had tried them in various forms.

5) This was the KISS principle solution that I missed.  Since the search for the "nextavailablenetwork" was working in Step 2, I just converted step 3 into "take the first 2 items from the list and add those using a new network" WAPI post.  It works 100% of the time now.


Thanks for the response!

Showing results for 
Search instead for 
Do you mean 

Recommended for You