Git Product home page Git Product logo

cooperate's Introduction

Cooperate

cooperate is a shell command that execute commands in a cooperative manner, by distributing them to many nodes.

It requires Python >= 3.3 and asyncio.

For example:

cooperate --local -- echo FOO

Will execute the job "echo FOO" locally.

This one:

cooperate --ssh [email protected] -- echo FOO

Is barelly equivalent to:

ssh [email protected] echo FOO

You can declare as many nodes as you want. For example:

cooperate --local --ssh [email protected] --ssh [email protected] -- echo FOO

Is equivalent to:

echo FOO
ssh [email protected] echo FOO
ssh [email protected] echo FOO

You can also declare many jobs at once. For example:

cooperate --local --command "echo FOO" --command "echo BAR"

Is equivalent to:

echo FOO
echo BAR

Installation

pip install cooperate

Nodes

Commands can be distribued thru these kind of nodes:

  • --local execute locally
  • --ssh execute thru ssh
  • --docker execute in a local docker container
  • --lxc execute in a local lxc container

These options can be repeated as often as needed.

Modes

By default, it spawns every commands to every nodes.

The -m, --mode allow to configure the desired mode.

The all mode executes all commands in all nodes:

cooperate --local --ssh [email protected] --ssh [email protected] \
    --command="echo FOO" --command="echo BAR"

Is equivalent to:

echo FOO
echo BAR
ssh [email protected] echo FOO
ssh [email protected] echo BAR

The distribute mode share the commands out among all the nodes:

cooperate --local --ssh [email protected] --ssh [email protected] \
    --command="echo FOO" --command="echo BAR" --mode=distribute

Is equivalent to:

echo FOO
ssh [email protected] echo BAR

Concurrency

By default, it executes all jobs simultaneously.

The -b, --batch option allows to execute on only a specify number of jobs at a time. Both percentages and finite numbers are supported:

cooperate --local --concurrence 1 \
    --command="echo FOO" --command="echo BAR" --command="echo BAZ"

cooperate --local --concurrence 33% \
    --command="echo FOO" --command="echo BAR" --command="echo BAZ"

The concurrency system maintains a window of running jobs. When a job returns then it starts a remnant job and so on.

Feeding cooperate

Arguments can accept multiple input files for providing arguments, for example:

cat arguments.txt | cooperate
cooperate < arguments.txt
cooperate @arguments1.txt @arguments2.txt

These files must have a line per argument, like this:

--command echo $FOO
--local
--ssh server1
--ssh server2

Ouputing

cooperate will output to the stdout each result as they come in single YAML documents, with these keys

code

the return code

command

the executed command

error

error occured into cooperate, if any

node

the node name

stderr

stderr of the command, if any

stdout

stdout of the command, if any

cooperate's People

Contributors

johnnoone avatar

Watchers

 avatar  avatar

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.