Viper is a handy tool for easily running infrastructure management tasks and commands.
Project description
▄ ▄█ █ ▄▄ ▄███▄ █▄▄▄▄ ▄█ ▄ ▄████ █▄▄▄▄ ██ ▄█▄ ████▄ █▀▄▀█ █▀▄▀█ ██ ▄ ██▄ ▄███▄ █▄▄▄▄ █ ██ █ █ █▀ ▀ █ ▄▀ ██ █ █▀ ▀ █ ▄▀ █ █ █▀ ▀▄ █ █ █ █ █ █ █ █ █ █ █ █ █ █▀ ▀ █ ▄▀ █ █ ██ █▀▀▀ ██▄▄ █▀▀▌ ██ ██ █ █▀▀ █▀▀▌ █▄▄█ █ ▀ █ █ █ ▄ █ █ ▄ █ █▄▄█ ██ █ █ █ ██▄▄ █▀▀▌ █ █ ▐█ █ █▄ ▄▀ █ █ ▐█ █ █ █ █ █ █ █ █ █▄ ▄▀ ▀████ █ █ █ █ █ █ █ █ █ █ █ █▄ ▄▀ █ █ █ █ ▐ █ ▀███▀ █ ▐ █ █ █ █ █ █ ▀███▀ █ █ █ █ █ █ ███▀ ▀███▀ █ █▐ ▀ ▀ █ ██ ▀ ▀ █ ▀ ▀ █ █ ██ ▀ ▐ ▀ ▀
Viper is a handy tool for easily running infrastructure management tasks and commands.
Getting Started
Installation
pip install -U viper-infra-commander
# Or install with batteries included
pip install -U "viper-infra-commander[batteries]"
Initialization
# (Optional) enable tab completion
eval "$(viper autocomplete $(basename $SHELL))"
# See the help menu
viper -h
# Initialize SQLite DB
viper init -f
Viper In Action (Basic Mode)
Define a set of hosts in csv format (json and yml are also supported)
cat > hosts.csv << EOF
ip,hostname,login_name,identity_file
192.168.0.11,host11,root,/root/.ssh/id_rsa.pub
192.168.0.12,host12,root,/root/.ssh/id_rsa.pub
192.168.0.13,host13,root,/root/.ssh/id_rsa.pub
192.168.0.14,host14,root,/root/.ssh/id_rsa.pub
192.168.0.15,host15,root,/root/.ssh/id_rsa.pub
EOF
Define a task
cat > task.py << EOF
from viper import Task
def ping_command(host):
return "ping", "-c", "1", host.ip
def ping():
return Task(
name="Ping once",
command_factory=ping_command
)
EOF
Perform the following actions:
Run the task on the set of hosts in parallel with 5 workers,
filter only the results where the task failed,
re-run the task on them,
store the results in DB
viper hosts:from-file hosts.csv \
| viper hosts:run-task task.ping --max-worker 5 \
| viper results:where returncode IS_NOT 0 \
| viper results:re-run --indent 4
See the stdout of the final results from DB
viper results \
| viper results:final \
| viper results:format "{host.hostname}: {stdout}"
Export the results to a csv file
viper results --final \
| viper results:to-file results.csv --indent 4
Define a job using the Python API (CLI and Python API are almost similar)
cat > job.py << EOF
from viper import WhereConditions
from task import ping
def ping_and_export(hosts):
return (
hosts.task(ping())
.run(max_workers=5)
.final()
.to_file("results.csv")
)
EOF
Run the job using CLI
viper hosts:from-file hosts.csv \
| viper run job.ping_and_export \
| viper results:format "{host.hostname}: {stdout}"
Viperfile In Action (Advanced Mode)
Define a project in viperfile
cat > viperfile.py << EOF
from viper import Hosts, Task
from viper.project import Project, arg
foo = Project(prefix="foo")
@foo.hostgroup(args=[arg("-f", "--file", default="hosts.csv")])
def allhosts(args):
return Hosts.from_file(args.file)
def remote_exec_command(host, command):
return (
"ssh",
"-i",
host.identity_file,
"-l",
host.login_name,
"-p",
str(host.port),
"-o",
"StrictHostKeyChecking=no",
"-o",
"PubkeyAuthentication=yes",
host.ip,
command,
)
@foo.job(
args=[
arg("command", help="command to execute"),
arg("-w", "--workers", type=int, default=1),
]
)
def remote_exec(hosts, args):
return (
hosts.task(
Task(
name="Remote execute command",
command_factory=remote_exec_command,
timeout=5,
),
args.command,
)
.run(max_workers=args.workers)
.final()
)
EOF
See the auto generated custom commands
viper --help
Run the job
viper @foo:allhosts \
| viper @foo:remote_exec "uname -a" --workers 5 \
| viper results:to-file results.csv \
| viper results:format "{task.name} [{host.hostname}]: {returncode}: {stdout}"
Further Readings
API Docs with Examples ☞ https://viper-infrastructure-commander.readthedocs.io
Contributing To Viper
Contribution Guidelines ☞ https://github.com/sayanarijit/viper/blob/master/CONTRIBUTING.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file viper-infra-commander-0.28.2.tar.gz
.
File metadata
- Download URL: viper-infra-commander-0.28.2.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 802450c2b227c9915d26e34b7e8dee23a323fef567e6c198613193d4b4be9c56 |
|
MD5 | a7378be654b205027cccfa97a3054bb5 |
|
BLAKE2b-256 | bb35af060793d24afd20db1562aa3ef8580aab1fd991d1a84dd190755ccf103e |
File details
Details for the file viper_infra_commander-0.28.2-py3-none-any.whl
.
File metadata
- Download URL: viper_infra_commander-0.28.2-py3-none-any.whl
- Upload date:
- Size: 35.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae0278bce97f1fde4182431e5b455ed688a37872ef22a9b9d27b2fce9e57e9a |
|
MD5 | b6a8225797c254a450ce1ca99f376566 |
|
BLAKE2b-256 | 0d2afbc78dc73047a1e6d20735652ade562dee1d56f95e704eb9d200da124112 |