add son-emu dashboard to the python setup file, so it is served from the Flask app...
[osm/vim-emu.git] / src / emuvim / api / rest / rest_api_endpoint.py
index 4767be4..71f87b9 100755 (executable)
@@ -25,6 +25,7 @@ the Horizon 2020 and 5G-PPP programmes. The authors would like to
 acknowledge the contributions of their colleagues of the SONATA
 partner consortium (www.sonata-nfv.eu).
 """
+
 import logging
 import threading
 from flask import Flask
@@ -42,6 +43,9 @@ from network import NetworkAction
 import monitor
 from monitor import MonitorInterfaceAction, MonitorFlowAction, MonitorLinkAction, MonitorSkewAction
 
+import pkg_resources
+from os import path
+
 logging.basicConfig(level=logging.INFO)
 
 
@@ -57,7 +61,12 @@ class RestApiEndpoint(object):
         self.port = port
 
         # setup Flask
-        self.app = Flask(__name__)
+        # find directory of dashboard files
+        dashboard_file = pkg_resources.resource_filename('emuvim.dashboard', "index.html")
+        dashboard_dir = path.dirname(dashboard_file)
+        logging.info("Started emu dashboard: {0}".format(dashboard_dir))
+
+        self.app = Flask(__name__, static_folder=dashboard_dir, static_url_path='/dashboard')
         self.api = Api(self.app)
 
         # setup endpoints
@@ -96,6 +105,7 @@ class RestApiEndpoint(object):
 
         logging.debug("Created API endpoint %s(%s:%d)" % (self.__class__.__name__, self.ip, self.port))
 
+
     def connectDatacenter(self, dc):
         compute.dcs[dc.label] = dc
         logging.info(