Loading src/webui/Config.py +6 −2 Original line number Diff line number Diff line Loading @@ -15,6 +15,10 @@ HOST = '0.0.0.0' # accepts connections coming from any ADDRESS DEBUG=False # CONTEXT_SERVICE_ADDRESS = '10.107.242.226' CONTEXT_SERVICE_ADDRESS = 'context' # TODO: use the correct context ADDRESS CONTEXT_SERVICE_ADDRESS = '10.107.242.226' # CONTEXT_SERVICE_ADDRESS = 'context' # TODO: use the correct context ADDRESS CONTEXT_SERVICE_PORT = 1010 DEVICE_SERVICE_ADDRESS = '10.109.49.149' # DEVICE_SERVICE_ADDRESS = 'device' # TODO: use the correct address DEVICE_SERVICE_PORT = 2020 src/webui/Dockerfile +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ RUN python3 -m pip install -r webui/requirements.txt # Add files into working directory COPY common/. common COPY context/client/ContextClient.py context/client/ContextClient.py COPY context/. context COPY webui/. webui # Start webui service Loading src/webui/service/device/routes.py +13 −6 Original line number Diff line number Diff line from flask import render_template, Blueprint, flash, session from flask import render_template, Blueprint, flash, session, redirect from context.proto.context_pb2 import ConfigActionEnum, ConfigRule, TopologyIdList, TopologyList from webui.Config import CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT from device.client.DeviceClient import DeviceClient from webui.Config import (CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT, DEVICE_SERVICE_ADDRESS, DEVICE_SERVICE_PORT) from context.client.ContextClient import ContextClient from webui.proto.context_pb2 import (ContextId, DeviceList, DeviceId, Device, DeviceDriverEnum, DeviceOperationalStatusEnum) Loading Loading @@ -70,11 +72,16 @@ def add(): if len(driver) == 0: continue device.device_drivers.extend([int(driver)]) client: ContextClient = ContextClient(CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT) response: DeviceId = client.SetDevice(request) try: client: DeviceClient = DeviceClient(DEVICE_SERVICE_ADDRESS, DEVICE_SERVICE_PORT) response: DeviceId = client.AddDevice(device) client.close() flash(f'New device was created with ID "{response.device_uuid.uuid}".', 'success') redirect('/device/') except Exception as e: print(e) flash(f'Problem adding the device. {e.details()}', 'danger') return render_template('device/add.html', form=form, submit_text='Add New Device', Loading src/webui/service/templates/device/detail.html +36 −0 Original line number Diff line number Diff line Loading @@ -2,4 +2,40 @@ {% block content %} <h1>Device {{ device.device_id.device_uuid.uuid }}</h1> <div class="row mb-3"> <b>UUID:</b> <div class="col-sm-10"> {{ device.device_id.device_uuid.uuid }} </div> </div> <div class="row mb-3"> <b>Type:</b> <div class="col-sm-10"> {{ device.device_type }} </div> </div> <div class="row mb-3"> <b>Configurations:</b> <div class="col-sm-10"> <ul> {% for config in device.device_config.config_rules %} <li>{{ config.resource_key }}: {{ config.resource_value }}</li> {% endfor %} </ul> </div> </div> <div class="row mb-3"> <b>Endpoints:</b> <div class="col-sm-10"> <ul> {% for endpoint in device.device_endpoints %} <li>{{ endpoint.endpoint_id.endpoint_uuid.uuid }}: {{ endpoint.endpoint_type }}</li> {% endfor %} </ul> </div> </div> <div class="row mb-3"><button type="button" class="btn btn-success" onclick="window.location.href = '/device/'"><i class="bi bi-box-arrow-in-left"></i>Back to device list</button></div> {% endblock %} No newline at end of file src/webui/tests/test_unitary.py +18 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,8 @@ def app(): app = create_app(use_config={'TESTING': True, 'SERVER_NAME': 'localhost.localdomain', 'SECRET_KEY': '>s&}24@{]]#k3&^5$f3#?6?h3{W@[}/7z}2pa]>{3&5%RP<)[('}) 'SECRET_KEY': '>s&}24@{]]#k3&^5$f3#?6?h3{W@[}/7z}2pa]>{3&5%RP<)[(', 'WTF_CSRF_ENABLED': False}) yield app Loading Loading @@ -81,3 +82,19 @@ def test_device_add_page(client): assert b'Type' in rw.data, 'Form is not correctly implemented.' assert b'Configurations' in rw.data, 'Form is not correctly implemented.' assert b'Drivers' in rw.data, 'Form is not correctly implemented.' def test_device_add_action(client): with client.session_transaction() as sess: sess['context_uuid'] = 'admin' DEVICE_EMU = { 'device_id': 'EMULATED', 'device_type': 'emulated', 'device_config': '', 'operational_status': 1, 'device_drivers': 0, 'device_endpoints': [], } rw = client.post('/device/add', data=DEVICE_EMU, follow_redirects=True) with open('device_add.html', 'wb') as file: file.write(rw.data) assert b'success' in rw.data Loading
src/webui/Config.py +6 −2 Original line number Diff line number Diff line Loading @@ -15,6 +15,10 @@ HOST = '0.0.0.0' # accepts connections coming from any ADDRESS DEBUG=False # CONTEXT_SERVICE_ADDRESS = '10.107.242.226' CONTEXT_SERVICE_ADDRESS = 'context' # TODO: use the correct context ADDRESS CONTEXT_SERVICE_ADDRESS = '10.107.242.226' # CONTEXT_SERVICE_ADDRESS = 'context' # TODO: use the correct context ADDRESS CONTEXT_SERVICE_PORT = 1010 DEVICE_SERVICE_ADDRESS = '10.109.49.149' # DEVICE_SERVICE_ADDRESS = 'device' # TODO: use the correct address DEVICE_SERVICE_PORT = 2020
src/webui/Dockerfile +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ RUN python3 -m pip install -r webui/requirements.txt # Add files into working directory COPY common/. common COPY context/client/ContextClient.py context/client/ContextClient.py COPY context/. context COPY webui/. webui # Start webui service Loading
src/webui/service/device/routes.py +13 −6 Original line number Diff line number Diff line from flask import render_template, Blueprint, flash, session from flask import render_template, Blueprint, flash, session, redirect from context.proto.context_pb2 import ConfigActionEnum, ConfigRule, TopologyIdList, TopologyList from webui.Config import CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT from device.client.DeviceClient import DeviceClient from webui.Config import (CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT, DEVICE_SERVICE_ADDRESS, DEVICE_SERVICE_PORT) from context.client.ContextClient import ContextClient from webui.proto.context_pb2 import (ContextId, DeviceList, DeviceId, Device, DeviceDriverEnum, DeviceOperationalStatusEnum) Loading Loading @@ -70,11 +72,16 @@ def add(): if len(driver) == 0: continue device.device_drivers.extend([int(driver)]) client: ContextClient = ContextClient(CONTEXT_SERVICE_ADDRESS, CONTEXT_SERVICE_PORT) response: DeviceId = client.SetDevice(request) try: client: DeviceClient = DeviceClient(DEVICE_SERVICE_ADDRESS, DEVICE_SERVICE_PORT) response: DeviceId = client.AddDevice(device) client.close() flash(f'New device was created with ID "{response.device_uuid.uuid}".', 'success') redirect('/device/') except Exception as e: print(e) flash(f'Problem adding the device. {e.details()}', 'danger') return render_template('device/add.html', form=form, submit_text='Add New Device', Loading
src/webui/service/templates/device/detail.html +36 −0 Original line number Diff line number Diff line Loading @@ -2,4 +2,40 @@ {% block content %} <h1>Device {{ device.device_id.device_uuid.uuid }}</h1> <div class="row mb-3"> <b>UUID:</b> <div class="col-sm-10"> {{ device.device_id.device_uuid.uuid }} </div> </div> <div class="row mb-3"> <b>Type:</b> <div class="col-sm-10"> {{ device.device_type }} </div> </div> <div class="row mb-3"> <b>Configurations:</b> <div class="col-sm-10"> <ul> {% for config in device.device_config.config_rules %} <li>{{ config.resource_key }}: {{ config.resource_value }}</li> {% endfor %} </ul> </div> </div> <div class="row mb-3"> <b>Endpoints:</b> <div class="col-sm-10"> <ul> {% for endpoint in device.device_endpoints %} <li>{{ endpoint.endpoint_id.endpoint_uuid.uuid }}: {{ endpoint.endpoint_type }}</li> {% endfor %} </ul> </div> </div> <div class="row mb-3"><button type="button" class="btn btn-success" onclick="window.location.href = '/device/'"><i class="bi bi-box-arrow-in-left"></i>Back to device list</button></div> {% endblock %} No newline at end of file
src/webui/tests/test_unitary.py +18 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,8 @@ def app(): app = create_app(use_config={'TESTING': True, 'SERVER_NAME': 'localhost.localdomain', 'SECRET_KEY': '>s&}24@{]]#k3&^5$f3#?6?h3{W@[}/7z}2pa]>{3&5%RP<)[('}) 'SECRET_KEY': '>s&}24@{]]#k3&^5$f3#?6?h3{W@[}/7z}2pa]>{3&5%RP<)[(', 'WTF_CSRF_ENABLED': False}) yield app Loading Loading @@ -81,3 +82,19 @@ def test_device_add_page(client): assert b'Type' in rw.data, 'Form is not correctly implemented.' assert b'Configurations' in rw.data, 'Form is not correctly implemented.' assert b'Drivers' in rw.data, 'Form is not correctly implemented.' def test_device_add_action(client): with client.session_transaction() as sess: sess['context_uuid'] = 'admin' DEVICE_EMU = { 'device_id': 'EMULATED', 'device_type': 'emulated', 'device_config': '', 'operational_status': 1, 'device_drivers': 0, 'device_endpoints': [], } rw = client.post('/device/add', data=DEVICE_EMU, follow_redirects=True) with open('device_add.html', 'wb') as file: file.write(rw.data) assert b'success' in rw.data