This repository is deprecated; please follow the main search page or use the ‘Related code repos’ widget on the right side of the current page.

DNAC-DNS-Automation

Automatically update device management from IP to DNS

This script is made for situations where DNAC users cannot rely on IP address to identify and manage devices, and need a dynamic, automated, and human friendly way to name and manage devices.

How it works

  1. DNAC generate a DNS name for the device through Day 0 template and provision/onboard the device
  2. Device boots and register DNS name automatically
  3. Run this script to update DNAC to manage these devices with DNS name instead of IP
    This script can also be run priodically to scan for new device onboarded and update their device information automatically

How to use

Before you start, please make sure you're running python version 3 and up. If you have multiple versions on the system, please run this by specifying Python version, for example,

python3 main.py

Or you can use venv, for example

python3 -m venv dns-automation

On Windows, run

dns-automation\Scripts\activate.bat

On Linux/Unix or MacOS, run

source dns-automation/bin/activate

Also, please make sure all the required packages are installed by issueing the following

pip install -r requirements.txt

This will make sure the modules are available so you won't see errors during import

  1. Configuration file
    Update "Config.py" with information of your environment. Wha'ts currently provided was DNAC Sandbox.
    You can use this for test but you wouldn't be able to make changes.
    When you run the script you will get a HTTP 403 code becuase you won't have access to make change on Sandbox.

    ### Use this file to configure access to DNAC
    ### Replace all values below with your production DNAC
    ### Provided is DNAC sandbox login
    
    DNAC_FQDN = 'sandboxdnac.cisco.com'
    DNAC_PORT = '443'
    DNAC_USER = 'devnetuser'
    DNAC_PASSWORD = 'Cisco123!'
    
    ### SCOPE of devices thi script is going to manipulate, this need to be the same as "Series" field of the device
    SCOPE = ["Cisco Catalyst 9300 Series Switches", "Cisco Catalyst 9200 Series Switches"]
    
    ### Optoinal - Domain that all devices belong to, for example ".cisco.com", the hostname of the device would be "device.cisco.com"
    DOMAIN = ".abc.inc"
    
  2. Make sure you have all 3 files

    • config.py - stores configuration as described in # How to use item 1
    • util.py - functions needed to run the script
    • main.py - main script
  3. Run "main.py"

    • Expected results
    # If "No" is chosen update operations will be canceled
    
     Parsing device list...
     Found new device, collecting information...
     Found new device, collecting information...
     ================================================================================
     Parsing complete, here is a list of devices that needs updated, please confirm...       
     ================================================================================
     10.10.22.66:    Cisco Catalyst 9300 Series Switches
     10.10.22.70:    Cisco Catalyst 9300 Series Switches
     Confirm to update devices [Y/N]? n
     ================================================================================
     Task canceled, exiting...
     ================================================================================
    
    # If "Yes" is chosen update operations proceed and devices will be updated
    
     Parsing device list...
     Parsing device list...
     Found new device, collecting information...
     Found new device, collecting information...
     ================================================================================
     Parsing complete, here is a list of devices that needs updated, please confirm...
     ================================================================================
     10.10.22.66:    Cisco Catalyst 9300 Series Switches
     10.10.22.70:    Cisco Catalyst 9300 Series Switches
     Confirm to update devices [Y/N]? y
     Confirmed, updating devices...
     ================================================================================
     Task completed, exiting...
     ================================================================================
    
    # If you're using the sandbox or don't have access to make changes, the following error will be seen
    
     Parsing device list...
     Found new device, collecting information...
     Found new device, collecting information...
     ================================================================================
     Parsing complete, here is a list of devices that needs updated, please confirm...
     ================================================================================
     10.10.22.66:    Cisco Catalyst 9300 Series Switches
     10.10.22.70:    Cisco Catalyst 9300 Series Switches
     Confirm to update devices [Y/N]? y
     Confirmed, updating devices...
     ================================================================================
     Unauthorized to make a change! Existing...
     ================================================================================
     Operation failed, exiting...
     ================================================================================
     Unauthorized to make a change! Existing...
     ================================================================================
     Operation failed, exiting...
     ================================================================================
     Task completed, exiting...
     ================================================================================
    

Thank you. If there's any issue please feel free to contact the author.

View code on GitHub

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.