From 9be2f2814c1883163d85f529bbfa24cc5e8a44ed Mon Sep 17 00:00:00 2001 From: Ravi Tripathi <ravi89@uab.edu> Date: Sun, 9 Feb 2020 19:52:13 -0500 Subject: [PATCH] add on_message_callback function, and start consuming messages --- slurm_agent.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/slurm_agent.py b/slurm_agent.py index 347c5c8..ab9e66e 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() + + + -- GitLab