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

VLAN Management in 8.4 WAPI Question

New Member
Posts: 3
5154     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
Moderator
Posts: 32
5154     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 ]
New Member
Posts: 3
5154     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.

Re: VLAN Management in 8.4 WAPI Question

New Member
Posts: 1
5154     0

chris_dipaola 

how to remove the vlan assignment from the network. I am not able to delink the vlan assignment from the assignment using api call. without removing the vlan from the network it is not allowing to delete the networ either vlan. 

Re: VLAN Management in 8.4 WAPI Question

Adviser
Posts: 181
5154     0

Hi,

 

Could you please try the following steps:

  1. Get the reference of the network you want to remove the VLAN from:
    API:
    curl -k -u admin:infoblox -X GET "https://grid-master/wapi/v2.11/network?network=62.0.0.0/24&_return_fields%2B=vlans"
    
    Output:
    [
        {
            "_ref": "network/ZG5zLm5ldHdvcmskNjIuMC4wLjAvMjQvMA:62.0.0.0/24/default", 
            "network": "62.0.0.0/24", 
            "network_view": "default", 
            "vlans": [
                {
                    "id": 11, 
                    "name": "testvlan", 
                    "vlan": "vlan/ZG5zLnZsYW4kLmNvbS5pbmZvYmxveC5kbnMudmxhbl92aWV3JHRlc3QuMTAuMjAuMTE:test/testvlan/11"
                }
            ]
        }
    ]
  2. Issue a PUT command to remove the VLAN assignment as below:
    API:
    curl -k -u admin:infoblox -H 'content-type: application/json' -X PUT "https://10.196.205.101/wapi/v2.11/network/ZG5zLm5ldHdvcmskNjIuMC4wLjAvMjQvMA:62.0.0.0/24/default?_return_fields%2B=vlans&_return_as_object=1" -d '{"vlans": []}'
    Output:
    { "result": { "_ref": "network/ZG5zLm5ldHdvcmskNjIuMC4wLjAvMjQvMA:62.0.0.0/24/default", "network": "62.0.0.0/24", "network_view": "default", "vlans": [] } }

Hope this helps,

Regards,

Krishna Vasudevan

Re: VLAN Management in 8.4 WAPI Question

Techie
Posts: 9
5154     0

How can i get the VLAN id from the hostname or from IP address.

Re: VLAN Management in 8.4 WAPI Question

New Member
Posts: 1
5154     0

Hello Chris
Thank you for sharing this

Can you send me the python codes please 

Thank you 
RedOne

Re: VLAN Management in 8.4 WAPI Question

New Member
Posts: 1
5155     0

I have some basic examples out in Github. Feel free to use them:

https://github.com/c5dipaola/infoblox_api 

Showing results for 
Search instead for 
Did you mean: 

Recommended for You