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;h=d2abde85f670403d6c7c846596e027253c80cc10;hp=4f9d6d8734327f54e8971253817d157b752ece25;hb=655815663bf8234c837793db7a5e2e3c50164d3f;hpb=72f09885db3935e77901c3dee132cb176b927c7b diff --git a/src/emuvim/api/rest/rest_api_endpoint.py b/src/emuvim/api/rest/rest_api_endpoint.py index 4f9d6d8..d2abde8 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 @@ -44,6 +44,7 @@ from monitor import MonitorInterfaceAction, MonitorFlowAction, MonitorLinkAction import pkg_resources from os import path + logging.basicConfig() @@ -63,18 +64,18 @@ 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//") @@ -117,6 +118,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(