start Docker VNF xterm via the rest api (can be called from the dashboard)
[osm/vim-emu.git] / src / emuvim / dcemulator / monitoring.py
index 6418e37..0d40531 100755 (executable)
@@ -34,7 +34,7 @@ import time
 from prometheus_client import start_http_server, Summary, Histogram, Gauge, Counter, REGISTRY, CollectorRegistry, \\r
     pushadd_to_gateway, push_to_gateway, delete_from_gateway\r
 import threading\r
-from subprocess import Popen, check_call\r
+from subprocess import Popen\r
 import os\r
 import docker\r
 import json\r
@@ -626,6 +626,46 @@ class DCNetworkMonitor():
                 wait_time += 1\r
         return ret\r
 \r
+    def term(self, vnf_list=[]):\r
+        """\r
+        Start a terminal window for the specified VNFs\r
+        (start a terminal for all VNFs if vnf_list is empty)\r
+        :param vnf_list:\r
+        :return:\r
+        """\r
+\r
+\r
+        if vnf_list is None:\r
+            vnf_list = []\r
+        if not isinstance(vnf_list, list):\r
+            vnf_list = str(vnf_list).split(',')\r
+            vnf_list = map(str.strip, vnf_list)\r
+        logging.info('vnf_list: {}'.format(vnf_list))\r
+\r
+        return self.start_xterm(vnf_list)\r
+\r
+\r
+    # start an xterm for the specfified vnfs\r
+    def start_xterm(self, vnf_names):\r
+        # start xterm for all vnfs\r
+        for vnf_name in vnf_names:\r
+            terminal_cmd = "docker exec -it mn.{0} /bin/bash".format(vnf_name)\r
+\r
+            cmd = ['xterm', '-xrm', 'XTerm*selectToClipboard: true', '-xrm', 'XTerm.vt100.allowTitleOps: false',\r
+                   '-T', vnf_name,\r
+                   '-e', terminal_cmd]\r
+            Popen(cmd)\r
+\r
+        ret = 'xterms started for {0}'.format(vnf_names)\r
+        if len(vnf_names) == 0:\r
+            ret = 'vnf list is empty, no xterms started'\r
+        return ret\r
+\r
+\r
+\r
+\r
+\r
+\r
 \r
 \r
 \r