Skip to content

Commit be605bc

Browse files
author
Jerome Tissieres
committed
Replaced Netmiko ConnectHandler with ConnLogOnly
1 parent ec93496 commit be605bc

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
netmiko>=3.3.0
1+
netmiko>=4.1.1

scp-multi-upload.py

100755100644
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import sys
77
from time import time
88
from concurrent.futures import ProcessPoolExecutor, wait
9-
from netmiko import ConnectHandler, file_transfer
10-
from netmiko.ssh_exception import NetMikoAuthenticationException, NetMikoTimeoutException
11-
from paramiko.ssh_exception import AuthenticationException
9+
from netmiko import ConnLogOnly, file_transfer
1210

1311
# --- Define the threads
1412
MAX_THREADS = 8
@@ -47,9 +45,15 @@ def confirm(prompt=None, resp=False):
4745
# --- Upload Netmiko function
4846
def upload_nemiko(net_device):
4947
print("Upload on:", HOST)
50-
# Create the Netmiko SSH connection
51-
try:
52-
ssh_conn = ConnectHandler(**net_device)
48+
49+
# Create the Netmiko SSH connection
50+
ssh_conn = ConnLogOnly(**net_device)
51+
52+
# Test access, skip if failed
53+
if ssh_conn is None:
54+
print(HOST+ ": Logging in failed... skipping")
55+
print(40*"-")
56+
else:
5357
transfer_dict = {}
5458
transfer_dict = file_transfer(ssh_conn,
5559
source_file=SOURCE_FILE,
@@ -60,16 +64,6 @@ def upload_nemiko(net_device):
6064
print('File exists already: ',transfer_dict['file_exists'])
6165
print('File transferred: ',transfer_dict['file_transferred'])
6266
print('MD5 verified :',transfer_dict['file_verified'])
63-
except NetMikoTimeoutException:
64-
print(80*"=")
65-
print('Results for', HOST+':')
66-
print('Skipped: SSH Timed out')
67-
#continue
68-
except (AuthenticationException, NetMikoAuthenticationException):
69-
print(80*"=")
70-
print('Results for', HOST+':')
71-
print('Skipped: Authentication failed')
72-
#continue
7367

7468
# --- Init argparse
7569
parser = ArgumentParser()

0 commit comments

Comments
 (0)