diff --git a/slurm_agent.py b/slurm_agent.py index 347c5c83d3767ba2da9c66d4f00e094767ea8c69..ab9e66e51defb153952bcc98031a5561195f7806 100644 --- a/slurm_agent.py +++ b/slurm_agent.py @@ -3,7 +3,7 @@ import pika # python client import sys import rabbit_config as rcfg import socket - +import subprocess import time hostname = socket.gethostname().split(".", 1)[0] @@ -30,3 +30,30 @@ result = channel.queue_declare(queue=queue_name, exclusive=False) channel.queue_bind(exchange=rcfg.Exchange, queue=queue_name, routing_key=queue_name) +def slurm_account_create(ch, method, properties, body): + msg = json.loads(body) + username = msg['username'] + try: + subprocess.call(["sacctmgr", "add", "account", username, "Descripition: Add user"]) + except: + print("Failed to create user") + + channel.basic_ack(delivery_tag=method.delivery_tag) + + channel.basic_publish(exchange=rcfg.Exchange, routing_key='warewulf_file_sync', body=json.dumps(msg)) + + +# ingest messages +channel.basic_consume(queue=queue_name, on_message_callback=slurm_account_create) + +# initiate message ingestion +try: + channel.start_consuming() +except KeyboardInterrupt: + print("Disconnecting from broker.") + channel.stop_consuming() + +connection.close() + + +