Skip to main content

Python library for Shell Operator

Project description

Shell Operator Python Framework

Simplifies writing shell-operator hooks in Python.

Install

pip install shell-operator

Sample hook

# hello.py
from shell_operator import hook

def main(ctx: hook.Context):
    # ... object = { "kind" : "Pod", "apiVersion" : "v1", ... }
    ctx.output.kubernetes.create_or_update(object)
    # ... metric = { "name" : "power", "group": "my_hook", "set" : 9000, ... }
    ctx.output.metrics.collect(metric)


if __name__ == "__main__":
    hook.run(main, configpath="hello.yaml") # 'config' arg is also supported for raw string
# hello.yaml
configVersion: v1
onStartup: 10

How to test

An example for pytest

# hello_test.py

from hello import main
from shell_operator import hook

# binding_context = [ { ... } ]
# expected_metrics = [ ... ]
# expected_kube_operations = [ ... ]

def test_hello():
    out = hook.testrun(main, binding_context)

    assert out.metrics.storage.data == expected_metrics
    assert out.kubernetes.storage.data == expected_kube_operations

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

shell_operator-0.0.5.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

shell_operator-0.0.5-py3-none-any.whl (9.6 kB view hashes)

Uploaded Python 3

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