Giter Site home page Giter Site logo

netmiko-scp-multi-thread-upload's Introduction

published

netmiko-scp-multi-thread-upload

This script leverages Netmiko's features to securely copy (SCP) a single file to a remote network device. It also checks if the file exists already on the remote device and compares the checksums: if the files are identical, it does not upload it. To this, I added parallelism: to make copies in parallel towards several remote devices. And also to have the remote hosts and OS defined in a CSV file, to avoid having to edit the Python script itself. I also added a check if the file to copy is present locally.

Use Case Description

If you have a large number of network devices to which you need to send a file, such as a new operating system or similar, doing it manually can be very time consuming. This script takes care of everything and does the upload in parallel to save time.

Supported devices are: Cisco IOS*/IOS-XE/IOS-XR/NX-OS, Arista EOS, and Juniper JunOS.

Remark: on Cisco IOS, only ascii files are supported. Modern Cisco OS (XE, XR, NXOS) are not affected.

Installation

Requirements: All you need is Python and pip. Then, with pip we will install Netmiko and dependencies.

Installation:

$ git clone https://github.com/jerome-t/netmiko-scp-multi-thread-upload
$ sudo pip install -r requirements.txt

Configuration

Update the hosts.csv file with the list of your network hosts and vendor type.

Vendor types are: cisco_ios (valid for IOS/IOS-XE/IOS-XR), cisco_nxos, arista_eos, juniper_junos

Example of hosts.csv:

host01.example.com,cisco_ios
host02.example.com,cisco_nxos
host03.example.com,arista_eos
host04.example.com,juniper_junos

The file system used for each device type is the one defined by default in Netmiko:

Cisco IOS/IOS-XE/IOS-XR        Auto detects the file-system
Cisco NX-OS                    bootflash:
Arista EOS                     /mnt/flash
Juniper Junos                  /var/tmp

Please refer to the Netmiko documentation here for more information: https://pynet.twb-tech.com/blog/automation/netmiko-scp.html

Usage

Add the filename as an argument to the script.

The script will also check if the file exists, then read the list of hosts, vendor type and ask you for your credentials.

It will ask you for a confirmation before starting the upload.

To save time and bandwidth, if the file already exists it will be not overwritten.

Usage: scp-multi-upload.py filename

positional arguments: filename The file to upload

Example where the file does not exists on the first host, but exists on the second:

$ ./scp-multi-upload.py testfile.txt
================================================================================
Please, confirm the upload of testfile.txt on: 
c.example.com
d.example.com
e.example.com
f.example.com
Proceed? [n]|y: y
--------------------------------------------------------------------------------
Please insert your username: admin
And your password
Password: 
--------------------------------------------------------------------------------
Upload on: c.example.com
Upload on: d.example.com
Upload on: e.example.com
Upload on: f.example.com
================================================================================
Results for c.example.com:
File exists already:  True
File transferred:  True
MD5 verified : True
================================================================================
Results for f.example.com:
File exists already:  True
File transferred:  True
MD5 verified : True
================================================================================
Results for e.example.com:
File exists already:  True
File transferred:  True
MD5 verified : True
================================================================================
Results for d.example.com:
File exists already:  True
File transferred:  True
MD5 verified : True
================================================================================
Uploads completed in 3.351285219192505 seconds.
================================================================================

How to test the software & DevNet Sandbox

You can test to transfer a file to a DevNet Sandbox For example, you can change the file hosts.csv like below, to test with the CRS1000v (IOX-XE) always on sandbox:

sandbox-iosxe-latest-1.cisco.com,cisco_ios

For the credentials, please check the Cisco DevNet Sandbox and search for Always On Sandbox in the Sandbox catalog.

Known issues

The 'file exists already' return value is always True, even if the file does not exists on the remote device. The upload is done anyway, this is only an output error, but the script is working at 100%

This script uses multi-threads, it may be improved by using multi-processing. The max. threads are 8 for now, I have to test what is the optimal number of threads depending on the devices, computer, network bandwidth and latency, etc.

Getting help and Getting involved

Please contact me on Twitter or open an Issue/P.R.

Author(s)

This project was written and is maintained by the following individuals:

netmiko-scp-multi-thread-upload's People

Contributors

giuliobosco avatar jerome-t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

netmiko-scp-multi-thread-upload's Issues

Problems with uploads

Hello -- I'm running a script to upload a TGZ image for Juniper EX3400 devices, the script runs and it says that it uploaded files but when I log into the device the files are missing from /var/tmp

Please, confirm the upload of junos-arm-32-20.4R3-S3.4.tgz on: 
10.100.1.1
10.100.1.2
10.100.1.3
10.100.1.4
10.100.1.5
10.100.1.6
10.100.1.7
10.100.1.8
10.100.1.9
10.100.1.10
10.100.1.11
10.100.1.12
Proceed? [n]|y: y
--------------------------------------------------------------------------------
Please insert your username: root
And your password
Password: 
--------------------------------------------------------------------------------
Upload on: 10.100.1.1
Upload on: 10.100.1.2
Upload on: 10.100.1.3
Upload on: 10.100.1.4
Upload on: 10.100.1.5
Upload on: 10.100.1.6
Upload on: 10.100.1.7
Upload on: 10.100.1.8
Upload on: 10.100.1.1
Upload on: 10.100.1.6
Upload on: 10.100.1.4
Upload on: 10.100.1.7
================================================================================
Uploads completed in 7.7323243618011475 seconds.

Transferring IOS XE Image to multiple Access Switches

To begin with, thanks a lot for this handy program. It's really helpful and saves a lot of time.

I just had one issue. I am trying to transfer cat9k_lite_iosxe.17.03.03.SPA.bin (about 480MBs) to three C9200L-48P-4G access switches, but I got an error socket.timeout(). However, I was able to find the IOS image on the three switches flash and the images were verified!

I added socket_timeout=200.0 to this line before running to prevent any timeouts but I still get one!

Any reason for why this is happening?

Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.