From 1fd19ccf22391ca59a4899614c5fe9313dbd9c37 Mon Sep 17 00:00:00 2001
From: Ravi Tripathi <ravi89@uab.edu>
Date: Sun, 9 Feb 2020 19:12:41 -0500
Subject: [PATCH] add initial slurm agent code

---
 slurm_agent.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 slurm_agent.py

diff --git a/slurm_agent.py b/slurm_agent.py
new file mode 100644
index 0000000..347c5c8
--- /dev/null
+++ b/slurm_agent.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+import pika # python client
+import sys
+import rabbit_config as rcfg
+import socket
+
+import time
+
+hostname = socket.gethostname().split(".", 1)[0]
+connect_host = rcfg.Server if hostname != rcfg.Server else "localhost"
+queue_name = "slurm_add_account"
+duration = 2
+
+# Set up credentials to connect to RabbitMQ server
+credentials = pika.PlainCredentials(rcfg.User, rcfg.Password)
+parameters = pika.ConnectionParameters(connect_host,
+                                   rcfg.Port,
+                                   rcfg.VHost,
+                                   credentials)
+
+# Establish connection to RabbitMQ server
+connection = pika.BlockingConnection(parameters)
+channel = connection.channel()
+
+# create exchange to pass messages
+channel.exchange_declare(exchange=rcfg.Exchange, exchange_type='direct')
+
+# creates a random name for the newly generated queue
+result = channel.queue_declare(queue=queue_name, exclusive=False)
+
+channel.queue_bind(exchange=rcfg.Exchange, queue=queue_name, routing_key=queue_name)
+
-- 
GitLab