X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fvim-emu.git;a=blobdiff_plain;f=src%2Femuvim%2Fapi%2Frest%2Frest_api_endpoint.py;fp=src%2Femuvim%2Fapi%2Frest%2Frest_api_endpoint.py;h=b9c11ab617c4a083b32830443d0bb6de34ee397d;hp=cefda5f9a535c76cb9d9285ffc32cc1823565f45;hb=d87400255e1997f85b9cdebc583811b70cca4ab7;hpb=2bbd459ee30a19ecb77bb0a0aeda73db16ef5244 diff --git a/src/emuvim/api/rest/rest_api_endpoint.py b/src/emuvim/api/rest/rest_api_endpoint.py index cefda5f..b9c11ab 100755 --- a/src/emuvim/api/rest/rest_api_endpoint.py +++ b/src/emuvim/api/rest/rest_api_endpoint.py @@ -26,7 +26,7 @@ import logging import threading -from flask import Flask +from flask import Flask, send_from_directory from flask_restful import Api from gevent.pywsgi import WSGIServer @@ -64,18 +64,17 @@ class RestApiEndpoint(object): self.connectDCNetwork(DCnetwork) # setup Flask - # 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.app = Flask(__name__) self.api = Api(self.app) - # setup endpoints + # define dashboard endpoints + db_dir, db_file = self.get_dashboard_path() + @self.app.route('/dashboard/') + def db_file(path): + logging.info("[DB] Serving: {}".format(path)) + return send_from_directory(db_dir, path) + # define REST API endpoints # compute related actions (start/stop VNFs, get info) self.api.add_resource( Compute, "/restapi/compute//") @@ -118,6 +117,17 @@ class RestApiEndpoint(object): logging.debug("Created API endpoint %s(%s:%d)" % (self.__class__.__name__, self.ip, self.port)) + def get_dashboard_path(self): + """ + Return absolute path to dashboard files. + """ + db_file = pkg_resources.resource_filename( + 'emuvim.dashboard', "index.html") + db_dir = path.dirname(db_file) + logging.info("[DB] Serving emulator dashboard from: {} and {}" + .format(db_dir, db_file)) + return db_dir, db_file + def connectDatacenter(self, dc): compute.dcs[dc.label] = dc logging.info(