Forum Discussion
REST API VLAN creation and interface sub-collection
I have been playing around with REST API and have stumbled across a challenge around assigning a "tagged" interface.
In this sample REST call, I create the vlan name, set the vlan tag & set the description. I assume a default setting exists assigning the interface as "Untagged" because that is the net result in tmsh.
https://10.128.1.245/mgmt/tm/net/vlan{"interfaces": "1.2", "kind": "tm:net:vlan:vlanstate", "tag": "10", "name": "v10", "description": "automation test"}
What I would like to do is add the interface as tagged. I have researched this for countless hours and attempted numerous uri variations. The interface portion of the config is a "sub-collection" so I have even tried setting the interface directly (after vlan creation) via https://10.128.1.245/mgmt/tm/net/vlan/v10. I tried numerous variations against that base URL as well. All to no avail.
This can be done via the following curl call, so I assume it can be done via the REST API?
curl -sk -u admin: -H "Content-type: application/json" -X POST -d '{"name":"v10","tag":"10","interfaces": [{"name":"1.2","tagged":true}]}' https://10.128.1.245/mgmt/tm/net/vlan
Can this be done via REST? All guidance appreciated.
7 Replies
- CBohannan_14046
Nimbostratus
Where are all the API guru's? =) - JRahm
Admin
That curl statement IS a REST API call.
- Jerry_Lees_4280Historic F5 Account
Jason is right, that curl command is an API call-- and is correct for a curl call. I am having similar challenges toying with this task in Python. I suspect that it's my ability to deal with collections in python (or anything in Python) and getting the JSON correctly formatted.
What language are you trying to do this in? Maybe you could provide some sample code for someone to look at more closely?
- Wiehann_Kotze_3
Nimbostratus
Hi, I am trying to do the same thing in Powershell but am also having trouble. Were you able to figure out the correct syntax ?
- Satoshi_Toyosa1Ret. Employee
Windows version curl (and the dos/power shell prompt) may handle the special characters slightly differently from its unix counterpart. When you have a complex JSON data to post/patch, try writing it to a file, and use -d@file instead.
- StephanManthey
Nacreous
Hi, I did not manage to get it done in a single step. Splitting it into two steps works fine as follows:
vlan create curl -svk -u admin:admin "https://localhost/mgmt/tm/net/vlan/" -H 'Content-Type: application/json' -POST -d '{"name": "", "tag": }' | python -m json.tool vlan interface assign curl -svk -u admin:admin "https://localhost/mgmt/tm/net/vlan/~Common~/interfaces" -H 'Content-Type: application/json' -X POST -d '{"name": "", "tagged": true}' | python -m json.tool vlan interface delete curl -svk -u admin:admin "https://localhost/mgmt/tm/net/vlan/~Common~/interfaces/" -X DELETE | python -m json.tool vlan delete curl -svk -u admin:admin "https://localhost/mgmt/tm/net/vlan/~Common~" -X DELETE | python -m json.toolCheers, Stephan
- StephanManthey
Nacreous
Hi,
perhaps this question is still of interest? This one is a single step solution (tested on TMOS v13.1.0.6) to create a new VLAN and assign an interface in tagged mode:curl -sk -u admin:admin "https://10.200.200.21/mgmt/tm/net/vlan" -H 'Content-Type: application/json' -X POST -d '{"name":"vlan_lab-103", "tag":103, "interfaces": [{"name":"1.3", "tagged": true}]}'A slightly modified syntax with the same result:
Cheers, Stephancurl -sk -u admin:admin "https://10.200.200.21/mgmt/tm/net/vlan" -H 'Content-Type: application/json' -X POST -d '{"name":"vlan_lab-103", "tag":103, "interfacesReference":{"items":[{"name":"1.3","tagged":true}]}}'
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
