Skip to main content

Viper is a handy tool for easily running infrastructure management tasks and commands.

Project description

Viper Infrastructure Commander

PyPI version PyPI pyversions Build Status codecov Code style: black

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

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 task-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 task results of the hosts from DB

cat /tmp/hosts.json | viper hosts:task-results --indent 4 --debug

Or get the past task results by task

viper task viper.demo.tasks.ping | viper task-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 task-results:filter viper.demo.filters.result_ok -i 4

# failed
cat /tmp/results.json | viper task-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 task-results:pipe viper.demo.handlers.print_status

# export the results to a csv file
cat /tmp/results.json | viper task-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:rttp viper.demo.tasks.ping 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:run-task-then-pipe,hosts:rttp,hosts:task-results,task-runners:filter,task-runners:count,task-runners:sort,task-runners:pipe,task-runners:run,task-runners:hosts,task-results:filter,task-results:count,task-results:sort,task-results:pipe,task-results:hosts,task-results:by-task}
             ...

Viper CLI v0.2.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:run-task-then-pipe,hosts:rttp,hosts:task-results,task-runners:filter,task-runners:count,task-runners:sort,task-runners:pipe,task-runners:run,task-runners:hosts,task-results:filter,task-results:count,task-results:sort,task-results:pipe,task-results:hosts,task-results:by-task}
    init                initialize the current workspace
    task:from-func      [task:from-func FUNC > Task] get the task from a
                        Python function location
    task                alias of 'task:from-func'
    task:results        [Task > task:results > TaskResults] get the past task
                        results of given task
    hosts:from-file     [hosts:from-file FILE > Hosts] get a group of hosts
                        from a file
    hosts:from-func     [hosts:from-func FUNC > Hosts] get a group of hosts
                        from a Python function location
    hosts               alias of 'hosts:from-func'
    hosts:filter        [Hosts > hosts:filter FILTER *AGS > 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 HANDLER *ARGS > ?] pipe the hosts
                        to the given handler
    hosts:task          [Hosts > hosts:task TASK > TaskRunners] assign a task
                        to each host
    hosts:run-task      [Hosts > hosts:run-task > TaskRunners] assign a task
                        to each host and run
    hosts:run-task-then-pipe
                        [Hosts > hosts:run-task-then-pipe TASK HANDLER *ARGS >
                        ?] run the task on hosts and pipe the results to a
                        handler
    hosts:rttp          alias of 'hosts:run-task-then-pipe'
    hosts:task-results  [Hosts > hosts:task-results > TaskResults] get the
                        past task results of the hosts
    task-runners:filter
                        [TaskRunners > task-runners:filter FILTER *ARGS >
                        TaskRunners] filter task runners by a given function
    task-runners:count  [TaskRunners > task-runners:count > int] count the
                        number of task runners
    task-runners:sort   [TaskRunners > task-runners:sort > TaskRunners] sort
                        the task runners
    task-runners:pipe   [TaskRunners > task-runners:pipe HANDLER *ARGS > ?]
                        pipe the task runners to the given handler
    task-runners:run    [TaskRunners > task-runners:run > TaskResults] run the
                        assigned tasks
    task-runners:hosts  [TaskRunners > task-runners:hosts > Hosts] get the
                        hohsts from the task runners
    task-results:filter
                        [TaskResults > task-results:filter FILTER *ARGS >
                        TaskResults] filter task results by a given handler
    task-results:count  [TaskResults > task-results:count > int] count the
                        number of task results
    task-results:sort   [TaskResults > task-results:sort > TaskResults] sort
                        the task results
    task-results:pipe   [TaskResults > task-results:pipe HANDLER *ARGS> ?]
                        pipe the task results to the given handler
    task-results:hosts  [TaskResults > task-results:hosts > Hosts] get the
                        hosts from the task results
    task-results:by-task
                        [Task > task-results:by-task > TaskResults] get the
                        past task 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

viper-infra-commander-0.2.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

viper_infra_commander-0.2.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file viper-infra-commander-0.2.1.tar.gz.

File metadata

  • Download URL: viper-infra-commander-0.2.1.tar.gz
  • Upload date:
  • Size: 13.7 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

Hashes for viper-infra-commander-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8e51bb2b58f505b5a7dac72dcf43c1f61fa78314fb3820cc4322e76e33ae8f66
MD5 7ce4e75b67850415e58435d0e48515b3
BLAKE2b-256 20edf1c9d4f0d8e493bedb8e0566ff2e76ea627d8e5c59d37c8a121c714f8880

See more details on using hashes here.

File details

Details for the file viper_infra_commander-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: viper_infra_commander-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 15.1 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

Hashes for viper_infra_commander-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b1e2b5949f9218bcb9ffc857734266cc7eb9145742039d747670e15e5bd04947
MD5 4d2d4ae6c30dd536d1f53ce489891a3f
BLAKE2b-256 c772cf341b32fa4d9083ba8490ebb1f5da2e8b026b0a66fb90d5a1998c9d95bf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page