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
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
shell_operator-0.0.5.tar.gz
(8.6 kB
view hashes)
Built Distribution
Close
Hashes for shell_operator-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3485f828bb03d85caf5a5dab7f27de89afce2ce2be5581c4c2e845cd6f5d9b6 |
|
MD5 | 89a248847d390e0d39f87747669c01c5 |
|
BLAKE2b-256 | e2b936f5c46452d557a2dbc4743342dba807881849a6dd3ca3cf865a0ac66972 |