Author: Jason Barbee
Contributions by: Jeremy Sanders, Heath Kuespert(htothek), Andrew Smith
Tested with DNA 1.1.1, 1.1.2, 1.1.4, 1.1.6, 1.1.8, 1.2.5, 2.2.3 Latest Version tested DNA 2.2.3
- Imports CSV to DNA Switch ports
- Exports DNA Switch ports to CSV
- Converts IOS to YML then CSV format for import
- Merges 24 to 48 port switch port in the CSV for combining (2) 24 port switches to a 48.
- Exports Virtual Networks and Address pools.
- Renames FastEthernet0/XX to GigabitEthernetX/0/XX based on the stack parameter passed.
- Locates a MAC address or any partial mac system wide in DNA.
- Prints Inventory and Provisioning Status of the system
- Exports configs from all devices in DNAC into raw files under configs folder.
Install Python 2 (or 3 doesn't matter) and Libraries
pip3 install requests pyaml requests
Modify your config.yml file
global:
hostname: 'fqdn_of_DNAC'
username: 'admin'
password: 'password'
defaultVoiceVN: '10_0_1_0-Phone_VN' (your default phone VN)
VoiceVlans: ['101','102'] (this helps the script know what voice vlans are - must manually update till I use the spreadsheet field.)
This is a format that worked for us, it stores some relevant data as we migrate.
This will take a file containg anything along with raw config, turn it into a YAML structure so we can later group the data together into switch stacks for DNA.
Drop your bulk configs in a folder call configs. Use .txt or .cfg suffixes. Name them like this Closet_1.1_Stack# - like Closet_1.1_1.txt. If you have Closet_1.1_2.txt the script will join them together automatically as a stack.
- Copy configs to configs folder.
- Run the script below.
python3 dnac-bulk.py --action migrate
- Parses the config folder.
- Exports to YML in yml_cfg.
- Cross Lookups DNA reference information to generate import data.
- Exports CSVs to converted_csvs
Have a CSV file ready through conversion(above) or manual building that looks like this
Switch Name,Interface,Address Pool(VN),Voice Pool(VN),Authentication
CLOSETSWITCH_1.domain.loc,GigabitEthernet1/0/1,10_0_0_0-Corp_VN,10_0_1_0-Phone_VN,No Authentication
python3 dnac-bulk.py --action import --input closet1.csv --switchname switch1.domain.loc
It will generate a compatible format above for re-importing. Good for backups.
python3 dnac-bulk.py --action export --output export.csv --switchname switch.domain.com
Wipe switch so that it can be re-provisioned from CLI.
python3 dnac-bulk.py --action clear --switchname switch.domain.com
python3 dnac-bulk.py --action findhost --mac 08:cc:a7:85:cb:5f
-------
Searching for Phone MAC Addresses ending with 08:cc:a7:85:cb:5f
Host IP: 10.2.2.2
Host MAC: 08:cc:a7:85:cb:5f
Switch Device IP: 10.1.1.1
Switch Name: switch.domain.loc
Switch Interface: GigabitEthernet1/0/48
python3 dnac-bulk.py --action backupconfigs
-------
Exporting switchname...
This step uses a DNA API Request to pull all endpoints DNA has categorized as IP_PHONE, and basically greps them for a match.
python3 dnac-bulk.py --action findphone --mac cb5f
-------
Searching for Phone MAC Addresses ending with cb5f
Host IP: 10.2.2.2
Host MAC: 08:cc:a7:85:cb:5f
Switch Device IP: 10.1.1.1
Switch Name: switch.domain.loc
Switch Interface: GigabitEthernet1/0/48
python3 dnac-bulk.py --action inventory
Hostname Platform Uptime Version CollectionStatus IP Address Reachability Status
A-DNA-SWITCH C9500-40X 95 days, 3:01:50.69 16.6.3 Managed 10.1.1.1 Reachable "SUCCESS"
This will convert the YAML to a CSV intermediary format for my script to later import.
python3 dnac-bulk.py --action convert --stack 1 --input yml_cfgs/211.yml --output 211.csv
- Run the Conversion process for Stack 2, etc. It will append to the csv file.
python3 dnac-bulk --stack 2 --input 212.yml --output 21.csv
If you need to convert a 24 to 48 port switch use --to48 it will transpse interfaces by 24, useful on the second switch in a merged stack of 48 ports.
python3 dnac-bulk --stack 2 --input 212.yml --output 21.csv --to48
- VN/Pool export shows up on screen, it does not write to CSV well yet. Partially implemented.
- This uses unofficial API calls to DNA, and may be volatile, but has not been so far(ok - one time they changed an API key), but I follow the WEB UI's response. This is not doing anything more magic than the same API calls you use when in Firefox. I just had to reverse engineer the calls using Firefox Inspector on the DNA Web Interface.
- I plan to actively support this through a rollout of a few hundred more switches probably till end of 2018.
- Open a github issue if you have one, or submit a pull request and I'll review it. We have 300 switches or so left to go, so if you think it's useful, I might add it.
- Long term, once Cisco publishes a real DNA API, I don't know what will happen to this tool.
- Better documentation
- Rethink the way voice address pools are handled.
MIT License. Copyright Jason Barbee 2018.
C Spire is a Cisco Gold Partner that offers professional services to support your DNA SD-Access design and installation.
Visit www.cspire.com for more information