From 5b876700bdef500e17c212f5b0bcea5383e44528 Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Sat, 8 Apr 2017 13:41:15 +0200 Subject: [PATCH] add son-emu dashboard to the python setup file, so it is served from the Flask app, at the dummygatekeeper's ip:port --- dashboard/README.md | 5 +--- dashboard/dashboard | 1 + setup.py | 3 +- src/emuvim/api/rest/rest_api_endpoint.py | 12 +++++++- src/emuvim/api/sonata/dummygatekeeper.py | 4 --- src/emuvim/dashboard/README.md | 4 +++ src/emuvim/dashboard/__init__.py | 27 ++++++++++++++++++ .../emuvim/dashboard}/css/main.css | 0 .../emuvim/dashboard}/img/SONATA_new.png | Bin .../emuvim/dashboard}/index.html | 2 +- .../emuvim/dashboard}/js/main.js | 0 .../son-emu-dashboard-screenshot.png | Bin 12 files changed, 47 insertions(+), 11 deletions(-) create mode 120000 dashboard/dashboard create mode 100755 src/emuvim/dashboard/README.md create mode 100644 src/emuvim/dashboard/__init__.py rename {dashboard => src/emuvim/dashboard}/css/main.css (100%) rename {dashboard => src/emuvim/dashboard}/img/SONATA_new.png (100%) rename {dashboard => src/emuvim/dashboard}/index.html (97%) rename {dashboard => src/emuvim/dashboard}/js/main.js (100%) rename {dashboard => src/emuvim/dashboard}/son-emu-dashboard-screenshot.png (100%) diff --git a/dashboard/README.md b/dashboard/README.md index db15c9d..70161b7 100755 --- a/dashboard/README.md +++ b/dashboard/README.md @@ -1,4 +1 @@ -# son-emu Dashboard - -A simple web-based dashboard that polls the REST API and displays running services etc. It does not do much more than son-cli but it looks nicer and improves the visualization of the emulator state for live demos. - +dashboard is moved to src/emuvim/dashboard so it can be part of the python-based installation script diff --git a/dashboard/dashboard b/dashboard/dashboard new file mode 120000 index 0000000..fa6d186 --- /dev/null +++ b/dashboard/dashboard @@ -0,0 +1 @@ +../src/emuvim/dashboard/ \ No newline at end of file diff --git a/setup.py b/setup.py index ce1c47f..186356c 100755 --- a/setup.py +++ b/setup.py @@ -38,7 +38,8 @@ setup(name='emuvim', packages=find_packages('src'), include_package_data=True, package_data= { - 'emuvim.api.sonata': ['*.yml'] + 'emuvim.api.sonata': ['*.yml'], + 'emuvim.dashboard' : ['*.html', 'css/*.css','img/*','js/*.js'] }, install_requires=[ 'pyaml', diff --git a/src/emuvim/api/rest/rest_api_endpoint.py b/src/emuvim/api/rest/rest_api_endpoint.py index 4767be4..71f87b9 100755 --- a/src/emuvim/api/rest/rest_api_endpoint.py +++ b/src/emuvim/api/rest/rest_api_endpoint.py @@ -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( diff --git a/src/emuvim/api/sonata/dummygatekeeper.py b/src/emuvim/api/sonata/dummygatekeeper.py index 4e98c6a..76ed3c2 100755 --- a/src/emuvim/api/sonata/dummygatekeeper.py +++ b/src/emuvim/api/sonata/dummygatekeeper.py @@ -1012,10 +1012,6 @@ api.add_resource(Instantiations, '/instantiations', '/api/v2/instantiations', '/ api.add_resource(Exit, '/emulator/exit') -#def initialize_GK(): -# global GK -# GK = Gatekeeper() - def start_rest_api(host, port, datacenters=dict()): GK.dcs = datacenters diff --git a/src/emuvim/dashboard/README.md b/src/emuvim/dashboard/README.md new file mode 100755 index 0000000..db15c9d --- /dev/null +++ b/src/emuvim/dashboard/README.md @@ -0,0 +1,4 @@ +# son-emu Dashboard + +A simple web-based dashboard that polls the REST API and displays running services etc. It does not do much more than son-cli but it looks nicer and improves the visualization of the emulator state for live demos. + diff --git a/src/emuvim/dashboard/__init__.py b/src/emuvim/dashboard/__init__.py new file mode 100644 index 0000000..45ad698 --- /dev/null +++ b/src/emuvim/dashboard/__init__.py @@ -0,0 +1,27 @@ +""" +Copyright (c) 2017 SONATA-NFV +ALL RIGHTS RESERVED. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] +nor the names of its contributors may be used to endorse or promote +products derived from this software without specific prior written +permission. + +This work has been performed in the framework of the SONATA project, +funded by the European Commission under Grant number 671517 through +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). +""" \ No newline at end of file diff --git a/dashboard/css/main.css b/src/emuvim/dashboard/css/main.css similarity index 100% rename from dashboard/css/main.css rename to src/emuvim/dashboard/css/main.css diff --git a/dashboard/img/SONATA_new.png b/src/emuvim/dashboard/img/SONATA_new.png similarity index 100% rename from dashboard/img/SONATA_new.png rename to src/emuvim/dashboard/img/SONATA_new.png diff --git a/dashboard/index.html b/src/emuvim/dashboard/index.html similarity index 97% rename from dashboard/index.html rename to src/emuvim/dashboard/index.html index 3c31bec..6f77d08 100755 --- a/dashboard/index.html +++ b/src/emuvim/dashboard/index.html @@ -58,7 +58,7 @@