Added custom registries for functions
This commit is contained in:
+30
-27
@@ -1,49 +1,52 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import argparse
|
||||
import traceback
|
||||
import importlib.util
|
||||
from typing import List
|
||||
from playbook import StepLog, CustomStep, Play, Status
|
||||
from dataclasses import asdict
|
||||
|
||||
def pre(ctx) -> StepLog:
|
||||
ctx["a"] = 5
|
||||
from playbook.action_registry import ActionRegistry
|
||||
|
||||
return StepLog(
|
||||
"pre something",
|
||||
Status.GOOD,
|
||||
0,
|
||||
msg="set 5",
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description="Playbook Taskrunner")
|
||||
|
||||
# Flag for the playbook file
|
||||
parser.add_argument(
|
||||
"-p", "--playbook",
|
||||
type=str,
|
||||
required=True,
|
||||
help="Path to the playbook yaml file"
|
||||
)
|
||||
|
||||
def play(ctx):
|
||||
ctx["a"] = ctx["a"] + 10
|
||||
|
||||
return StepLog(
|
||||
"play something",
|
||||
Status.BAD,
|
||||
0,
|
||||
msg="added 10",
|
||||
# Flag for the custom registry files
|
||||
parser.add_argument(
|
||||
"-r", "--registry",
|
||||
nargs="+",
|
||||
default=[],
|
||||
help="One or more python files with actions"
|
||||
)
|
||||
|
||||
def post(ctx):
|
||||
ctx["a"] = ctx["a"] / 2
|
||||
return parser.parse_args()
|
||||
|
||||
return StepLog(
|
||||
"post something",
|
||||
Status.GOOD,
|
||||
0,
|
||||
msg=f"halved {ctx["a"]}",
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
args: argparse.Namespace = parse_args()
|
||||
extra_regs: List[ActionRegistry] = []
|
||||
|
||||
newPlay: Play
|
||||
try:
|
||||
newPlay = Play.from_yaml("./playbook.yaml")
|
||||
newPlay = Play.from_yaml(args.playbook, registries=extra_regs)
|
||||
except Exception as e:
|
||||
print(f"Failed to load playbook: {e}")
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
|
||||
print(newPlay.view_playbook())
|
||||
|
||||
# print(json.dumps(asdict(newPlay.play()), indent=2))
|
||||
print(json.dumps(asdict(newPlay.play()), indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user