Giter VIP home page Giter VIP logo

python-rc's Introduction

python-rc

PyPI version

Python remote control library for programmatically control remote machines of mutliple cloud providers. Currently support gcloud, azure and digitalocean.

Usage

python-rc consists of python-rc lib and python-rc cli.

python-rc cli

rc <group name> command ...: execute command non interactively in group of machines
rc <group name>/name_pattern1,... command ...: execute command non interactively in group of machines, but only subset that match pattern 
rc <group name> @file: execute content of local file in group of machines
rc tmux <group name>: launch a tmux that ssh to every instance in group of machines, input to one machine will be replicate to the group
rc edit <group name>: create or edit machines in group
rc cat <group name>: show machines in group
rc ls: show defined groups
rc rm <group name>: delete group definition (does not delete machines)
rc rsync: parallel rsync
rc ssh-config: generate ~/.ssh/config that can be used with ssh machine_name, scp, rsync, mosh, etc.

In python-rc tmux, you can use C-b a to toggle input to all machines and input into single machine.

python-rc lib

Import one of provider module: gcloud, digitalocean and azure to get or create a machine. Use machine methods to execute shell commands, execute background task, edit file, etc on the machine. Example:

from rc import gcloud
m = gcloud.get('instance1')
# run a single line command
p = m.run('ls')
print(p.stdout)

# run a multiline command
m.bash('''
cd workspace/proj
make -j 4
''')

# run a muliline commands as root
m.sudo('''
apt update
apt install -y jq
''')

# edit a file, as user `ubuntu`:
m.edit('~/a.txt', '''
file line1
file line2
''', user='ubuntu')

# run a server process in background
m.run_bg('''
cd workspace/someserver
npm i
npm run
''')

# run a python snippet on a server
p = m.python('''
import json
j = json.load(open('foo.json'))
print(j['key'])
''')

# Useful utility example:
# parallel run tasks on each machine
from rc import pmap
def task(machine, script_path):
    machine.bootup()
    machine.upload(f'~/local/path/{script_path}', f'~/remote/path/script_path}')
    machine.run(f'bash remote/path/{script_path}')

pmap(lambda i: task(machines[i], tasks[i]), range(n))

Documentation

TODO. See rc/test/ for example usages for now

Test

To run gcloud part test, gcloud cli needs to be installed and logged in.

pipenv sync -d
pipenv run pytest -s

python-rc's People

Contributors

ailisp avatar mfornet avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

mfornet

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.