mgr/dashboard: implement can_run checks for dashboard v2

Should be especially handy in development environments
for giving a clear message for people who have forgotten
to build frontend bits.

Signed-off-by: John Spray <john.spray@redhat.com>
This commit is contained in:
John Spray 2018-03-02 09:57:35 -05:00
parent 23eb14de52
commit b4190bed6f

View File

@ -11,7 +11,12 @@ try:
from urlparse import urljoin
except ImportError:
from urllib.parse import urljoin
import cherrypy
try:
import cherrypy
except ImportError:
# To be picked up and reported by .can_run()
cherrypy = None
from mgr_module import MgrModule, MgrStandbyModule
if 'COVERAGE_ENABLED' in os.environ:
@ -74,6 +79,21 @@ class Module(MgrModule):
mgr.init(self)
self._url_prefix = ''
@classmethod
def can_run(cls):
if cherrypy is None:
return False, "Missing dependency: cherrypy"
if not os.path.exists(cls.get_frontend_path()):
return False, "Frontend assets not found: incomplete build?"
return True, ""
@classmethod
def get_frontend_path(cls):
current_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(current_dir, 'frontend/dist')
def configure_cherrypy(self):
server_addr = self.get_localized_config('server_addr', '::')
server_port = self.get_localized_config('server_port', '8080')
@ -101,12 +121,10 @@ class Module(MgrModule):
}
cherrypy.config.update(config)
current_dir = os.path.dirname(os.path.abspath(__file__))
fe_dir = os.path.join(current_dir, 'frontend/dist')
config = {
'/': {
'tools.staticdir.on': True,
'tools.staticdir.dir': fe_dir,
'tools.staticdir.dir': self.get_frontend_path(),
'tools.staticdir.index': 'index.html'
}
}