Reply

VLAN Management in 8.4 WAPI Question

chris_dipaola
Techie
Posts: 10
286     0

Hello all,

 

  I'm working on putting together some scripting to leverage the new VLAN management in Infoblox.  I've figured out how to do the following using the new WAPI interface v2.10 to do the following via Python "requests":

 

- Get the "_ref" data for each of the VLAN views.

 

- Get the next available VLAN object in a particular VLAN view.

 

- Create a new VLAN object in a particular VLAN view (both manual VLAN ID and next available).

 

  What I am having a hard time figuring out is how to assign a VLAN to a network.  There doesn't seem to be a function in the VLAN ovbject construct (there is "assigned_to", but it is not writable) to do this.

  

  I did find "vlans" under the DHCP Network Object construct, and if I am reading it right there is a "create" section in there.  The "Type" is a "vlanlink" array, and when I follow that link in the API documentation, it takes me to the "vlanklink" section, but I am not following how it works.

 

  So my question is this.  1) Is it possible to add a VLAN to a network object (either an existing VLAN or next available) and 2) if this is possible, does anyone have an example of how to to it?  Please note that I am not super strong with API calls, I rely on Python requests and the Postman application to muddle my way through.

 

  Thanks in advance for your help!

 

Chris.

 

Re: VLAN Management in 8.4 WAPI Question

Moderator Dave_Signori
Moderator
Posts: 117
287     0

Hi Chris.  See if this helps:

 

Below are the sample WAPI requests:

 

Creating VLAN View:

 

curl -H "Content-Type: application/json" -k1 -u  admin:infoblox -X  POST https://<MASTER-IP>/wapi/v2.10/vlanview -d '{"name":"wapi_command","start_vlan_id":100,"end_vlan_id":200,"pre_create_vlan":true}'

 

Creating VLAN:

 

curl -H "Content-Type: application/json" -k1 -u  admin:infoblox -X  POST https://<MASTER-IP>/wapi/v2.10/vlan -d '{"parent":"","name":"Range_vlan","id":154,"reserved":true,"contact":"879220","department":"ng","description":"descn"}'

 

Creating VLAN-Range:

 

 curl -H "Content-Type: application/json" -k1 -u  admin:infoblox -X  POST https://<MASTER-IP>/wapi/v2.10/vlanrange -d '{"vlan_view":"vlanview/ZG5zLnZsYW5fdmlldyR3YXBpX3ZsYW5fdmlldy4xMDAuMjAw","name":"wapi_range-2","start_vlan_id":151,"end_vlan_id":155,"pre_create_vlan":true,"vlan_name_prefix":"","comment":"test comment"}'

 

Next Available VLAN:

 

curl -H "Content-Type: application/json" -k1 -u  admin:infoblox -X  POST https://<MASTER-IP>/wapi/v2.10/vlan -d '{"parent":"vlanview/ZG5zLnZsYW5fdmlldyRzaGVraGFyLjEuMjAw:shekhar/1/200","id":"func:nextavailablevlanid:vlanview/ZG5zLnZsYW5fdmlldyRzaGVraGFyLjEuMjAw:shekhar/1/200","name":"vlan","reserved":true,"contact":"879220","department":"ng","description":"descn"}'

 

Create a network with VLAN:

 

curl -H "Content-Type: application/json" -k1 -u admin:infoblox -X POST https://<MASTER-IP>/wapi/v2.10/network -d '{"network_view":"default","network":"61.0.0.0/24","vlans":[{"vlan": "vlan/ZG5zLnZsYW4kLmNvbS5pbmZvYmxveC5kbnMudmxhbl92aWV3JHNpbmdoLjEuMTAwMC4z:shekhar/1/200" }] }'

 

Create a network with next Available VLAN:

 

curl -H "Content-Type: application/json" -k1 -u admin:infoblox -X POST https://10.35.120.4/wapi/v2.10/network -d{"network_view": "default", "network": "100.0.0.0/24", "vlans": [

{"vlan": "func:nextavailablevlan:vlanview/ZG5zLnZsYW5fdmlldyRzaGVraGFyLjEuMTAw:shekhar/1/200"}]}'

@DaveSignori

Re: VLAN Management in 8.4 WAPI Question

[ Edited ]
chris_dipaola
Techie
Posts: 10
287     0

@DaveSignori,

 

  I was actually going to type up a response to my own message this morning, but thank you for responding as well.  I ended up open a case with support and they were able to provide me with all the commands you posted below.  There is one thing to add to what you posted, and that is how to use PUT to add an existing VLAN to an existing network.

 

Here is an important note from support about using PUT:

 

"Important:  Put method is used to update the values present in the object. If the object needs to be updated, We must include all the object references including the existing ones or else it will overwrite the existing values and update only the values present in the API call."

 

Get all available _ref value for all VLANs:
 
curl -k -u username:yourpassword -X GET https://127.0.0.1/wapi/v2.10/vlan?_return_as_object=1

 

Assign single VLAN to existing network:
 
curl -H "Content-Type: application/json" -k1 -u username:yourpassword  -X PUThttps://127.0.0.1/wapi/v2.10/network/ZG5zLm5ldHdvcmskMS4xLjIuMC8yNC8w:1.1.2.0/24/default -d'{"vlans":[{"vlan":"vlan/ZG5zLnZsYW4kLmNvbS5pbmZvYmxveC5kbnMudmxhbl92aWV3JHRlc3QuMTAuMzAuMTE:test/testvlan/11"}]}'
 
Assign multiple VLANs to an existing network:
     

curl -H "Content-Type: application/json" -k1 -u username:yourpassword  -X PUT https:// 127.0.0.1/wapi/v2.10/ network/ZG5zLm5ldHdvcmskMS4xLjIuMC8yNC8w:1.1.2.0/24/default -d'{"vlans":[{"vlan":"vlan/ZG5zLnZsYW4kLmNvbS5pbmZvYmxveC5kbnMudmxhbl92aWV3JHRlc3QuMTAuMzAuMTE:test/testvlan/11"},{"vlan":"vlan/ZG5zLnZsYW4kLmNvbS5pbmZvYmxveC5kbnMudmxhbl92aWV3JHRlc3QuMTAuMzAuMTI:test/testvlan1/12"},{"vlan":"vlan/ZG5zLnZsYW4kLmNvbS5pbmZvYmxveC5kbnMudmxhbl92aWV3JHRlc3QuMTAuMzAuMTQ:test/testvlan3/14"}]}'

 

  If anyone is interested, I have all these operations in Python using the "requests" module.  I may just go ahead and post them later anyway depending on how much time I have.

 

Thanks again.

 

Chris.

Showing results for 
Search instead for 
Do you mean 

Recommended for You

Businesses are investing heavily into securing company resources from cyber-attacks form cybercrimin