mirror of
https://gitlab.com/fabinfra/fabaccess/actors/python_process_template.git
synced 2025-03-12 06:41:45 +01:00
73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import argparse
|
||
|
|
||
|
def on_free(args, actor_name):
|
||
|
print("Free")
|
||
|
|
||
|
def on_use(args, actor_name, user_id):
|
||
|
print("In Use")
|
||
|
|
||
|
def on_tocheck(args, actor_name, user_id):
|
||
|
print("To Check")
|
||
|
|
||
|
def on_blocked(args, actor_name, user_id):
|
||
|
print("Blocked")
|
||
|
|
||
|
def on_disabled(args, actor_name):
|
||
|
print("Disabled")
|
||
|
|
||
|
def on_reserve(args, actor_name, user_id):
|
||
|
print("Reversed")
|
||
|
|
||
|
def on_raw(args, actor_name, data):
|
||
|
print("Raw")
|
||
|
|
||
|
|
||
|
def main(args):
|
||
|
new_state = args.state
|
||
|
if new_state == "free":
|
||
|
on_free(args, args.name)
|
||
|
elif new_state == "inuse":
|
||
|
on_use(args, args.name, args.userid)
|
||
|
elif new_state == "tocheck":
|
||
|
on_tocheck(args, args.name, args.userid)
|
||
|
elif new_state == "blocked":
|
||
|
on_blocked(args, args.name, args.userid)
|
||
|
elif new_state == "disabled":
|
||
|
on_disabled(args, args.name)
|
||
|
elif new_state == "reserved":
|
||
|
on_reserve(args, args.name, args.userid)
|
||
|
elif new_state == "raw":
|
||
|
on_raw(args, args.name, args.data)
|
||
|
else:
|
||
|
print("Process actor called with unknown state %s" % new_state)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
parser = argparse.ArgumentParser()
|
||
|
parser.add_argument("name", help="name of this actor as configured in bffh.dhall")
|
||
|
|
||
|
subparsers = parser.add_subparsers(required=True, dest="state")
|
||
|
|
||
|
parser_free = subparsers.add_parser("free")
|
||
|
|
||
|
parser_inuse = subparsers.add_parser("inuse")
|
||
|
parser_inuse.add_argument("userid", help="The user that is now using the machine")
|
||
|
|
||
|
parser_tocheck = subparsers.add_parser("tocheck")
|
||
|
parser_tocheck.add_argument("userid", help="The user that should go check the machine")
|
||
|
|
||
|
parser_blocked = subparsers.add_parser("blocked")
|
||
|
parser_blocked.add_argument("userid", help="The user that marked the machine as blocked")
|
||
|
|
||
|
parser_disabled = subparsers.add_parser("disabled")
|
||
|
|
||
|
parser_reserved = subparsers.add_parser("reserved")
|
||
|
parser_reserved.add_argument("userid", help="The user that reserved the machine")
|
||
|
|
||
|
parser_raw = subparsers.add_parser("raw")
|
||
|
parser_raw.add_argument("data", help="Raw data for for this actor")
|
||
|
|
||
|
args = parser.parse_args()
|
||
|
main(args)
|