Skip to content

Commit

Permalink
Merge pull request #62 from laimaretto/devel
Browse files Browse the repository at this point in the history
8.0.1
  • Loading branch information
laimaretto authored May 30, 2023
2 parents d1a44bc + ed634bd commit a360a90
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Versions #

## [8.0.1] - 2023-05-30

- Using latest version of netmiko, 4.2.0
- Update of the method `routerLogin()`, to use the new method from netmiko, `ConnLogOnly()`. If `sshDebug` is True, then a debug file will be created under `logsDirectory` with per-thread information.

## [7.19.4] - 2023-05-06

- Update function `renderCliLine()`
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='taskAutom',
version='7.19.4',
version='8.0.1',
description='A simple task automation tool',
long_description='A simple task automation tool for NOKIA SROS based routers',
long_description_content_type='text/x-rst',
Expand All @@ -13,7 +13,7 @@
license='BSD 3-clause',
packages=['src/taskAutom'],
install_requires=['sshtunnel==0.4.0',
'netmiko==4.1.0',
'netmiko==4.2.0',
'pandas==1.5.2',
'pyyaml==5.3.1',
'python-docx==0.8.11',
Expand Down
2 changes: 1 addition & 1 deletion src/taskAutom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "7.19.4"
__version__ = "8.0.1"
__author__ = 'Lucas Aimaretto'
48 changes: 38 additions & 10 deletions src/taskAutom/taskAutom.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import sshtunnel
import paramiko
from netmiko import ConnectHandler
from netmiko import ConnLogOnly
from scp import SCPClient
import pandas as pd
import yaml
Expand All @@ -37,9 +38,7 @@
from docx.shared import Pt


#logging.basicConfig(level=logging.DEBUG,format='[%(levelname)s] (%(threadName)-10s) %(message)s')

LATEST_VERSION = '7.19.4'
LATEST_VERSION = '8.0.1'

# Constants
IP_LOCALHOST = "127.0.0.1"
Expand Down Expand Up @@ -292,7 +291,7 @@ def fncFormatTime(timeFloat, adjust=True):
return float(int(timeFloat*move))/move

def fncPrintConsole(inText, show=1):
#logging.debug(inText)

localtime = time.localtime()
if show:
output = str(time.strftime("%H:%M:%S", localtime)) + "| " + inText
Expand Down Expand Up @@ -930,6 +929,7 @@ def __init__(self, thrdNum, routerInfo, dictParam):
'outRxJson':{},
'cronScript':None,
'auxRetry':dictParam['auxRetry'],
'sshDebug':dictParam['sshDebug']
}

self.connInfo.update(routerInfo)
Expand Down Expand Up @@ -1380,7 +1380,12 @@ def routerLogin(self, connInfo):
index = index + 1

try:
conn2rtr = ConnectHandler(device_type=deviceType, host=ip, port=port, username=tempUser, password=tempPass, fast_cli=False)
#conn2rtr = ConnectHandler(device_type=deviceType, host=ip, port=port, username=tempUser, password=tempPass, fast_cli=False, session_log=debug) #, log_level="DEBUG")
if self.connInfo['sshDebug'] is True:
debug = self.logsDirectory + "debug.debug"
conn2rtr = ConnLogOnly(device_type=deviceType, host=ip, port=port, username=tempUser, password=tempPass, fast_cli=False, log_file=debug, log_level="DEBUG",log_format='[%(levelname)s] %(name)s: [%(threadName)s] %(message)s')
else:
conn2rtr = ConnLogOnly(device_type=deviceType, host=ip, port=port, username=tempUser, password=tempPass, fast_cli=False)
aluLogged = True
aluLogReason = "LoggedOk"
aluLogUser = tempUser
Expand Down Expand Up @@ -1935,6 +1940,28 @@ def checkCredentials(dictParam):

return dictParam

def enableLogging(dictParam):

## Netmiko Debug
if dictParam['sshDebug'] is True:

debugFileName = dictParam['logsDirectory'] + 'debug.log'

logger = logging.getLogger("netmiko")
logger.setLevel('DEBUG')

handler = logging.FileHandler(debugFileName)
handler.setLevel(logging.DEBUG)
handler.setFormatter(logging.Formatter('[%(levelname)s] %(name)s: [%(threadName)s] %(message)s'))

logger.addHandler(handler)

#log_formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s [%(threadName)s] ") # I am printing thread id here
#logging.basicConfig(filename=debugFileName, level=logging.DEBUG)


return None

def fncRun(dictParam):
"""[summary]
Expand All @@ -1952,18 +1979,16 @@ def fncRun(dictParam):
# Generar threads
threads_list = ThreadPool(dictParam['progNumThreads'])

## Netmiko Debug
if dictParam['sshDebug'] is True:
logging.basicConfig(filename='debug.log', level=logging.DEBUG)
logger = logging.getLogger("netmiko")

################
# Running...
if dictParam['outputJob'] == 2:

# logInfo
dictParam = createLogFolder(dictParam)

# debug
enableLogging(dictParam)

for i, IPconnect in enumerate(listOfRouters):

routerInfo = dictParam['inventory'][IPconnect]
Expand Down Expand Up @@ -1996,6 +2021,9 @@ def fncRun(dictParam):
dictParam = createLogFolder(dictParam)
listOfRouters = list(dictParam['inventory'].keys())

# debug
enableLogging(dictParam)

for i, IPconnect in enumerate(listOfRouters):

routerInfo = dictParam['inventory'][IPconnect]
Expand Down

0 comments on commit a360a90

Please sign in to comment.