Skip to main content

Community-developed Python CLI companion for the DNA Center SDK

Project description

Command Line Interface for Cisco DNA Center APIs.


dnacentercli is a CLI built for working with the DNA Center APIs.

Installation

To install dnacentercli, you will need to have python and pip installed. After you can enter the following command:

$ pip install dnacentercli

The project has a few dependencies:

Note: dnacentercli works starting from python 3

What is DNA Center?

“A better way to control your network. Cisco DNA Center is the network management and command center for Cisco DNA, your intent-based network for the enterprise.”

Visit the official DNA Center website for more information.

Usage

The DNA Center CLI depends and actively uses the DNA Center SDK. They, however, have some differences in their usage.

API Version

Cisco DNA Center SDK wraps DNA Center APIs (versions: 1.2.10 and 1.3.0), using the version parameter to control which API version to use.

DNA Center CLI does it by separating the versions by the –dna-version or -v option.

Authenticate

DNA Center SDK creates a DNACenterAPI “Connection Object” defaults to pulling from environment variables and config values. The same happens for the DNA Center CLI.

You can ask for help using --help and see the list of options and commands available on your selected version:

$ dnacentercli -v '1.2.10' --help

Note:

To avoid getting errors like the following:

> HTTPSConnectionPool(host='128.107.71.199', port=443):
Max retries exceeded with url: /dna/system/api/v1/auth/token (Caused by SSLError
(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate
verify failed: self signed certificate in certificate chain (_ssl.c:1076)')))

Include the verify option and set it to False: --verify False

Access to DNA Center APIs

You need to authenticate for accessing other DNA Center APIs, such as Clients, Networks or PnP.

You can ask for specific API help using --help after the previous command options, which will list the endpoints (as commands):

$ dnacentercli -v '1.2.10' --base_url https://128.107.71.199:443 --verify False networks --help

Making API Calls

Each DNA Center SDK API Call parameter is a DNA Center CLI option.

The following call using the dnacentersdk

from dnacentersdk import DNACenterAPI
api = DNACenterAPI(username="devnetuser",
                   password="Cisco123!",
                   base_url="https://sandboxdnac2.cisco.com:443",
                   version='1.2.10',
                   verify=True)

api.networks.get_overall_network_healt(timestamp='1568008500000', headers={'__runsync': True})

is the same as

$ dnacentercli -v '1.2.10' --username devnetuser --password Cisco123! \
> --base_url https://sandboxdnac2.cisco.com:443 --verify True \
> networks get-overall-network-health \
> --timestamp "1568008500000" --headers '{"__runsync": true}'

Note:

There are differences across platforms about JSON strings.

On *nix based systems and command lines, the following is a valid JSON string representation:

$ dnacentercli -v '1.2.10' networks get-overall-network-health \
--timestamp "1568008500000" --headers '{"__runsync": true}'

On Windows and its command lines, the following is the valid JSON string representation:

dnacentercli -v '1.2.10' networks get-overall-network-health ^
--timestamp "1568008500000" --headers '{\"__runsync\": true}'

Be careful.

Multiple Options

There are some cases where the parameter type is a list. To record all the values, you have to provide the parameter multiple times.

For example:

$ dnacentercli -v '1.2.10' devices add-device --ipaddress '10.20.10.1' --ipaddress '10.30.10.1'

Bell

To activate the beep when the spinner finishes (or the API call ends), add the --beep option to your API Call. The --beep option is a boolean flag if present is on otherwise is off.

Pretty Print

To pretty-print the JSON response add the option -pp or --pretty_print INTEGER to your API Call, where the INTEGER is the indentation.

Both the debug and the JSON response of the API call are streamed to the Standard Output (stdout).

For example:

$ dnacentercli -v '1.2.10' devices get-device-list --family 'Unified AP' --hostname 'T1-9' -pp 2
{
  "response": [
    {
      "apManagerInterfaceIp": "10.10.20.51",
      "associatedWlcIp": "10.10.20.51",
      "bootDateTime": null,
      "collectionInterval": "NA",
      "collectionStatus": "Managed",
      "errorCode": "null",
      "errorDescription": null,
      "family": "Unified AP",
      "hostname": "T1-9",
      ...
      "memorySize": "NA",
      "platformId": "AIR-AP1141N-A-K9",
      "reachabilityFailureReason": "NA",
      "reachabilityStatus": "Reachable",
      "role": "ACCESS",
      "roleSource": "AUTO",
      "serialNumber": "1140K0009",
      ...
      "snmpContact": "",
      "snmpLocation": "default-location",
      "softwareType": null,
      ...
      "tagCount": "0",
      "tunnelUdpPort": "16666",
      "type": "Cisco 1140 Unified Access Point",
      "upTime": "195days 11:11:32.270",
      "waasDeviceMode": null
    }
  ],
  "version": "1.0"
}

Exceptions

All DNA Center SDK exceptions are streamed to the Standard Error (stderr). Before exiting the program, it will print the traceback (limited to 1 element), the exception name and its description.

Copyright (c) 2019 Cisco and/or its affiliates.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dnacentercli-0.0.2.tar.gz (221.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dnacentercli-0.0.2-py3-none-any.whl (100.0 kB view details)

Uploaded Python 3

File details

Details for the file dnacentercli-0.0.2.tar.gz.

File metadata

  • Download URL: dnacentercli-0.0.2.tar.gz
  • Upload date:
  • Size: 221.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for dnacentercli-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c4d2ba15c980197c6765eefb1d930ae93a759e18bad24b6ddc1dd1f3fbbb7180
MD5 18c0c4d4a3864ec9d1c4403dc71c39fb
BLAKE2b-256 35fdd4bc747d24ba263a4f59ca9d9c08f97a4795fc9d7d3883e9d3025333b014

See more details on using hashes here.

File details

Details for the file dnacentercli-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: dnacentercli-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 100.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for dnacentercli-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 02e46cae4d82fbb7e3695e2d835f084c7e3597a2438e2f550c18febf550ff79c
MD5 1ac5b37903533805d2df20d36ac318a8
BLAKE2b-256 b75641244172ff89d78a844cc1faf4a04306203de29f8178cbc591abfa5c8b06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page