Skip to content

Commit 7b420cc

Browse files
authored
Merge pull request #2 from alphabet5/update-to-napalm
0.0.3
2 parents 081581e + 90bdbea commit 7b420cc

File tree

6 files changed

+55
-17
lines changed

6 files changed

+55
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ cisco_documentation.egg-info/*
88
log.txt
99
output.csv
1010
output.json
11-
11+
dist/*

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1-
# cisco_documentation
1+
# cisco-documentation
22

33
Documentation Method for Cisco Devices using excel.
44

5-
# Requirements
5+
## Requirements
66

77
- python3 (3.9)
88
- pip
99
- cisco-documentation
1010

11-
# Usage
11+
## Installation
12+
13+
```bash
14+
python3.9 -m pip install cisco-documentation
15+
```
16+
17+
## Updating
18+
19+
```bash
20+
pip install --upgrade --upgrade-strategy eager cisco-documentation
21+
```
22+
23+
## Usage
1224

1325
For CiscoDocumentation
1426

15-
- Update switch_list.txt with a complete list of switches.
27+
- Update switch-list.txt with a complete list of switches.
1628
- Device types supported include cisco_ios (ssh), cisco_ios_telnet (telnet)
17-
- Cisco s300 will need aditional changes before it will work.
29+
- Cisco s300 will need additional changes before it will work.
1830
- Run the .exe, or run python3.9 ./CiscoDocumentation.py
19-
- Select 'y' to use the switch_list.txt as input.
31+
- Select 'y' to use the switch-list.txt as input.
2032
- This will output the arp tables from the switches, as well as the devices connected to each port, and port statuses to output.csv
2133

2234
For RunCommands
@@ -38,7 +50,8 @@ For RunCommands
3850
## Building and installing from source
3951

4052
```bash
41-
python3.9 -m pip uninstall cisco-documentation
53+
python3.9 -m pip uninstall cisco-documentation -y
54+
rm dist/cisco_documentation-*-py2.py3-none-any.whl
4255
python3.9 setup.py bdist_wheel --universal
4356
python3.9 -m pip install dist/cisco_documentation-*-py2.py3-none-any.whl
4457
# To upload to pypi

cisco_documentation/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.3

cisco_documentation/cli.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import netmiko.ssh_exception
23
import yamlarg
34
import os
45
import shutil
@@ -10,6 +11,11 @@
1011
import keyring
1112
from napalm.base.helpers import canonical_interface_name
1213
from joblib import Parallel, delayed
14+
15+
#Set rich to be the default method for printing tracebacks.
16+
from rich.traceback import install
17+
install(show_locals=True)
18+
1319
#import asyncio
1420
#from aiomultiprocess import Pool
1521

@@ -23,14 +29,19 @@ def is_open(ip,port):
2329
return False
2430

2531

32+
def setpass(service, username):
33+
import keyring
34+
import getpass
35+
keyring.set_password(service,
36+
username,
37+
getpass.getpass('Enter the ' + username + ' for ' + service + ': '))
38+
39+
2640
def get_or_set_password(service, username):
2741
import keyring
2842
creds = keyring.get_password(service, username)
2943
if creds is None:
30-
import getpass
31-
keyring.set_password(service,
32-
username,
33-
getpass.getpass('Enter the password for ' + service + ', username:' + username + ':'))
44+
setpass(service, username)
3445
creds = keyring.get_password(service, username)
3546
return creds
3647

@@ -91,11 +102,21 @@ def oui_lookup(mac_address, oui_dict):
91102
def collect_sw_info(switch):
92103
sw_ip = switch['switch']
93104
device_info = dict()
94-
un = get_or_set_password(switch['switch'], 'username')
95-
pw = get_or_set_password(switch['switch'], 'password')
96105
driver = get_network_driver(switch['driver'])
97-
device = driver(switch['switch'], un, pw, optional_args={'global_delay_factor': 2, 'transport': switch['transport']})
98-
device.open()
106+
107+
while True:
108+
try:
109+
un = get_or_set_password(switch['switch'], 'username')
110+
pw = get_or_set_password(switch['switch'], 'password')
111+
device = driver(switch['switch'], un, pw,
112+
optional_args={'global_delay_factor': 2, 'transport': switch['transport']})
113+
device.open()
114+
break
115+
except netmiko.ssh_exception.AuthenticationException:
116+
print("Authentication Failed.")
117+
setpass(switch['switch'], 'username')
118+
setpass(switch['switch'], 'password')
119+
99120
device_info['facts'] = device.get_facts()
100121
device_info['full-config'] = device.get_config(full=True)
101122
device_info['config'] = device.get_config()
-624 KB
Binary file not shown.

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
with open("README.md", "r") as fh:
44
long_description = fh.read()
55

6+
with open('cisco_documentation/VERSION', 'r') as f:
7+
version = f.read()
8+
69
setuptools.setup(
710
name="cisco-documentation",
8-
version="0.0.1",
11+
version=version,
912
author="John Burt",
1013
author_email="[email protected]",
1114
description="Gather information from switches to create documentation in excel.",

0 commit comments

Comments
 (0)