All Projects → fgimian → multissh

fgimian / multissh

Licence: MIT license
A multiprocessed library written in Python and utilising Paramiko.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to multissh

Imminent
A composable Futures library for Clojure
Stars: ✭ 88 (+158.82%)
Mutual labels:  parallelism
Plasma
Plasma Programming Language
Stars: ✭ 133 (+291.18%)
Mutual labels:  parallelism
Util
A collection of useful utility functions
Stars: ✭ 201 (+491.18%)
Mutual labels:  parallelism
Composite
A component-based OS
Stars: ✭ 113 (+232.35%)
Mutual labels:  parallelism
Hpx
The C++ Standard Library for Parallelism and Concurrency
Stars: ✭ 1,805 (+5208.82%)
Mutual labels:  parallelism
Svelto.tasks
Svelto Tasks - C# promises compliant multi-threaded tasks runner
Stars: ✭ 159 (+367.65%)
Mutual labels:  parallelism
Cekirdekler
Multi-device OpenCL kernel load balancer and pipeliner API for C#. Uses shared-distributed memory model to keep GPUs updated fast while using same kernel on all devices(for simplicity).
Stars: ✭ 76 (+123.53%)
Mutual labels:  parallelism
java-multithread
Códigos feitos para o curso de Multithreading com Java, no canal RinaldoDev do YouTube.
Stars: ✭ 24 (-29.41%)
Mutual labels:  parallelism
Floyd
The Floyd programming language
Stars: ✭ 133 (+291.18%)
Mutual labels:  parallelism
Threadbox
Recursive Worker Threads in NodeJS
Stars: ✭ 181 (+432.35%)
Mutual labels:  parallelism
Jlsca
Side-channel toolkit in Julia
Stars: ✭ 114 (+235.29%)
Mutual labels:  parallelism
Agency
Execution primitives for C++
Stars: ✭ 127 (+273.53%)
Mutual labels:  parallelism
Awesome Machine Learning In Compilers
Must read research papers and links to tools and datasets that are related to using machine learning for compilers and systems optimisation
Stars: ✭ 168 (+394.12%)
Mutual labels:  parallelism
Chocolate
A fully decentralized hyperparameter optimization framework
Stars: ✭ 112 (+229.41%)
Mutual labels:  parallelism
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+467.65%)
Mutual labels:  parallelism
Paramgmt
A parallel SSH-based remote machine management system
Stars: ✭ 80 (+135.29%)
Mutual labels:  parallelism
Chymyst Core
Declarative concurrency in Scala - The implementation of the chemical machine
Stars: ✭ 142 (+317.65%)
Mutual labels:  parallelism
open-ops
Open Optimizing Parallelizing System
Stars: ✭ 21 (-38.24%)
Mutual labels:  parallelism
parallelizer
Simplifies the parallelization of function calls.
Stars: ✭ 62 (+82.35%)
Mutual labels:  parallelism
Pht
A new threading extension for PHP
Stars: ✭ 175 (+414.71%)
Mutual labels:  parallelism

Multi-SSH

License

Multi-SSH Logo

Artwork courtesy of Open Clip Art Library

Introduction

Multi-SSH is my take on multiprocessing and Paramiko. I have huge respect and admiration for projects such as Fabric and Ansible which were a great reference while I was developing this library.

So the obvious question, why another library to do the same thing? Heres where Multi-SSH stands apart:

  • This library is completely abstract and made to run on Cisco IOS, Unix and any other device which supports SSH. There are no Unix-specific commands or interactions used.
  • The library allows integration with my paramiko-expect library, allowing complex interactions with servers.
  • The library is made to be integrated with scripts and doesn't rely on config files for storing server names and other information. The user is requested to perform that task themselves via JSON or similar.
  • The library implements tailing of a file across multiple servers in one session.

Quick Start

To install Multi-SSH, simply run the following at your prompt:

pip install git+https://github.com/fgimian/multissh.git

Here's how we can use the library (please see multissh-demo.py for the complete code):

# Create a multi-SSH runner.  Processes sets the number of processes that
# can run at the same time.
runner = MultiSSHRunner(processes=2)

# We must add jobs one at a time (allows for more flexibility)
for device in devices:
    runner.add_ssh_job(hostname=device, connect_timeout=connect_timeout,
                       username=username, password=password, command=command)

# Run the commands, returned is a list of tuples.  Tuples are as follows:
# (return_code, stdout, stderr)
outputs = runner.run()

# Process the output
for device, output in zip(devices, outputs):
    if output:
        return_code, stdout, stderr = output

    # Check the return code was 0 (successful) and something was returned in stdout
    if output and stdout and return_code == 0:
        print device, stdout,
    # If output has been set and we arrive here, then the return code was non-zero or stdout was empty
    elif output:
        print device, 'Command did not run successfully'
    # Otherwise, we didn't connect successfully
    else:
        print device, "Couldn't connect to this server"

As well as running basic commands, Multi-SSH also supports custom interactions. A function (such as that shown below) can be written and passed into the add_ssh_job function via the interaction variable (see multissh-interact-demo.py for the complete code):

def server_interaction(client, hostname):
    """The server interaction function"""
    prompt = 'fots@fotsies-ubuntu-testlab:~\$ '

    # Start a client interaction using the paramiko-expect class
    interact = paramikoe.SSHClientInteraction(client, timeout=10, display=False)
    interact.expect(prompt)

    # Run the first command and capture the cleaned output.
    interact.send('cat /etc/*release')
    interact.expect(prompt)
    output1 = interact.current_output_clean

    # Now let's do the same for the uname command
    interact.send('uname -a')
    interact.expect(prompt)
    output2 = interact.current_output_clean

    # Send the exit command and expect EOF (a closed session)
    interact.send('exit')
    interact.expect()

    # Return a tuple of the results
    return output1, output2

Similar to that above, you may use the special tail function to tail a log on multiple servers in the one session. Gone are the days of logging into 10 web servers to tail the apache access logs during a fault! Here's how the interact function looks (full code listing is in multissh-tail-demo.py):

def tail_authlog(client, hostname):
    """The tail interaction function"""
    prompt = 'fots@fotsies-ubuntu-testlab:~\$ '
    line_prefix = hostname + ': '

    # Start a client interaction using the paramiko-expect class
    interact = paramikoe.SSHClientInteraction(client, display=False)
    interact.expect(prompt)

    # Begin tailing the file
    interact.send('tail -f /var/log/auth.log')
    interact.tail(line_prefix=line_prefix)

License

Multi-SSH is released under the MIT license. Please see the LICENSE file for more details.

TODO

  • Piping scripts into other commands and then interrupting them with Ctrl+C causes an error message (shown below)> This only occurs when you attempt to print text inside the KeyboardInterrupt exception:

    close failed in file object destructor:
    sys.excepthook is missing
    lost sys.stderr
    
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].