Loading src/webui/service/__init__.py +26 −15 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ # limitations under the License. import json from typing import List, Tuple, Union from flask import Flask, request, session from flask_healthz import healthz, HealthError from context.client.ContextClient import ContextClient Loading @@ -36,10 +37,20 @@ def readiness(): device_client.connect() device_client.close() except Exception as e: raise HealthError('Can\'t connect with the service: ' + e.details()) raise HealthError("Can't connect with the service: {:s}".format(str(e))) from e def from_json(json_str): return json.loads(json_str) def json_to_list(json_str : str) -> List[Union[str, Tuple[str, str]]]: try: data = json.loads(json_str) except: # pylint: disable=bare-except return [('item', str(json_str))] if isinstance(data, dict): return [('kv', key, value) for key, value in data.items()] elif isinstance(data, list): return [('item', item) for item in data] else: return [('item', str(data))] class SetSubAppMiddleware(): def __init__(self, app, web_app_root): Loading @@ -63,32 +74,32 @@ def create_app(use_config=None, web_app_root=None): app.register_blueprint(healthz, url_prefix='/healthz') from webui.service.js.routes import js from webui.service.js.routes import js # pylint: disable=import-outside-toplevel app.register_blueprint(js) from webui.service.main.routes import main from webui.service.main.routes import main # pylint: disable=import-outside-toplevel app.register_blueprint(main) from webui.service.load_gen.routes import load_gen from webui.service.load_gen.routes import load_gen # pylint: disable=import-outside-toplevel app.register_blueprint(load_gen) from webui.service.service.routes import service from webui.service.service.routes import service # pylint: disable=import-outside-toplevel app.register_blueprint(service) from webui.service.slice.routes import slice from webui.service.slice.routes import slice # pylint: disable=import-outside-toplevel,redefined-builtin app.register_blueprint(slice) from webui.service.device.routes import device from webui.service.device.routes import device # pylint: disable=import-outside-toplevel app.register_blueprint(device) from webui.service.link.routes import link from webui.service.link.routes import link # pylint: disable=import-outside-toplevel app.register_blueprint(link) app.jinja_env.filters['from_json'] = from_json app.jinja_env.globals.update(get_working_context=get_working_context) app.jinja_env.globals.update(get_working_topology=get_working_topology) app.jinja_env.globals.update({ # pylint: disable=no-member 'json_to_list' : json_to_list, 'get_working_context' : get_working_context, 'get_working_topology': get_working_topology, }) if web_app_root is not None: app.wsgi_app = SetSubAppMiddleware(app.wsgi_app, web_app_root) Loading src/webui/service/templates/device/detail.html +8 −2 Original line number Diff line number Diff line Loading @@ -103,8 +103,14 @@ </td> <td> <ul> {% for key, value in (config.custom.resource_value | from_json).items() %} <li><b>{{ key }}:</b> {{ value }}</li> {% for item_type, item in json_to_list(config.custom.resource_value) %} {% if item_type == 'item' %} <li>{{ ', '.join(item[1:]) }}</li> {% elif item_type == 'kv' %} <li><b>{{ item[1] }}:</b> {{ item[2] }}</li> {% else %} <li>{{ item }}</li> {% endif %} {% endfor %} </ul> </td> Loading Loading
src/webui/service/__init__.py +26 −15 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ # limitations under the License. import json from typing import List, Tuple, Union from flask import Flask, request, session from flask_healthz import healthz, HealthError from context.client.ContextClient import ContextClient Loading @@ -36,10 +37,20 @@ def readiness(): device_client.connect() device_client.close() except Exception as e: raise HealthError('Can\'t connect with the service: ' + e.details()) raise HealthError("Can't connect with the service: {:s}".format(str(e))) from e def from_json(json_str): return json.loads(json_str) def json_to_list(json_str : str) -> List[Union[str, Tuple[str, str]]]: try: data = json.loads(json_str) except: # pylint: disable=bare-except return [('item', str(json_str))] if isinstance(data, dict): return [('kv', key, value) for key, value in data.items()] elif isinstance(data, list): return [('item', item) for item in data] else: return [('item', str(data))] class SetSubAppMiddleware(): def __init__(self, app, web_app_root): Loading @@ -63,32 +74,32 @@ def create_app(use_config=None, web_app_root=None): app.register_blueprint(healthz, url_prefix='/healthz') from webui.service.js.routes import js from webui.service.js.routes import js # pylint: disable=import-outside-toplevel app.register_blueprint(js) from webui.service.main.routes import main from webui.service.main.routes import main # pylint: disable=import-outside-toplevel app.register_blueprint(main) from webui.service.load_gen.routes import load_gen from webui.service.load_gen.routes import load_gen # pylint: disable=import-outside-toplevel app.register_blueprint(load_gen) from webui.service.service.routes import service from webui.service.service.routes import service # pylint: disable=import-outside-toplevel app.register_blueprint(service) from webui.service.slice.routes import slice from webui.service.slice.routes import slice # pylint: disable=import-outside-toplevel,redefined-builtin app.register_blueprint(slice) from webui.service.device.routes import device from webui.service.device.routes import device # pylint: disable=import-outside-toplevel app.register_blueprint(device) from webui.service.link.routes import link from webui.service.link.routes import link # pylint: disable=import-outside-toplevel app.register_blueprint(link) app.jinja_env.filters['from_json'] = from_json app.jinja_env.globals.update(get_working_context=get_working_context) app.jinja_env.globals.update(get_working_topology=get_working_topology) app.jinja_env.globals.update({ # pylint: disable=no-member 'json_to_list' : json_to_list, 'get_working_context' : get_working_context, 'get_working_topology': get_working_topology, }) if web_app_root is not None: app.wsgi_app = SetSubAppMiddleware(app.wsgi_app, web_app_root) Loading
src/webui/service/templates/device/detail.html +8 −2 Original line number Diff line number Diff line Loading @@ -103,8 +103,14 @@ </td> <td> <ul> {% for key, value in (config.custom.resource_value | from_json).items() %} <li><b>{{ key }}:</b> {{ value }}</li> {% for item_type, item in json_to_list(config.custom.resource_value) %} {% if item_type == 'item' %} <li>{{ ', '.join(item[1:]) }}</li> {% elif item_type == 'kv' %} <li><b>{{ item[1] }}:</b> {{ item[2] }}</li> {% else %} <li>{{ item }}</li> {% endif %} {% endfor %} </ul> </td> Loading