Viper is a handy tool for easily running infrastructure management tasks and commands.
Project description
Viper Infrastructure Commander
Viper is a handy tool for easily running infrastructure management tasks and commands.
Installation
pip install -U viper-infra-commander
Viper CLI Examples
Initialize current workspace (creates a viperdb.sqlite3
file)
viper init
# or remove or overwrite existing data with "-f" / "--force"
viper init -f
Load hosts from file
viper hosts:from-file tests/data/hosts.csv --indent 4
# or with a custom loader
viper hosts:from-file tests/data/hosts.json --loader viper.demo.loaders.json --indent 4
Load hosts from a Python function
viper hosts viper.demo.hosts.group1 --indent 4
Count the number of hosts
viper hosts viper.demo.hosts.group1 | viper hosts:count
Sort the hosts by custom logic
viper hosts viper.demo.hosts.group1 | viper hosts:sort --key viper.demo.sort.by_ip -i 4
Pipe the hosts to a custom handler that formats the hosts to CSV
viper hosts viper.demo.hosts.group1 | viper hosts:pipe viper.demo.handlers.hosts_to_csv
Let's save the hosts
viper hosts viper.demo.hosts.group1 > /tmp/hosts.json
Filter hosts
cat /tmp/hosts.json | viper hosts:filter viper.demo.filters.ip_is 8.8.8.8 --indent 4
Assign tasks to the given hosts
cat /tmp/hosts.json | viper hosts:task viper.demo.tasks.ping --indent 4
Run the assigned tasks
cat /tmp/hosts.json | viper hosts:task viper.demo.tasks.ping | viper runners:run --indent 4
# or use a shortcut
cat /tmp/hosts.json | viper hosts:run-task viper.demo.tasks.ping --indent 4
Run tasks in parallel using multiple workers
cat /tmp/hosts.json | viper hosts:run-task viper.demo.tasks.ping --max-workers 50 --indent 4
Get the past results from DB
viper results
Or get the past results by hosts
cat /tmp/hosts.json | viper hosts:results --indent 4 --debug
Or get the past results by task
viper task viper.demo.tasks.ping | viper results:by-task -i 4
# or
viper task viper.demo.tasks.ping | viper task:results -i 4
Let's save the result
viper task viper.demo.tasks.ping | viper task:results > /tmp/results.json
Now filter the results by their status
# success
cat /tmp/results.json | viper results:filter viper.demo.filters.result_ok -i 4
# failed
cat /tmp/results.json | viper results:filter viper.demo.filters.result_errored -i 4
Pipe the results to a custom handler
# print the status to terminal
cat /tmp/results.json | viper results:pipe viper.demo.handlers.print_status
# export the results to a csv file
cat /tmp/results.json | viper results:pipe viper.demo.handlers.export_csv /tmp/results.csv
Let's do that again in one go
viper hosts viper.demo.hosts.group1 | viper hosts:run-task viper.demo.tasks.ping | viper results:pipe viper.demo.handlers.export_csv /tmp/results.csv
Viper CLI Reference
usage: viper [-h] [--version] [--debug]
{init,task:from-func,task,task:results,hosts:from-file,hosts:from-func,hosts,hosts:filter,hosts:count,hosts:sort,hosts:pipe,hosts:task,hosts:run-task,hosts:results,runners:filter,runners:count,runners:sort,runners:pipe,runners:run,runners:hosts,results:from-history,results,results:filter,results:count,results:sort,results:pipe,results:hosts,results:by-task}
...
Viper CLI v0.13.0
positional arguments:
{init,task:from-func,task,task:results,hosts:from-file,hosts:from-func,hosts,hosts:filter,hosts:count,hosts:sort,hosts:pipe,hosts:task,hosts:run-task,hosts:results,runners:filter,runners:count,runners:sort,runners:pipe,runners:run,runners:hosts,results:from-history,results,results:filter,results:count,results:sort,results:pipe,results:hosts,results:by-task}
init initialize the current workspace
task:from-func [task:from-func > Task] get the task from a Python
function location
task alias of 'task:from-func'
task:results [Task > task:results > Results] get the past results
of given task
hosts:from-file [hosts:from-file > Hosts] get a group of hosts from a
file
hosts:from-func [hosts:from-func > Hosts] get a group of hosts from a
Python function location
hosts alias of 'hosts:from-func'
hosts:filter [Hosts > hosts:filter > Hosts] filter hosts by a given
function
hosts:count [Hosts > hosts:count > int] count the number of hosts
hosts:sort [Hosts > hosts:sort > Hosts] sort the hosts
hosts:pipe [Hosts > hosts:pipe > ?] pipe the hosts to the given
handler
hosts:task [Hosts > hosts:task > Runners] assign a task to each
host
hosts:run-task [Hosts > hosts:run-task > Results] assign a task to
each host and run
hosts:results [Hosts > hosts:results > Results] get the past results
of the hosts
runners:filter [Runners > runners:filter > Runners] filter runners by
a given function
runners:count [Runners > runners:count > int] count the number of
runners
runners:sort [Runners > runners:sort > Runners] sort the runners
runners:pipe [Runners > runners:pipe > ?] pipe the runners to the
given handler
runners:run [Runners > runners:run > Results] run the assigned
tasks
runners:hosts [Runners > runners:hosts > Hosts] get the hosts from
the runners
results:from-history
[results:from-history > Results] get the past results
from database
results alias of 'results:from-history'
results:filter [Results > results:filter > Results] filter results by
a given handler
results:count [Results > results:count > int] count the number of
results
results:sort [Results > results:sort > Results] sort the results
results:pipe [Results > results:pipe > ?] pipe the results to the
given handler
results:hosts [Results > results:hosts > Hosts] get the hosts from
the results
results:by-task [Task > results:by-task > Results] get the past
results of given task
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
--debug show traceback information when an exception is raised
Contributing to Viper
See the contribution guidelines.
NOTE: This file is generated by running "make readme"
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.13.0.tar.gz
.
File metadata
- Download URL: viper-infra-commander-0.13.0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de1fb99bb6603897f66454367273618857ad54863bc15d527a58e0fa4a519aee |
|
MD5 | b5e544f6930c0933041212ae4b696c5f |
|
BLAKE2b-256 | 1ca60be64909fd92c8c16ebc1acf94348badb6620adf61c94f29823637774a5a |
File details
Details for the file viper_infra_commander-0.13.0-py3-none-any.whl
.
File metadata
- Download URL: viper_infra_commander-0.13.0-py3-none-any.whl
- Upload date:
- Size: 22.0 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/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08669cfa85ad08e8e87b6cea7003f54173d7994a1254881dfac35ad50d95ec65 |
|
MD5 | f1bd0e69b53e000652ac061156bdad71 |
|
BLAKE2b-256 | 9654e9b7f928f8dc3fcc8ede7a40b113be9da2a213aa10ef1867760e7bf03dc2 |