Example: Configuration management using REST APIs

Downloading a configuration

Downloading the current configuration:

  • Example method and URI:

    GET "https://192.0.2.5/rest/v10.04/ fullconfigs / running-config”
  • Example curl command:

    $curl --noproxy 192.0.2.5 -k GET \ -b /tmp/primary_auth_cookie \ "https://192.0.2.5/rest/v10.04/ fullconfigs / running-config”

Downloading the startup configuration:

  • Example method and URI:

    GET "https://192.0.2.5/rest/v10.04/fullconfigs/startup-config"
  • Example curl command:

    $curl --noproxy 192.0.2.5 -k GET \ -b /tmp/primary_auth_cookie \ "https://192.0.2.5/rest/v10.04/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 other configurations. For more information about copying configurations, see Copying a configuration.

  • Example method and URI:

    PUT "https://192.0.2.5/rest/v10.04/ fullconfigs / running-config”

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

  • Example curl command:

    $curl --noproxy 192.0.2.5 -k -X PUT \ -b /tmp/auth_cookie \ "https://192.0.2.5/rest/v10.04/ 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. Use thefrom查询string parameter to specify the source configuration.

  • At least one of the source or the destination configuration must be eitherrunning-configorstartup-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:///rest/v10.04/fullconfigs/? from=/rest/v10.04/fullconfigs/"

Copying the running configuration to the startup configuration:

  • Example method and URI:

    PUT "https://192.0.2.5/rest/v10.04/fullconfigs/startup-config? from=/rest/v10.04/ fullconfigs / running-config”
  • Example curl command:

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

Copying the startup configuration to the running configuration:

  • Example method and URI:

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

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

Copying a checkpoint to the running configuration:

  • Example method and URI:

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

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

Copying the running configuration to a checkpoint:

  • Example method and URI:

    PUT "https://192.0.2.5/rest/v10.04/fullconfigs/MyCheckpoint? from=/rest/v10.04/ fullconfigs / running-config”
  • Example curl command:

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