X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Femuvim%2Fapi%2Frest%2Frest_api_endpoint.py;h=b9c11ab617c4a083b32830443d0bb6de34ee397d;hb=baeab7bcd1a8d65301d44c84e091845090010de5;hp=a9a863d43a3a79b387eef9774cf103e174d60c10;hpb=4a8088d1decc9041fd12e758888be09839c69a90;p=osm%2Fvim-emu.git diff --git a/src/emuvim/api/rest/rest_api_endpoint.py b/src/emuvim/api/rest/rest_api_endpoint.py index a9a863d..b9c11ab 100755 --- a/src/emuvim/api/rest/rest_api_endpoint.py +++ b/src/emuvim/api/rest/rest_api_endpoint.py @@ -26,9 +26,8 @@ import logging import threading -from flask import Flask +from flask import Flask, send_from_directory from flask_restful import Api -from gevent import monkey from gevent.pywsgi import WSGIServer # need to import total module to set its global variable dcs @@ -45,7 +44,6 @@ from monitor import MonitorInterfaceAction, MonitorFlowAction, MonitorLinkAction import pkg_resources from os import path -monkey.patch_all() logging.basicConfig() @@ -66,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//") @@ -120,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(