summaryrefslogtreecommitdiff
path: root/tools/plopcontrol.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/plopcontrol.py')
-rwxr-xr-xtools/plopcontrol.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/plopcontrol.py b/tools/plopcontrol.py
new file mode 100755
index 0000000..295f311
--- /dev/null
+++ b/tools/plopcontrol.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2017, NORDUnet A/S.
+# See LICENSE for licensing information.
+
+import socket
+import sys
+import signal
+
+def send_message(plopcontrolfile, message):
+ plopcontrolport = int(open(plopcontrolfile).read())
+ print >>sys.stderr, "plopcontrolport", plopcontrolport
+ s = socket.socket(socket.AF_INET)
+ print >>sys.stderr, "opened socket"
+ s.connect(("127.0.0.1", plopcontrolport))
+ print >>sys.stderr, "connected, sending message", message
+ s.sendall(message + "\n")
+ print >>sys.stderr, "sent message"
+ data = ""
+ while "\n" not in data:
+ data = data + s.recv(1024)
+ print >>sys.stderr, "received data"
+ data = data.rstrip("\n")
+ print >>sys.stderr, "received all data"
+ s.close()
+ return data
+
+def main():
+ signal.alarm(5)
+ reply = send_message(sys.argv[1], sys.argv[2])
+ print reply
+
+if __name__ == '__main__':
+ main()