Skip to content

Commit

Permalink
Merge pull request #2 from alphabet5/update-to-napalm
Browse files Browse the repository at this point in the history
0.0.3
  • Loading branch information
alphabet5 authored Aug 14, 2021
2 parents 081581e + 90bdbea commit 7b420cc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ cisco_documentation.egg-info/*
log.txt
output.csv
output.json

dist/*
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions cisco_documentation/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.3
37 changes: 29 additions & 8 deletions cisco_documentation/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import netmiko.ssh_exception
import yamlarg
import os
import shutil
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand Down
Binary file removed dist/cisco_documentation-0.0.1-py2.py3-none-any.whl
Binary file not shown.
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
description="Gather information from switches to create documentation in excel.",
Expand Down

0 comments on commit 7b420cc

Please sign in to comment.