Skip to content

An concurrent ssh command executor, based on the concepts behind fabric.

Notifications You must be signed in to change notification settings

gnarlyman/sshleme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sshleme

Installation

pip install sshleme

Usage

hosts list

create a list of ips

10.1.1.1
10.2.2.2

create a tasks module

# tasks.py
from sshleme.lib import async_task

@async_task
async def uptime(client):
    result, error = await client.run('uptime')
    if error:
        print(client.output(error))
    else:
        print(client.output(result.stdout))

run the following

sshleme -r uptime hosts -f ~/path/to/iplist

csv rows

create a csv file

ipaddress,name
10.1.1.1,hostA
10.2.2.2,hostB

create a tasks module

# tasks.py
from sshleme.lib import async_task

@async_task
async def uptime(client):
    result, error = await client.run('uptime')
    if error:
        print(client.output(error, fields=['name']))
    else:
        print(client.output(result.stdout, fields=['name']))
sshleme -r uptime csv -f ~/path/to/csv -c ipaddress

Importing into another project

using sshleme as a module in project

# project.py
import asyncio
from sshleme.lib import ConcurrentExecutor, async_task

@async_task
async def get_uptime(client):
    command = 'uptime'
    result, error = await client.run(command)
    # return result and error to the executor
    return result, error

list_of_hosts = ['127.0.0.1', '127.0.0.2', '127.0.0.3']


loop = asyncio.get_event_loop()
executor = ConcurrentExecutor(concurrent=50)
loop.run_until_complete(
    executor.run_func_on_hosts(list_of_hosts, get_uptime)
)

# returns [tuple(results, error)]
print(executor.results)

About

An concurrent ssh command executor, based on the concepts behind fabric.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages