Example: Configuration management using REST APIs

Downloading a configuration

Downloading the current configuration:

  • Example method and URI:

    GET "https://192.0.2.5/rest/v1/fullconfigs/running-config"
  • Example curl command:

    $ curl -k --noproxy 192.0.2.5 GET \
    -b /tmp/primary_auth_cookie \
    "https://192.0.2.5/rest/v1/fullconfigs/running-config"
    

Downloading the startup configuration:

  • Example method and URI:

    GET "https://192.0.2.5/rest/v1/fullconfigs/startup-config"
  • Example curl command:

    $ curl -k --noproxy 192.0.2.5 GET \
    -b /tmp/primary_auth_cookie \
    "https://192.0.2.5/rest/v1/fullconfigs/startup-config"
    

On successful completion, the switch returns response code 200 OK and a response body containing the entire configuration in JSON format.

Uploading a configuration

The following example shows uploading a configuration to become the running configuration. The running configuration is the only configuration that can be updated using this technique. However you can copy configurations (see Copying configurations).

  • Example method and URI:

    PUT "https://192.0.2.5/rest/v1/fullconfigs/running-config"

    The request body must contain the configuration—in JSON format—to be uploaded.

  • Example curl command:

    $ curl -k --noproxy "192.0.2.5" -X PUT \
    -b /tmp/auth_cookie \
    "https://192.0.2.5/rest/v1/fullconfigs/running-config" \
    –d '
    {
    …
    }'
    

    The configuration being uploaded—represented as ellipsis but not shown in this example—is in JSON format in the body of the command (enclosed in braces).

On successful completion, the switch returns response code 200 OK.

Copying a configuration

To replace an existing configuration with another, use a REST PUT request to the destination configuration, using the from query string parameter to specify the source configuration.

  • At least one of the source or the destination configuration must be either running-config or startup-config. You cannot copy a checkpoint to a different checkpoint.

  • If you specify a destination checkpoint that exists, an error is returned. You cannot overwrite an existing checkpoint.

The syntax of the method and URI is as follows:

PUT "https://<IPADDR>/rest/v1/fullconfigs/<destination-config>?
from=/rest/v1/fullconfigs/<source-config>"

Copying the running configuration to the startup configuration:

  • Example method and URI:

    PUT "https://192.0.2.5/rest/v1/fullconfigs/startup-config?
    from=/rest/v1/fullconfigs/running-config"
  • Example curl command:

    $ curl -k --noproxy "192.0.2.5" -X PUT \
    -b /tmp/auth_cookie -D- 
    "https://192.0.2.5/rest/v1/fullconfigs/startup-config?
    from=/rest/v1/fullconfigs/running-config"
    

Copying the startup configuration to the running configuration:

  • Example method and URI:

    PUT "https://192.0.2.5/rest/v1/fullconfigs/running-config?
    from=/rest/v1/fullconfigs/startup-config"
  • Example curl command:

    $ curl -k --noproxy "192.0.2.5" -X PUT \
    -b /tmp/auth_cookie -D- 
    "https://192.0.2.5/rest/v1/fullconfigs/running-config?
    from=/rest/v1/fullconfigs/startup-config"
    

Copying a checkpoint to the running configuration:

  • Example method and URI:

    PUT "https://192.0.2.5/rest/v1/fullconfigs/running-config?
    from=/rest/v1/fullconfigs/MyCheckpoint"
  • Example curl command:

    $ curl -k --noproxy "192.0.2.5" -X PUT \
    -b /tmp/auth_cookie -D- 
    "https://192.0.2.5/rest/v1/fullconfigs/running-config?
    from=/rest/v1/fullconfigs/MyCheckpoint"
    

Copying the running configuration to a checkpoint:

  • Example method and URI:

    PUT "https://192.0.2.5/rest/v1/fullconfigs/MyCheckpoint?
    from=/rest/v1/fullconfigs/running-config"
  • Example curl command:

    $ curl -k --noproxy "192.0.2.5" -X PUT \
    -b /tmp/auth_cookie -D- 
    "https://192.0.2.5/rest/v1/fullconfigs/MyCheckpoint?
    from=/rest/v1/fullconfigs/running-config"