python-rc
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
Metadata
Release files for python-rc 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python-rc-0.4.1.tar.gz | 18.1 kB | Without provenance | Details for python-rc-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_rc-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for python_rc-0.4.1-py3-none-any.whl |
Total release size: 43.7 kB
Release files / python-rc-0.4.1.tar.gz
| Download URL | python-rc-0.4.1.tar.gz |
|---|---|
| Size | 18.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8953b37f76299bd00a46fcf8d2c427e0443486ec21db8817930fb9ab13cb16d
|
|
BLAKE2b-256 checksum How to use checksums |
3298a2de74efbab8a1b176077b04d46e84ece3f06b34d7395de58dfec3a2ef75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3
|
Release files / python_rc-0.4.1-py3-none-any.whl
| Download URL | python_rc-0.4.1-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6a47ba139edb4d508b9455c2db1aa96337f7ebde40269243f2816f1fe2fb6bf
|
|
BLAKE2b-256 checksum How to use checksums |
26a0107b421a3f58091cca2f63211b1e86fb94c037dba7d7510cd596ffa2e7e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3
|
Security for python-rc 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.