diff --git a/.gitignore b/.gitignore index c7c8090..45823a1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ cisco_documentation.egg-info/* log.txt output.csv output.json - +dist/* diff --git a/README.md b/README.md index 757f45d..1fa88b4 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,34 @@ -# cisco_documentation +# cisco-documentation Documentation Method for Cisco Devices using excel. -# Requirements +## Requirements - python3 (3.9) - pip - cisco-documentation -# Usage +## Installation + +```bash +python3.9 -m pip install cisco-documentation +``` + +## Updating + +```bash +pip install --upgrade --upgrade-strategy eager cisco-documentation +``` + +## Usage For CiscoDocumentation -- Update switch_list.txt with a complete list of switches. +- Update switch-list.txt with a complete list of switches. - Device types supported include cisco_ios (ssh), cisco_ios_telnet (telnet) - - Cisco s300 will need aditional changes before it will work. + - Cisco s300 will need additional changes before it will work. - Run the .exe, or run python3.9 ./CiscoDocumentation.py -- Select 'y' to use the switch_list.txt as input. +- Select 'y' to use the switch-list.txt as input. - This will output the arp tables from the switches, as well as the devices connected to each port, and port statuses to output.csv For RunCommands @@ -38,7 +50,8 @@ For RunCommands ## Building and installing from source ```bash -python3.9 -m pip uninstall cisco-documentation +python3.9 -m pip uninstall cisco-documentation -y +rm dist/cisco_documentation-*-py2.py3-none-any.whl python3.9 setup.py bdist_wheel --universal python3.9 -m pip install dist/cisco_documentation-*-py2.py3-none-any.whl # To upload to pypi diff --git a/cisco_documentation/VERSION b/cisco_documentation/VERSION new file mode 100644 index 0000000..6812f81 --- /dev/null +++ b/cisco_documentation/VERSION @@ -0,0 +1 @@ +0.0.3 \ No newline at end of file diff --git a/cisco_documentation/cli.py b/cisco_documentation/cli.py index 59230fd..046c1b0 100644 --- a/cisco_documentation/cli.py +++ b/cisco_documentation/cli.py @@ -1,4 +1,5 @@ import sys +import netmiko.ssh_exception import yamlarg import os import shutil @@ -10,6 +11,11 @@ import keyring from napalm.base.helpers import canonical_interface_name from joblib import Parallel, delayed + +#Set rich to be the default method for printing tracebacks. +from rich.traceback import install +install(show_locals=True) + #import asyncio #from aiomultiprocess import Pool @@ -23,14 +29,19 @@ def is_open(ip,port): return False +def setpass(service, username): + import keyring + import getpass + keyring.set_password(service, + username, + getpass.getpass('Enter the ' + username + ' for ' + service + ': ')) + + def get_or_set_password(service, username): import keyring creds = keyring.get_password(service, username) if creds is None: - import getpass - keyring.set_password(service, - username, - getpass.getpass('Enter the password for ' + service + ', username:' + username + ':')) + setpass(service, username) creds = keyring.get_password(service, username) return creds @@ -91,11 +102,21 @@ def oui_lookup(mac_address, oui_dict): def collect_sw_info(switch): sw_ip = switch['switch'] device_info = dict() - un = get_or_set_password(switch['switch'], 'username') - pw = get_or_set_password(switch['switch'], 'password') driver = get_network_driver(switch['driver']) - device = driver(switch['switch'], un, pw, optional_args={'global_delay_factor': 2, 'transport': switch['transport']}) - device.open() + + while True: + try: + un = get_or_set_password(switch['switch'], 'username') + pw = get_or_set_password(switch['switch'], 'password') + device = driver(switch['switch'], un, pw, + optional_args={'global_delay_factor': 2, 'transport': switch['transport']}) + device.open() + break + except netmiko.ssh_exception.AuthenticationException: + print("Authentication Failed.") + setpass(switch['switch'], 'username') + setpass(switch['switch'], 'password') + device_info['facts'] = device.get_facts() device_info['full-config'] = device.get_config(full=True) device_info['config'] = device.get_config() diff --git a/dist/cisco_documentation-0.0.1-py2.py3-none-any.whl b/dist/cisco_documentation-0.0.1-py2.py3-none-any.whl deleted file mode 100644 index 2c83121..0000000 Binary files a/dist/cisco_documentation-0.0.1-py2.py3-none-any.whl and /dev/null differ diff --git a/setup.py b/setup.py index 811aa7e..122be03 100644 --- a/setup.py +++ b/setup.py @@ -3,9 +3,12 @@ with open("README.md", "r") as fh: long_description = fh.read() +with open('cisco_documentation/VERSION', 'r') as f: + version = f.read() + setuptools.setup( name="cisco-documentation", - version="0.0.1", + version=version, author="John Burt", author_email="johnburt.jab@gmail.com", description="Gather information from switches to create documentation in excel.",