Example: Creating a VLAN and a VLAN interface using REST APIs
This example shows creating the following VLAN and interface configuration on a switch at IP address 192.0.2.5:
vlan 2
no shutdown
interface 1/1/2
no shutdown
no routing
vlan access 2
Creating the VLAN.
$ curl -k --noproxy 192.0.2.5 -X POST \ -b /tmp/auth_cookie -d '{ "name":"VLAN2", "id":2, "type":"static", "admin":"up"}' \ "https://192.0.2.5/rest/v10.04/system/vlans"
Creating an interface with VLAN information
$ curl -k --noproxy 192.0.2.5 -X POST \ -b /tmp/auth_cookie -d '{ "vrf": "/rest/v10.04/system/vrfs/default", "vlan_tag":"/rest/v10.04/system/vlans/2", "name":"VLAN2"}' \ -D- "https://192.0.2.5/rest/v10.04/system/interfaces"
Getting the writable configuration information for the interface.
The GET response body includes only the configuration attributes that have been set.
$ curl -k --noproxy 192.0.2.5 GET \ -b /tmp/auth_cookie \ "https://192.0.2.5/rest/v10.04/system/interfaces/1%2F1%2F2?selector=writable" { "options": {}, "other_config": {}, "udld_arubaos_compatibility_mode": "forward_then_verify", "udld_compatibility": "aruba_os", "udld_enable": false, "udld_interval": 7000, "udld_retries": 4, "udld_rfc5171_compatibility_mode": "normal", "user_config": {} }
Enabling the interface by using the return body received from the GET request, modifying the
user_config
attribute to be:"user_config":{"admin":"up"}
Any writable attributes you do not include in the PUT request body are set to their defaults, which could be empty.
$ curl -k --noproxy 192.0.2.5 -X PUT \ -b /tmp/auth_cookie -d '{ "options": {}, "other_config": {}, "udld_arubaos_compatibility_mode": "forward_then_verify", "udld_compatibility": "aruba_os", "udld_enable": false, "udld_interval": 7000, "udld_retries": 4, "udld_rfc5171_compatibility_mode": "normal", "user_config": { "admin": "up" } }' \ "https://192.0.2.5/rest/v10.04/system/interfaces/1%2F1%2F2"