Example: Creating a VLAN with a port using REST APIs

This example shows creating the following VLAN and port 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
  1. Creating the VLAN.

    $ curl -k --noproxy 192.0.2.5 POST \ 
    -b /tmp/auth_cookie -d '{
    "name":"VLAN2",
    "id":2,
    "type":"static",
    "admin":"up"}' \
    "https://192.0.2.5/rest/v1/system/bridge/vlans"
  2. Creating a port and configure the VLAN information.

    $ curl -k --noproxy 192.0.2.5 POST \
    -b /tmp/auth_cookie -d '{
    "name": "1/1/2",
    "admin":"up",
    "interfaces":["/rest/v1/system/interfaces/1%2F1%2F2"],
    "vlan_mode":"access",
    "vlan_tag":"/rest/v1/system/bridge/vlans/2",
    "referenced_by":"/rest/v1/system/bridge"
    "description":"referenced by /system/bridge"}' \
    -D- "https://192.0.2.5/rest/v1/system/ports"
  3. Getting the 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/v1/system/interfaces/1%2F1%2F2?selector=configuration"
    {
      "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": {}
    }
  4. Verifying which configuration attributes are mutable and therefore can be included in the PUT request.

    When you send a PUT request, the JSON request body must not contain immutable attributes. The ArubaOS-CX REST API Reference JSON model for the PUT method of the resource shows the mutable attributes. Any mutable attributes you do not include in the PUT request body are set to their defaults, which could be empty.

    The ArubaOS-CX REST API Reference JSON model for the PUT method of the /system/interfaces/{id} resource shows the following example:

    {
      "description": "string",
      "options": {},
      "other_config": {},
      "selftest_disable": true,
      "udld_arubaos_compatibility_mode": "string",
      "udld_compatibility": "string",
      "udld_enable": true,
      "udld_interval": 0,
      "udld_retries": 0,
      "udld_rfc5171_compatibility_mode": "string",
      "user_config": {}
    }
  5. Enabling the interface using all the attributes in the return body received from the GET request, modifying the user_config attribute to be: "user_config":{"admin":"up"}

    $ 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/v1/system/interfaces/1%2F1%2F2"
    

    In the preceding example, the following mutable attributes listed in the previous step were not included, so they are set to their default values, which could be empty:

    • description

    • selftest_disable