All Projects → lordmauve → Chopsticks

lordmauve / Chopsticks

Licence: apache-2.0
Chopsticks is an orchestration library: it lets you execute Python code on remote hosts over SSH.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Chopsticks

Bolt
Bolt is an open source orchestration tool that automates the manual work it takes to maintain your infrastructure on an as-needed basis or as part of a greater orchestration workflow. It can be installed on your local workstation and connects directly to remote nodes with SSH or WinRM, so you are not required to install any agent software.
Stars: ✭ 380 (+151.66%)
Mutual labels:  ssh, orchestration
re-mote
Re-mote operations using SSH and Re-gent
Stars: ✭ 61 (-59.6%)
Mutual labels:  ssh, orchestration
Sshtunnel
🚇 Ultra simple SSH tunnelling for Go programs.
Stars: ✭ 135 (-10.6%)
Mutual labels:  ssh
Cedarkey
$2 hardware SSH keys storage
Stars: ✭ 148 (-1.99%)
Mutual labels:  ssh
Gossh
gossh is an extremely concise ssh tool which developed by go language. It has only a binary program without any dependencies and is really ready to use out of the box. gossh is used Used to manage of linux (like unix) machines: including remote execution of commands and push and pull files, and support stand-alone and batch modes.
Stars: ✭ 142 (-5.96%)
Mutual labels:  ssh
Saga Orchestration Serverless
An orchestration-based saga implementation reference in a serverless architecture
Stars: ✭ 136 (-9.93%)
Mutual labels:  orchestration
Docker X11 Bridge
Simple Xpra X11 bridge to enable GUI with any docker image
Stars: ✭ 143 (-5.3%)
Mutual labels:  ssh
Adams
UNIX system administration in Common Lisp
Stars: ✭ 135 (-10.6%)
Mutual labels:  ssh
Corkscrew
Corkscrew is a tool for tunneling SSH through HTTP proxies.
Stars: ✭ 149 (-1.32%)
Mutual labels:  ssh
Ssm Sh
Experiment to use SSM RunCommand instead of SSH
Stars: ✭ 140 (-7.28%)
Mutual labels:  ssh
Core
Eru, a simple, stateless, flexible, production-ready orchestrator designed to easily integrate into existing workflows. Can run any virtualization things in long or short time.
Stars: ✭ 147 (-2.65%)
Mutual labels:  orchestration
Dos ssh
Use BIOS ram hacks to make a SSH server out of any INT 10 13h app (MS-DOS is one of those)
Stars: ✭ 139 (-7.95%)
Mutual labels:  ssh
Cli
🧰 A zero trust swiss army knife for working with X509, OAuth, JWT, OATH OTP, etc.
Stars: ✭ 2,151 (+1324.5%)
Mutual labels:  ssh
Wordmove
Multi-stage command line deploy/mirroring and task runner for Wordpress
Stars: ✭ 1,791 (+1086.09%)
Mutual labels:  ssh
Laravel Ssh Tunnel
Easy creation & maintenance of an SSH Tunnel for Laravel/Lumen
Stars: ✭ 134 (-11.26%)
Mutual labels:  ssh
Swiftsh
A Swift SSH framework that wraps libssh2.
Stars: ✭ 148 (-1.99%)
Mutual labels:  ssh
Generate Ssh Configs
Automatically generate ssh config files for your cloud servers
Stars: ✭ 136 (-9.93%)
Mutual labels:  ssh
Coco
Jumpserver ssh/ws server
Stars: ✭ 139 (-7.95%)
Mutual labels:  ssh
Wolfssh
wolfSSH is a small, fast, portable SSH implementation, including support for SCP and SFTP.
Stars: ✭ 142 (-5.96%)
Mutual labels:  ssh
Flightplan
Run sequences of shell commands against local and remote hosts.
Stars: ✭ 1,804 (+1094.7%)
Mutual labels:  ssh

Chopsticks

.. image:: https://badges.gitter.im/chopsticks-chat/Lobby.svg :alt: Join the chat at https://gitter.im/chopsticks-chat/Lobby :target: https://gitter.im/chopsticks-chat/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

Chopsticks is an orchestration library: it lets you manage and configure remote hosts over SSH.

Naturally this is agentless and nothing needs to be installed on the remote host except Python and an SSH agent.

It also has support for executing code in Docker containers.

It's perhaps best compared to Ansible or Fabric, but has some clever transport magic which means it's very easy to develop with: you just write Python functions that can be called from the orchestration host. No invoking bash commands (eg. Fabric) or writing self-contained scripts with constrained input and output formats (eg. Ansible).

One might also draw a comparison with Python's built-in multiprocessing library, but instead of calling code in subprocesses on the same host, the code may be run on remote hosts.

Example

With chopsticks you can simply import functions and hand them to the remote host to be executed.

First stand up an SSH Tunnel:

.. code:: python

from chopsticks.tunnel import Tunnel
tun = Tunnel('troy.example.com')

Then you can pass a function, to be called on the remote host:

.. code:: python

import time
print('Time on %s:' % tun.host, tun.call(time.time))

You can use any pure-Python function in the current codebase, meaning you can create your own libraries of orchestration functions to call on remote hosts (as well as functions that call out to remote hosts using Chopsticks).

Tunnel provides support for executing on a single host; there is also a Group that can execute a callable on a number of hosts in parallel:

.. code:: python

from chopsticks.group import Group

group = Group([
    'web1.example.com',
    'web2.example.com',
    'web3.example.com',
])
for host, addr in group.call(ip).successful():
    print('%s ip:' % host, addr)

Subclasses of tunnels allow connecting using streams other than SSH, such as using sudo, or to fresh Docker containers for sandboxing:

.. code:: python

from chopsticks.tunnel import Docker
from chopsticks.group import Group
from chopsticks.facts import python_version

group = Group([
    Docker('worker-1', image='python:3.4'),
    Docker('worker-2', image='python:3.5'),
    Docker('worker-3', image='python:3.6'),
])

for host, python_version in group.call(python_version).items():
    print('%s Python version:' % host, python_version)

Tunnels and Groups connect lazily (or you can connect them proactively by calling connect()). They are also usable as context managers:

.. code:: python

# Explictly connect and disconnect
group.connect()
group.call(time.time)
group.close()

# Reconnect and disconnect as context manager
with group:
    group.call(time.time)

# Implicit reconnect
group.call(time.time)

# Disconnect when destroyed
del group

Naturally, any remote state (imports, globals, etc) is lost when the Tunnel/Group is closed.

Installation

Chopsticks can be used directly from a clone of the repo; or installed with pip:

.. code:: bash

$ pip install chopsticks

API

See the full documentation__ on Read The Docs.

.. __: https://chopsticks.readthedocs.io/

Python 2/3

Chopsticks supports both Python 2 and Python 3.

Because Chopsticks takes the view that agents run out of the same codebase as the controller, agents will attempt to use a similar Python interpreter to the one for the controller process:

  • /usr/bin/python2 if the controller process is (any) Python 2.
  • /usr/bin/python3 if the controller process is (any) Python 3.

How it works

The SSH tunnel invokes the python binary on the remote host, and feeds it a bootstrap script via stdin.

Once bootstrapped, the remote "agent" sets up bi-directional communication over the stdin/stdout of the tunnel. This communication is used (currently) for two purposes:

  • An RPC system to invoke arbitrary callables within the remote agent and pass the returned values back to the controller.
  • A PEP-302 import hook system, allowing the remote agent to import pure-Python code from the controller (NB. the controller can only serve Python modules that live within the filesystem - import hooks such as zipimport/compressed eggs are not currently supported).

stderr is echoed to the controlling console, prefixed with a hostname to identify which Tunnel it issued from. This can therefore be used to feed debugging information back to the orchestration host.

License

Apache License 2.0__

.. __: http://www.apache.org/licenses/LICENSE-2.0

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].