Example: Configuration management using REST APIs

Downloading a configuration image

Example of downloading the current configuration:

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

Example of downloading the startup configuration:

GET "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 image

The following example shows the curl command to upload a configuration to become the running configuration. 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).

The running configuration is the only configuration that can be updated using this technique. However you can copy configurations (see Copying configurations).

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

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

Copying configurations

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.

  • 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 is as follows:

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

Example of copying the running configuration to the startup configuration:

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

Example of copying the startup configuration to the running configuration:

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

Example of copying a checkpoint to the running configuration:

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

Example of copying the running configuration to a checkpoint:

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