From 5779c40d82da5350ca0d6f27545d2733fbc5b082 Mon Sep 17 00:00:00 2001
From: Cloud User <centos@ohpc.novalocal>
Date: Tue, 11 Feb 2020 04:06:15 +0000
Subject: [PATCH] Adding json import, and changing the slurm call to add
 sacctmgr account

---
 slurm_agent.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 slurm_agent.py

diff --git a/slurm_agent.py b/slurm_agent.py
old mode 100644
new mode 100755
index ab9e66e..bb805b4
--- a/slurm_agent.py
+++ b/slurm_agent.py
@@ -5,6 +5,7 @@ import rabbit_config as rcfg
 import socket
 import subprocess
 import time
+import json
 
 hostname = socket.gethostname().split(".", 1)[0]
 connect_host = rcfg.Server if hostname != rcfg.Server else "localhost"
@@ -22,6 +23,8 @@ parameters = pika.ConnectionParameters(connect_host,
 connection = pika.BlockingConnection(parameters)
 channel = connection.channel()
 
+print "connection established. Listening for messages:"
+
 # create exchange to pass messages
 channel.exchange_declare(exchange=rcfg.Exchange, exchange_type='direct')
 
@@ -32,15 +35,16 @@ channel.queue_bind(exchange=rcfg.Exchange, queue=queue_name, routing_key=queue_n
 
 def slurm_account_create(ch, method, properties, body):
     msg = json.loads(body)
+    print("Message received {}".format(msg))
     username = msg['username']
     try:
-        subprocess.call(["sacctmgr", "add", "account", username, "Descripition: Add user"])
+        subprocess.call(["sudo", "sacctmgr", "add", "account", username, "-i",  "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))
+    channel.basic_publish(exchange=rcfg.Exchange, routing_key=username, body=json.dumps(msg))
     
 
 # ingest messages
-- 
GitLab