From 3afb222d90b83566fc9f33e189648868b30658a6 Mon Sep 17 00:00:00 2001 From: hangliu1 Date: Thu, 12 May 2022 01:27:24 -0400 Subject: [PATCH] [config tool][doc]: remove old configurator remove configurator in misc/config_tools/config_app, since there is new configurator in misc/config_tools/configurator. remove related document. Tracked-On: #7466 Signed-off-by: hangliu1 --- doc/develop.rst | 1 - doc/tutorials/acrn_configurator_tool.rst | 226 --- .../config_app/acrn_configurator.py | 45 - misc/config_tools/config_app/configs.py | 18 - misc/config_tools/config_app/controller.py | 515 ------- misc/config_tools/config_app/requirements | 5 - misc/config_tools/config_app/static/main.js | 1182 --------------- .../config_tools/config_app/static/styles.css | 8 - .../config_app/templates/base.html | 210 --- .../config_app/templates/launch.html | 407 ----- .../config_app/templates/scenario.html | 482 ------ misc/config_tools/config_app/views.py | 1338 ----------------- 12 files changed, 4437 deletions(-) delete mode 100644 doc/tutorials/acrn_configurator_tool.rst delete mode 100755 misc/config_tools/config_app/acrn_configurator.py delete mode 100644 misc/config_tools/config_app/configs.py delete mode 100644 misc/config_tools/config_app/controller.py delete mode 100644 misc/config_tools/config_app/requirements delete mode 100644 misc/config_tools/config_app/static/main.js delete mode 100644 misc/config_tools/config_app/static/styles.css delete mode 100644 misc/config_tools/config_app/templates/base.html delete mode 100644 misc/config_tools/config_app/templates/launch.html delete mode 100644 misc/config_tools/config_app/templates/scenario.html delete mode 100644 misc/config_tools/config_app/views.py diff --git a/doc/develop.rst b/doc/develop.rst index 71a42b03d..885794f72 100644 --- a/doc/develop.rst +++ b/doc/develop.rst @@ -39,7 +39,6 @@ Configuration Tutorials tutorials/acrn_configuration_tool tutorials/board_inspector_tool - tutorials/acrn_configurator_tool tutorials/upgrading_configuration reference/config-options reference/config-options-launch diff --git a/doc/tutorials/acrn_configurator_tool.rst b/doc/tutorials/acrn_configurator_tool.rst deleted file mode 100644 index ece5361c5..000000000 --- a/doc/tutorials/acrn_configurator_tool.rst +++ /dev/null @@ -1,226 +0,0 @@ -.. _acrn_configurator_tool: - -ACRN Configurator Tool -###################### - -This guide describes all features and uses of the tool. - -About the ACRN Configurator Tool -********************************* - -The ACRN Configurator tool ``acrn_configurator.py`` provides a web-based -user interface to help you customize your -:ref:`ACRN configuration `. Capabilities: - -- reads board information from the specified board configuration file -- provides a GUI to help you configure and validate scenario and - launch configuration files -- generates launch scripts for the specified post-launched User VMs -- dynamically creates a new scenario configuration and adds or deletes VM - settings in it -- dynamically creates a new launch configuration and adds or deletes User VM - settings in it - -The tool guides you to configure ACRN in a particular order, due to -dependencies among the different types of configuration files. Here's an -overview of what to expect: - -#. Import the board configuration file that you generated via the - :ref:`Board Inspector tool `. - -#. Customize your scenario configuration file by defining hypervisor and - VM settings that will be used to build the ACRN hypervisor. - -#. If your scenario has post-launched User VMs, customize launch scripts - that the Service VM will use to create the VMs - and allocate resources to them dynamically at runtime. - Customizing launch scripts involves these steps: - - a. Configure settings for all post-launched User VMs in your scenario - and save the configuration in a launch configuration file. - - #. Generate the launch scripts. The ACRN Configurator creates one - launch script for each VM defined in the launch configuration file. - -Generate a Scenario Configuration File and Launch Scripts -********************************************************* - -The following steps describe all options in the ACRN Configurator for generating -a custom scenario configuration file and launch scripts. - -#. Make sure the development computer is set up and ready to launch the ACRN - Configurator, according to :ref:`gsg-dev-setup` in the Getting Started Guide. - -#. Launch the ACRN Configurator. This example assumes the tool is in the - ``~/acrn-work/`` directory. Feel free to modify the command as needed. - - .. code-block:: bash - - ~/acrn-work/acrn-hypervisor/misc/config_tools/config_app/acrn_configurator.py - -#. Your web browser should open the website ``_ - automatically, or you may need to visit this website manually. The ACRN - Configurator is supported on Chrome and Firefox. - -#. Click the **Import Board XML** button and browse to the board - configuration file that you generated via the - :ref:`Board Inspector `. After the file is uploaded, - make sure the board name is selected in the **Board info** drop-down list - and the board information appears. - -#. Start the scenario configuration process by selecting an option from the - **Scenario Settings** menu on the top banner of the UI or by importing a - scenario configuration file via the **Import XML** button. The four options - are described below: - - * Click **Create a new scenario** from the **Scenario Settings** menu to - dynamically create a new scenario configuration for the current board. - - * Click **Load a default scenario** from the **Scenario Settings** menu to - select a :ref:`predefined scenario configuration `. - - * Click the **Scenario Settings** menu and select a scenario from the list - under **scenario setting list**. - - .. image:: images/choose_scenario.png - :align: center - :class: drop-shadow - - * Click the **Import XML** button to import a customized scenario - configuration file. - The file must be one that was written for the current board. Any mismatch - in the board name and the one found in the scenario configuration file you - are trying to import will lead to an error message. - -#. When the scenario configuration file is available for editing, the - configurable items appear below the **Scenario Setting** row. You may - need to scroll down to see them. Example: - - .. image:: images/configure_scenario.png - :align: center - :class: drop-shadow - - * You can edit these items directly in the text boxes, or you can choose - single or even multiple items from the drop-down list. - - * Read-only items are marked as gray. - - * Hover the mouse cursor over the item to see the description. - -#. Add or delete VMs: - - * Click **Add a VM below** in a VM's settings, and then select a VM type - to add a new VM under the current VM. - - * Click **Remove this VM** in a VM's settings to remove the VM from the - scenario. - - When a VM is added or removed, the ACRN Configurator reassigns the VM IDs for - the remaining VMs by the order of pre-launched User VMs, Service VM, and - post-launched User VMs. - - .. image:: images/configure_vm_add.png - :align: center - :class: drop-shadow - -#. Click **Export XML** to save the scenario configuration file. A dialog box - appears, enabling you to save the file to a specific folder by inputting the - absolute path to this folder. If you don't specify a path, the file will be - saved to the default folder: ``acrn-hypervisor/../user_config/``. - - Before saving the scenario configuration file, the Configurator validates - the configurable items. If errors exist, the Configurator lists all - incorrectly configured items and shows the errors. Example: - - .. image:: images/err_acrn_configuration.png - :align: center - :class: drop-shadow - - After the scenario is saved, the page automatically displays the saved - scenario configuration file. - -#. To delete a scenario configuration file, click **Export XML** > **Remove**. - The Configurator will delete the loaded file, even if you change the name of - the file in the dialog box. - -#. If your scenario has post-launched User VMs, continue to the next step - to create launch scripts for those VMs. If your scenario doesn't have - post-launched User VMs, you can skip to the final step to close the tool. - -#. Start the launch script configuration process by - selecting an option from the **Launch Settings** menu on the top banner of - the UI or by importing a launch configuration file via the **Import XML** - button. The four options are described below: - - * Click **Create a new launch script** from the **Launch Settings** menu to - dynamically create a new launch configuration for the current board. - - * Click **Load a default launch script** from the **Launch Settings** menu to - select a predefined launch configuration. - - * Click the **Launch Settings** menu and select a launch configuration - from the list under **launch setting list**. - - .. image:: images/choose_launch.png - :align: center - :class: drop-shadow - - * Click the **Import XML** button to import a customized launch - configuration file. - -#. Select a scenario for the current launch configuration from the - **Select Scenario** drop-down box. - -#. When the launch configuration file is available for editing, the - configurable items appear below the **Launch Setting** row. You may need - to scroll down to see them. Example: - - .. image:: images/configure_launch.png - :align: center - :class: drop-shadow - - * You can edit these items directly in the text boxes, or you can choose - single or even multiple items from the drop-down list. - - * Read-only items are marked as gray. - - * Hover the mouse cursor over the item to see the description. - -#. Add or remove User VM launch scripts: - - * Click **Configure a User VM below** to add a User VM launch script. - - * Click **Remove this VM** to remove a User VM launch script. - - .. image:: images/configure_launch_add.png - :align: center - :class: drop-shadow - -#. Click **Export XML** to save the launch configuration file. A dialog box - appears, enabling you to save the file to a specific folder by inputting the - absolute path to this folder. If you don't specify a path, the file will - be saved to the default folder: - ``acrn-hypervisor/../user_config/``. - - Before saving the launch configuration file, the Configurator validates the - configurable items. If errors exist, the Configurator lists all incorrectly - configured items and shows the errors. - -#. To delete a launch configuration file, click **Export XML** > **Remove**. - The Configurator will delete the loaded file, even if you change the name of - the file in the dialog box. - -#. Click **Generate Launch Script** to save the current launch configuration - and then generate a launch script for each VM defined in the launch - configuration. - - .. image:: images/generate_launch_script.png - :align: center - :class: drop-shadow - -#. Confirm that the launch scripts appear in the - ``/output`` directory. - -#. When you are done using the tool, close the browser and press - :kbd:`CTRL` + :kbd:`C` to terminate the - ``acrn_configurator.py`` program running in the terminal window. diff --git a/misc/config_tools/config_app/acrn_configurator.py b/misc/config_tools/config_app/acrn_configurator.py deleted file mode 100755 index 082584bbd..000000000 --- a/misc/config_tools/config_app/acrn_configurator.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (C) 2019 Intel Corporation. -# SPDX-License-Identifier: BSD-3-Clause - -"""Entry for config app. - -""" - -import os -import sys -import threading -import webbrowser - -# flask: Copyright 2010 Pallets -# SPDX-License-Identifier: BSD-3-Clause -# Refer to https://github.com/pallets/flask/blob/master/LICENSE.rst for the permission notice. -from flask import Flask - -# flask: Copyright (c) 2013, Marc Brinkmann -# SPDX-License-Identifier: BSD-3-Clause -# Refer to https://pypi.org/project/Flask-Bootstrap/ for the permission notice. -from flask_bootstrap import Bootstrap - -import configs -sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) -sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library')) -sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', - 'board_config')) -sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', - 'scenario_config')) -sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', - 'launch_config')) -from views import CONFIG_APP - -APP = Flask(__name__) -APP.config.from_object(configs) -APP.register_blueprint(CONFIG_APP) -APP.jinja_env.add_extension('jinja2.ext.do') -Bootstrap(app=APP) - -if __name__ == '__main__': - URL = "http://127.0.0.1:5001/scenario" - threading.Timer(1, lambda: webbrowser.open(URL)).start() - APP.run(port=5001, debug=False) diff --git a/misc/config_tools/config_app/configs.py b/misc/config_tools/config_app/configs.py deleted file mode 100644 index 0af8cf192..000000000 --- a/misc/config_tools/config_app/configs.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. -# SPDX-License-Identifier: BSD-3-Clause - -"""Configurations for config app. - -""" - -import os - -BOARD_INFO = None -BOARD_TYPE = None -SCENARIO = None -LAUNCH = None -DEFAULT_CONFIG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data') -CONFIG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..', '..', 'user_config') - -if not os.path.isdir(CONFIG_PATH): - os.makedirs(CONFIG_PATH) diff --git a/misc/config_tools/config_app/controller.py b/misc/config_tools/config_app/controller.py deleted file mode 100644 index e7f1d8747..000000000 --- a/misc/config_tools/config_app/controller.py +++ /dev/null @@ -1,515 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. -# SPDX-License-Identifier: BSD-3-Clause - -"""Controller for config app. - -""" - -import os -from xmlschema import XMLSchema11 -from xmlschema.validators import Xsd11Element, XsdSimpleType, XsdAtomicBuiltin, Xsd11ComplexType, Xsd11Group, Xsd11Attribute -import lxml.etree as etree - - -class XmlConfig: - """The core class to analyze and modify acrn config xml files""" - def __init__(self, path=None, default=True): - self._xml_path = path - self._default = default - self._curr_xml = None - self._curr_xml_tree = None - - @staticmethod - def _get_xml_type(xml_file): - """ - get the config type by file. - :param xml_file: the file path of xml file. - :return: the xml type. - :raises: ValueError, OSError, SyntaxError. - """ - xml_type = '' - if os.path.splitext(xml_file)[1] != '.xml': - return xml_type - try: - tree = etree.parse(xml_file) - root = tree.getroot() - if 'user_vm_launcher' in root.attrib: - xml_type = 'user_vm_launcher' - elif 'scenario' in root.attrib: - xml_type = 'scenario' - elif 'board' in root.attrib: - xml_type = 'board' - elif 'board_setting' in root.attrib: - xml_type = 'board_setting' - except ValueError: - print('xml parse error: {}'.format(xml_file)) - xml_type = '' - except OSError: - print('xml open error: {}'.format(xml_file)) - xml_type = '' - except SyntaxError: - print('xml syntax error: {}'.format(xml_file)) - xml_type = '' - - return xml_type - - def list_all(self, xml_type=None): - """ - list all xml config files by type. - :param xml_type: the xml type. - :return: he list of xml config files. - """ - xmls = [] - user_xmls = [] - - if self._xml_path is None or not os.path.exists(self._xml_path): - return xmls, user_xmls - for test_file in os.listdir(self._xml_path): - test_file_path = os.path.join(self._xml_path, test_file) - if os.path.isfile(test_file_path): - if XmlConfig._get_xml_type(test_file_path) == xml_type: - xmls.append(os.path.splitext(test_file)[0]) - user_path = os.path.join(self._xml_path, 'user_defined') - if os.path.isdir(user_path): - for test_file in os.listdir(user_path): - test_file_path = os.path.join(user_path, test_file) - if os.path.isfile(test_file_path): - if XmlConfig._get_xml_type(test_file_path) == xml_type: - user_xmls.append(os.path.splitext(test_file)[0]) - - return xmls, user_xmls - - def set_curr(self, xml): - """ - set current xml file to analyze. - :param xml: the xml file. - :return: None. - :raises: ValueError, OSError, SyntaxError. - """ - if self._xml_path is None or xml is None: - return - try: - self._curr_xml = xml - - xml_path = os.path.join(self._xml_path, self._curr_xml + '.xml') \ - if self._default \ - else os.path.join(self._xml_path, 'user_defined', self._curr_xml + '.xml') - - parser = etree.XMLParser(remove_blank_text=True) - tree = etree.parse(xml_path, parser) - self._curr_xml_tree = tree - except ValueError: - print('xml parse error: {}'.format(xml)) - self._curr_xml = None - self._curr_xml_tree = None - except OSError: - print('xml open error: {}'.format(xml)) - self._curr_xml = None - self._curr_xml_tree = None - except SyntaxError: - print('xml syntax error: {}'.format(xml)) - self._curr_xml = None - self._curr_xml_tree = None - - def get_curr(self): - """ - get current xml config file. - :return: current xml config file name. - """ - return self._curr_xml - - def get_curr_root(self): - """ - get the xml root of current xml config file. - :return: the xml root of current xml config file. - """ - if self._curr_xml_tree is None: - return None - return self._curr_xml_tree.getroot() - - def get_curr_value(self, *args): - """ - get the value of the element by its path. - :param args: the path of the element. - :return: the value of the element. - """ - if self._curr_xml_tree is None: - return None - dest_node = self._get_dest_node(*args) - if dest_node is None: - return None - if dest_node.text is None or dest_node.text.strip() == '': - return '' - return dest_node.text - - def set_curr_value(self, value, *args): - """ - set the value of the element by its path. - :param value: the value of the element. - :param args: the path of the element. - :return: None. - """ - if self._curr_xml_tree is None: - return - dest_node = self._get_dest_node(*args) - dest_node.text = value - - def set_curr_list(self, values, *args): - """ - set a list of sub element for the element by its path. - :param values: the list of values of the element. - :param args: the path of the element. - :return: None. - """ - if self._curr_xml_tree is None: - return - tag = args[-1] - args = args[:-1] - dest_node = self._get_dest_node(*args) - new_node_desc = None - for node in list(dest_node): - if node.tag == tag: - if 'desc' in node.attrib: - new_node_desc = node.attrib['desc'] - dest_node.remove(node) - for value in values: - new_node = etree.SubElement(dest_node, tag) - new_node.text = value - if new_node_desc is not None: - new_node.attrib['desc'] = new_node_desc - - def set_curr_attr(self, attr_name, attr_value, *args): - """ - set the attribute of the element by its path. - :param attr_name: the attribute name of the element. - :param attr_value: the attribute value of the element. - :param args: the path of the element. - :return: None. - """ - if self._curr_xml_tree is None: - return - dest_node = self._get_dest_node(*args) - dest_node.attrib[attr_name] = attr_value - - def add_curr_value(self, key, desc, value, *args): - """ - add a sub element for the element by its path. - :param key: the tag of the sub element. - :param desc: the attribute desc of the sub element. - :param value: the value of the sub element. - :param args: the path of the element. - :return: None. - """ - if self._curr_xml_tree is None: - return - - dest_node = self._get_dest_node(*args) - - if key in ['vm']: - etree.SubElement(dest_node, key, attrib={'id': value, 'desc': desc}) - else: - new_node = etree.SubElement(dest_node, key, attrib={'desc': desc}) - new_node.text = value - - def get_curr_elem(self, *args): - """ - get elements for current path. - :param args: the path of the element. - :return: current element. - """ - if self._curr_xml_tree is None: - return - - dest_node = self._get_dest_node(*args) - return dest_node - - def clone_curr_elem(self, elem, *args): - """ - clone elements for current path. - :param elem: the element to clone. - :param args: the path of the element. - :return: None. - """ - if self._curr_xml_tree is None: - return - - dest_node = self._get_dest_node(*args) - dest_node.append(elem) - - def insert_curr_elem(self, index, elem, *args): - """ - insert elements for current path. - :param index: the location for the element to insert. - :param elem: the element to insert. - :param args: the path of the element. - :return: None. - """ - if self._curr_xml_tree is None: - return - - dest_node = self._get_dest_node(*args) - dest_node.insert(index, elem) - - def delete_curr_elem(self, *args): - """ - delete the element by its path. - :param args: the path of the element. - :return: None. - """ - if self._curr_xml_tree is None: - return - father_node = self._get_dest_node(*args[:-1]) - dest_node = self._get_dest_node(*args) - father_node.remove(dest_node) - - def delete_curr_key(self, *args): - """ - delete the element by its path. - :param args: the path of the element. - :return: None. - """ - if self._curr_xml_tree is None: - return - dest_node = self._get_dest_node(*args) - self._curr_xml_tree.getroot().remove(dest_node) - - def _get_dest_node(self, *args): - """ - get the destination element by its path. - :param args: the path of the element. - :return: the destination element. - """ - if self._curr_xml_tree is None: - return None - dest_node = self._curr_xml_tree.getroot() - path = '.' - for arg in args: - # tag:attr=xxx - # tag:attr - # tag - tag = None - attr_name = None - attr_value = None - if ':' not in arg: - tag = arg - elif '=' not in arg: - # tag = arg.split(':')[0] - # attr_name = arg.split(':')[1] - raise Exception('unsupported xml path: tag:attr') - else: - tag = arg.split(':')[0] - attr = arg.split(':')[1] - attr_name = attr.split('=')[0] - attr_value = attr.split('=')[1] - - if attr_value is None: - path += ("/" + tag) - else: - path += ("/" + tag + "[@" + attr_name + "='" + attr_value + "']") - - dest_node = dest_node.findall(path) - if dest_node is not None and dest_node != []: - return dest_node[0] - - raise Exception('can not find node by {} from xml'.format(args)) - - def save(self, xml=None, user_defined=False): - """ - save current xml to file. - :param xml: the file name to save; if not specified, save current xml to default names. - :param user_defined: save to user defined folder or default folder. - :return: None. - """ - if self._curr_xml_tree is None: - return - if xml is None: - xml = self._curr_xml - - xml_path = self._xml_path - if user_defined: - xml_path = os.path.join(self._xml_path, 'user_defined') - if not os.path.isdir(xml_path): - os.makedirs(xml_path) - - self._curr_xml_tree.write(os.path.join(xml_path, xml+'.xml'), encoding='utf-8', pretty_print=True) - - def _format_xml(self, element, depth=0): - i = "\n" + depth * " " - if element: - if not element.text or not element.text.strip(): - element.text = i + " " - if not element.tail or not element.tail.strip(): - element.tail = i - for element in element: - self._format_xml(element, depth + 1) - if not element.tail or not element.tail.strip(): - element.tail = i - else: - if depth and (not element.tail or not element.tail.strip()): - element.tail = i - - -def get_acrn_config_element(xsd_file): - """ - return the root element for the xsd file - :param xsd_file: the input xsd schema file - :return: the root element of the xsd file - """ - # schema = XMLSchema11(xsd_file) - xsd_doc = etree.parse(xsd_file) - xsd_doc.xinclude() - schema = XMLSchema11(etree.tostring(xsd_doc, encoding="unicode")) - - xsd_element_root = schema.root_elements[0] - acrn_config_element_root = xsd_2_acrn_config_element(xsd_element_root) - # doc_dict = acrn_config_element_2_doc_dict(acrn_config_element_root, {}) - # enum_dict = acrn_config_element_2_enum_dict(acrn_config_element_root, {}) - # xpath_dict = acrn_config_element_2_xpath_dict(acrn_config_element_root, {}) - - # from pprint import pprint - # pprint(acrn_config_element_root) - # pprint(xpath_dict) - - return acrn_config_element_root - - -def xsd_2_acrn_config_element(xsd_element, layer=0, index=0, path=''): - """ - translate XSD element to ACRN config element - :param xsd_element: the xsd element - :param layer: current layer - :param index: current index of current layer - :param path: path of current element - :return: ACRN config element - """ - acrn_config_element = { - 'name': xsd_element.name, - 'type': None, - 'path': path+'/'+xsd_element.name, - 'layer': layer, - 'index': index, - 'doc': None, - 'configurable': 'y', - 'readonly': 'n', - 'multiselect': 'n', - 'default': xsd_element.default, - 'attributes': None, - # 'minOccurs': None, - # 'maxOccurs': None, - 'enumeration': None, - 'sub_elements': None - } - if isinstance(xsd_element.type, Xsd11ComplexType): - acrn_config_element['type'] = xsd_element.type.name - for xsd_component in xsd_element.type.iter_components(): - if isinstance(xsd_component, Xsd11Group): - if acrn_config_element['sub_elements'] is None: - acrn_config_element['sub_elements'] = {'all':[], 'choice':[], 'sequence':[]} - index = 0 - for sub_xsd_component in xsd_component.iter_components(): - if isinstance(sub_xsd_component, Xsd11Element): - sub_acrn_config_element = xsd_2_acrn_config_element(sub_xsd_component, layer+1, - index, path+'/'+xsd_element.name) - acrn_config_element['sub_elements'][xsd_component.model].append(sub_acrn_config_element) - index += 1 - else: - if isinstance(xsd_element.type, XsdAtomicBuiltin): - acrn_config_element['type'] = xsd_element.type.name - elif isinstance(xsd_element.type.base_type, XsdSimpleType): - acrn_config_element['type'] = xsd_element.type.base_type.name - else: - acrn_config_element['type'] = xsd_element.type.name - if xsd_element.type.enumeration: - acrn_config_element['enumeration'] = xsd_element.type.enumeration - - annotation = None - if hasattr(xsd_element, 'annotation') and xsd_element.annotation: - annotation = xsd_element.annotation - elif hasattr(xsd_element.type, 'annotation') and xsd_element.type.annotation: - annotation = xsd_element.type.annotation - if annotation: - if annotation.documentation: - doc_list = [documentation.text for documentation in annotation.documentation] - acrn_config_element['doc'] = '\n'.join(doc_list) - for key in annotation.elem.keys(): - if key.endswith('configurable'): - acrn_config_element['configurable'] = annotation.elem.get(key) - elif key.endswith('readonly'): - acrn_config_element['readonly'] = annotation.elem.get(key) - elif key.endswith('multiselect'): - acrn_config_element['multiselect'] = annotation.elem.get(key) - - if xsd_element.attributes: - attrs = [] - for attr in xsd_element.attributes.iter_components(): - if isinstance(attr, Xsd11Attribute): - attrs.append({'name': attr.name, 'type': attr.type.name}) - acrn_config_element['attributes'] = attrs - - return acrn_config_element - -def acrn_config_element_2_doc_dict(acrn_config_element, doc_dict): - """ - get the dictionary for documentation of all configurable elements by ACRN config element. - :param acrn_config_element: the ACRN config element - :param doc_dict: the dictionary to save documentation of all configurable elements - :return: the dictionary to save documentation of all configurable elements - """ - if 'doc' in acrn_config_element and 'path' in acrn_config_element \ - and acrn_config_element['path'] not in doc_dict: - if acrn_config_element['doc']: - doc_dict[acrn_config_element['path']] = acrn_config_element['doc'] - else: - doc_dict[acrn_config_element['path']] = acrn_config_element['name'] - - if 'sub_elements' in acrn_config_element and acrn_config_element['sub_elements']: - for order_type in acrn_config_element['sub_elements']: - for element in acrn_config_element['sub_elements'][order_type]: - doc_dict = acrn_config_element_2_doc_dict(element, doc_dict) - return doc_dict - -def acrn_config_element_2_enum_dict(acrn_config_element, enum_dict): - """ - get the dictionary for enumeration of all configurable elements by ACRN config element. - :param acrn_config_element: the ACRN config element - :param enum_dict: the dictionary to save enumeration of all configurable elements - :return: the dictionary to save enumeration of all configurable elements - """ - if 'enumeration' in acrn_config_element and 'path' in acrn_config_element \ - and acrn_config_element['path'] not in enum_dict \ - and acrn_config_element['enumeration']: - enum_dict[acrn_config_element['path']] = acrn_config_element['enumeration'] - if 'sub_elements' in acrn_config_element and acrn_config_element['sub_elements']: - for order_type in acrn_config_element['sub_elements']: - for element in acrn_config_element['sub_elements'][order_type]: - enum_dict = acrn_config_element_2_enum_dict(element, enum_dict) - return enum_dict - -def acrn_config_element_2_xpath_dict(acrn_config_element, xpath_dict): - """ - get the dictionary for xpath of all configurable elements by ACRN config element. - :param acrn_config_element: the ACRN config element - :param xpath_dict: the dictionary to save xpath of all configurable elements - :return: the dictionary to save xpath of all configurable elements - """ - if acrn_config_element['path'] not in xpath_dict.keys(): - xpath_dict[acrn_config_element['path']] = { - 'name': acrn_config_element['name'], - 'type': acrn_config_element['type'], - 'layer': acrn_config_element['layer'], - 'index': acrn_config_element['index'], - 'doc': acrn_config_element['doc'] if acrn_config_element['doc'] else acrn_config_element['name'], - 'configurable': acrn_config_element['configurable'], - 'readonly': acrn_config_element['readonly'], - 'multiselect': acrn_config_element['multiselect'], - 'default': acrn_config_element['default'], - 'attributes': acrn_config_element['attributes'], - # 'minOccurs': None, - # 'maxOccurs': None, - 'enumeration': acrn_config_element['enumeration'] - } - if 'sub_elements' in acrn_config_element and acrn_config_element['sub_elements']: - for order_type in acrn_config_element['sub_elements']: - for element in acrn_config_element['sub_elements'][order_type]: - enum_dict = acrn_config_element_2_xpath_dict(element, xpath_dict) - return xpath_dict diff --git a/misc/config_tools/config_app/requirements b/misc/config_tools/config_app/requirements deleted file mode 100644 index ba971b134..000000000 --- a/misc/config_tools/config_app/requirements +++ /dev/null @@ -1,5 +0,0 @@ -Flask==1.1.1 -flask_bootstrap==3.3.7.1 -xmlschema==1.4.1 -lxml==4.6.2 -defusedxml==0.7.1 diff --git a/misc/config_tools/config_app/static/main.js b/misc/config_tools/config_app/static/main.js deleted file mode 100644 index 9ad04ab43..000000000 --- a/misc/config_tools/config_app/static/main.js +++ /dev/null @@ -1,1182 +0,0 @@ -$().ready(function(){ - $("#board_info_file").change(function () { - var fileObj = $(this)[0].files[0]; - if (typeof (fileObj) == "undefined" || fileObj.size <= 0) { - alert("Upload error."); - return; - } - var file_name = $(this).val(); - var formFile = new FormData(); - formFile.append("name", file_name); - formFile.append("file", fileObj); - - $.ajax({ - url: "../upload_board_info", - data: formFile, - type: "Post", - dataType: "json", - cache: false, - processData: false, - contentType: false, - success: function (result) { - console.log(result); - if (result.status == 'success') { - if (result.info != 'updated') { - alert('Upload successfully.\nA new board type: '+result.info+' created.'); - } else { - alert('Upload successfully.'); - } - } else { - alert(result.status); - } - - window.location = 'http://'+ window.location.host+"/scenario"; - }, - error: function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }) - }); - - $("#scenario_file").change(function () { - var fileObj = $(this)[0].files[0]; - if (typeof (fileObj) == "undefined" || fileObj.size <= 0) { - alert("Upload error."); - return; - } - var file_name = $(this).val(); - - var formFile = new FormData(); - formFile.append("name", file_name); - formFile.append("file", fileObj); - - $.ajax({ - url: "../upload_scenario", - data: formFile, - type: "Post", - dataType: "json", - cache: false, - processData: false, - contentType: false, - success: function (result) { - console.log(result); - status = result.status; - if (status!='success') { - alert(status); - return; - } - error_list = result.error_list; - file_name = result.file_name; - rename = result.rename - if(result.rename==true) { - alert('Scenario setting existed, import successfully with a new name: '+file_name); - } else { - alert('Scenario setting import successfully with name: '+file_name); - } - window.location = 'http://' - + window.location.host+"/scenario/" + file_name; - }, - error: function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }) - }); - - $("#launch_file").change(function () { - var fileObj = $(this)[0].files[0]; - if (typeof (fileObj) == "undefined" || fileObj.size <= 0) { - alert("Upload error."); - return; - } - var file_name = $(this).val(); - - var formFile = new FormData(); - formFile.append("name", file_name); - formFile.append("file", fileObj); - - $.ajax({ - url: "../upload_launch", - data: formFile, - type: "Post", - dataType: "json", - cache: false, - processData: false, - contentType: false, - success: function (result) { - console.log(result); - status = result.status; - if (status!='success') { - alert(status); - return; - } - error_list = result.error_list; - file_name = result.file_name; - rename = result.rename - if(result.rename==true) { - alert('Launch setting existed, import successfully with a new name: '+file_name); - } else { - alert('Launch setting import successfully with name: '+file_name); - } - window.location = 'http://' - + window.location.host+"/launch/" + file_name; - }, - error: function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }) - }); - - $("select#board_info").change(function(){ - data = {board_info: $(this).val()}; - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../select_board", - data : JSON.stringify(data), - success : function(result) { - console.log(result); - window.location = 'http://'+ window.location.host+"/scenario"; - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - } - }); - }); - - $("input").on('blur',function(){ - $(this).parents(".form-group").removeClass("has-error"); - $(this).parents(".form-group").children("p").text(""); - }); - - $("select").on('changed.bs.select',function(){ - $(this).parents(".form-group").removeClass("has-error"); - $(this).parents(".form-group").children("p").text(""); - }) - - $('#save_board').on('click', function() { - save_board(); - }); - - $('#save_scenario').on('click', function() { - var name = $(this).data('id'); - if(name=="generate_config_src") { - save_scenario(name); - } - else { - save_scenario(); - } - }); - - $('#remove_scenario').on('click', function() { - old_scenario_name = $("#old_scenario_name").text(); - - var board_info = $("select#board_info").val(); - if (board_info==null || board_info=='') { - alert("Please select one board info before this operation."); - return; - } - - scenario_config = { - old_setting_name: $("#old_scenario_name").text(), - new_setting_name: $("#new_scenario_name").val() - } - - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../remove_setting", - data : JSON.stringify(scenario_config), - success : function(result) { - console.log(result); - status = result.status - info = result.info - if (status == 'success') { - alert('Remove current scenario setting from acrn-config app successfully.'); - window.location = window.location = 'http://' - + window.location.host+"/scenario"; - } else { - alert('Remove current scenario setting from acrn-config app failed:\n'+info); - } - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); - }); - - $('#save_launch').on('click', function() { - var name = $(this).data('id'); - if(name=="generate_launch_script") { - save_launch(name); - } - else { - save_launch(); - } - }); - - $('#remove_launch').on('click', function() { - old_launch_name = $("#old_launch_name").text(); - - var board_info = $("select#board_info").val(); - if (board_info==null || board_info=='') { - alert("Please select one board before this operation."); - return; - } - - launch_config = { - old_setting_name: $("#old_launch_name").text(), - new_setting_name: $("#new_launch_name").val(), - } - - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../remove_setting", - data : JSON.stringify(launch_config), - success : function(result) { - console.log(result); - status = result.status - info = result.info - if (status == 'success') { - alert('Remove current launch setting from acrn-config app successfully.'); - window.location = window.location = 'http://' - + window.location.host+"/launch"; - } else { - alert('Remove current launch setting from acrn-config app failed:\n'+info); - } - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); - }); - - $('#export_scenario_xml').on('click', function() { - var dataId = $(this).data('id'); - $("#save_scenario").data('id', dataId); - }); - - $('#generate_config_src').on('click', function() { - var dataId = $(this).data('id'); - $("#save_scenario").data('id', dataId); - $('#src_path_row').removeClass('hidden'); - }); - - $('#export_launch_xml').on('click', function() { - var dataId = $(this).data('id'); - $("#save_launch").data('id', dataId); - }); - - - $('#generate_launch_script').on('click', function() { - var dataId = $(this).data('id'); - $("#save_launch").data('id', dataId); - $('#src_path_row').removeClass('hidden'); - }); - - $('a.create_menu').on('click', function() { - var type = $(this).data('id'); - $("#createModalLabel").text("Create a new " + type + " setting"); - var date = new Date(); - $("#create_name").val(date.getTime()); - $("#create_btn").data('id', type); - }); - - $('#create_btn').on('click', function() { - var type = $(this).data('id'); - var create_name = $("#create_name").val(); - create_setting(type, create_name, create_name, 'create'); - }); - - $(document).on('change', "select#load_scenario_name", function() { - $('input#load_scenario_name2').val(this.value); - }); - - $(document).on('change', "select#load_launch_name", function() { - $('input#load_launch_name2').val(this.value); - }); - - $('#load_scenario_btn').on('click', function() { - var type = $(this).data('id'); - var default_load_name = $("#load_scenario_name").val(); - var load_name = $("#load_scenario_name2").val(); - create_setting(type, default_load_name, load_name, 'load') - }); - - $('#load_launch_btn').on('click', function() { - var type = $(this).data('id'); - var default_load_name = $("#load_launch_name").val(); - var load_name = $("#load_launch_name2").val(); - create_setting(type, default_load_name, load_name, 'load') - }); - - $(document).on('click', "#add_vm", function() { - var curr_vm_id = $(this).data('id'); - $("#add_vm_submit").data('id', curr_vm_id); - }); - - $(document).on('click', "#add_vm_submit", function() { - var curr_vm_id = $(this).data('id'); - save_scenario('add_vm:'+curr_vm_id) - }); - - $(document).on('click', "#remove_vm", function() { - var remove_confirm_message = 'Do you want to delete this VM?' - if(confirm(remove_confirm_message)) { - var curr_vm_id = $(this).data('id'); - save_scenario('remove_vm:'+curr_vm_id) - } - }); - - $(document).on('click', "#add_launch_vm", function() { - var curr_vm_id = $(this).data('id'); - $("#add_launch_submit").data('id', curr_vm_id); - }); - - $(document).on('click', "#add_launch_submit", function() { - var curr_vm_id = $(this).data('id'); - save_launch('add_vm:'+curr_vm_id); - }); - - $('#add_launch_script').on('click', function() { - var curr_vm_id = $(this).data('id'); - $("#add_launch_submit").data('id', curr_vm_id); - }); - - $(document).on('click', "#remove_launch_vm", function() { - var remove_confirm_message = 'Do you want to delete this VM?' - if(confirm(remove_confirm_message)) { - var curr_vm_id = $(this).data('id'); - save_launch('remove_vm:'+curr_vm_id) - } - }); - - $(document).on('change', "select#scenario_name", function() { - data = {scenario_name: $(this).val(), - launch_name: $('text#old_launch_name').text()}; - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../get_post_launch_vms", - data : JSON.stringify(data), - success : function(result) { - console.log(result); - vm_list = result.vm_list - $('select#add_launch_type').empty().selectpicker('refresh'); - for(i in vm_list) { - var option = vm_list[i][1]+' ( ID : '+vm_list[i][0]+' )' - $('select#add_launch_type').append( - '').selectpicker('refresh'); - } - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - } - }); - }); - - $("select[ID$='vuart:id=1,base']").change(function(){ - var id = $(this).attr('id'); - var value = $(this).val(); - show_com_target(id, value); - }); - - $("select[ID$='vuart:id=1,base']").each(function(index, item) { - var id = $(item).attr('id'); - var value = $(item).val(); - show_com_target(id, value); - }); - - $(document).on('change', "select[ID*='communication_vuart'][ID$='base']", function() { - var id = $(this).attr('id'); - var value = $(this).val(); - show_com_target(id, value); - }); - - $("select[ID*='communication_vuart'][ID$='base']").each(function(index, item) { - var id = $(item).attr('id'); - var value = $(item).val(); - show_com_target(id, value); - }); - - $(document).on('change', "select[ID$='vuart:id=0,base']", function() { - var id = $(this).attr('id'); - var value = $(this).val(); - if(value == 'COM1_BASE') { - id = id.replace('legacy_vuart', 'console_vuart'); - id = escape_str(id); - $('#'+id).val('INVALID_PCI_BASE').trigger('change'); - } else if(value == 'PCI_VUART') { - id = id.replace('console_vuart', 'legacy_vuart'); - id = escape_str(id); - $('#'+id).val('INVALID_COM_BASE').trigger('change'); - } - }); - - $(document).on('change', "select[ID$='vuart:id=1,base']", function() { - var id = $(this).attr('id'); - var value = $(this).val(); - - if(value == 'COM2_BASE') { - id = id.replace('legacy_vuart', 'communication_vuart'); - id = escape_str(id); - $('#'+id).val('INVALID_PCI_BASE').trigger('change'); - } else if(value == 'PCI_VUART') { - id = id.replace('communication_vuart', 'legacy_vuart'); - id = escape_str(id); - $('#'+id).val('INVALID_COM_BASE').trigger('change'); - } - }); - - $(document).on('change', "select[ID^='user_vm'][ID$='vuart0']", function() { - var id = $(this).attr('id'); - var value = $(this).val(); - if(value == 'Enable') { - id = id.replace('vuart0', 'console_vuart'); - id = escape_str(id); - $('#'+id).val('Disable').trigger('change'); - } - }); - - $(document).on('change', "select[ID^='user_vm'][ID$='console_vuart']", function() { - var id = $(this).attr('id'); - var value = $(this).val(); - if(value == 'Enable') { - id = id.replace('console_vuart', 'vuart0'); - id = escape_str(id); - $('#'+id).val('Disable').trigger('change'); - } - }); - - $("select[ID$='FEATURES,RDT,CDP_ENABLED']").change(function(){ - var id = $(this).attr('id'); - var value = $(this).val(); - update_vcpu_clos_option(id, value); - update_rdt_clos_mask(id, value); - }); - - $("select[ID$='FEATURES,RDT,CDP_ENABLED']").each(function(index, item) { - var id = $(this).attr('id'); - var value = $(item).val(); - update_vcpu_clos_option(id, value); - update_rdt_clos_mask(id, value); - }); - - $(document).on('click', "button:contains('+')", function() { - if($(this).text() != '+') - return; - var curr_item_id = $(this).attr('id'); - var curr_id = curr_item_id.substr(curr_item_id.lastIndexOf('_')+1); - var config_item = $(this).parent().parent(); - var config_item_added = config_item.clone(); - var config_vm = config_item.parent(); - var vcpu_index_list = []; - var vuart_index_list = []; - config_vm.children().each(function(){ - if($(this).find("button:contains('+')").size() > 0) { - var btn_add_vm_id = $(this).find("button:contains('+')").attr('id'); - if(btn_add_vm_id.indexOf('add_communication_vuart')>=0) { - vuart_index_list.push(parseInt(btn_add_vm_id.substr(btn_add_vm_id.lastIndexOf('_')+1))); - } else { - vcpu_index_list.push(parseInt(btn_add_vm_id.substr(btn_add_vm_id.lastIndexOf('_')+1))); - } - } - }); - var id_added = -1; - if(curr_item_id.indexOf('add_communication_vuart')>=0) { - for (i=1; i<100; i++) { - if (!vuart_index_list.includes(i)) { - id_added = i; - break - } - } - } else { - for (i=0; i<100; i++) { - if (!vcpu_index_list.includes(i)) { - id_added = i; - break - } - } - } - - var id_pre_added = curr_item_id.substr(0, curr_item_id.lastIndexOf('_')); - config_item_added.find("button:contains('+')").attr('id', id_pre_added+'_'+id_added); - config_item_added.find("button:contains('-')").attr('id', id_pre_added.replace('add_', 'remove_')+'_'+id_added); - var curr_err_id = config_item_added.find("p").attr('id'); - config_item_added.find("p").attr('id', curr_err_id.replace(','+curr_id+'_', ','+id_added+'_')); - config_item_added.find("button:contains('-')").prop("disabled", false); - config_item_added.find('.bootstrap-select').replaceWith(function() { return $('select', this); }); - config_item_added.find('.selectpicker').val('default').selectpicker('deselectAll');; - config_item_added.find('.selectpicker').selectpicker('render'); - if(curr_item_id.indexOf('add_communication_vuart')>=0) { - var config_item_target_vm = config_item.next().clone(); - var config_item_target_vuart = config_item.next().next().clone(); - var curr_vuart_id = parseInt(curr_id); - config_item_added.find("label:first").text(config_item_added.find("label:first").html().replace(curr_vuart_id, id_added)); - var orig_id_list = ['base_label1', 'base_label2', 'base', 'base_err', - 'target_vm_id_label1', 'target_vm_id_label2', 'target_vm_id_config', 'target_vm_id', 'target_vm_id_err', - 'target_uart_id_label1', 'target_uart_id_label2', 'target_uart_id_config', 'target_uart_id', 'target_uart_id_err'] - for(var i = 0, len = 4; i < len; i++){ - var orig_base_item = config_item_added.find('[id$='+orig_id_list[i]+']') - orig_base_item.attr('id', orig_base_item.attr('id').replace(curr_vuart_id+','+orig_id_list[i], id_added+','+orig_id_list[i])) - } - for(var i = 4, len = 9; i < len; i++){ - var orig_target_vm_item = config_item_target_vm.find('[id$='+orig_id_list[i]+']') - orig_target_vm_item.attr('id', orig_target_vm_item.attr('id').replace(curr_vuart_id+','+orig_id_list[i], id_added+','+orig_id_list[i])) - } - for(var i = 9, len = orig_id_list.length; i < len; i++){ - var orig_target_vuart_item = config_item_target_vuart.find('[id$='+orig_id_list[i]+']') - orig_target_vuart_item.attr('id', orig_target_vuart_item.attr('id').replace(curr_vuart_id+','+orig_id_list[i], id_added+','+orig_id_list[i])) - } - config_item_added.insertAfter(config_item.next().next()); - config_item_target_vm.insertAfter(config_item_added); - config_item_target_vuart.insertAfter(config_item_target_vm); - } else { - config_item_added.find("label:first").text(""); - config_item_added.insertAfter(config_item); - } - - if(curr_item_id.indexOf('add_vcpu')>=0) { - var config_vm = config_item.parent(); - var curr_vcpu_index = vcpu_index_list.indexOf(parseInt(curr_id)) - var vcpu_clos_item = config_vm.find("label:contains('vcpu_clos')").first().parent(); - while(curr_vcpu_index > 0) { - vcpu_clos_item = vcpu_clos_item.next(); - curr_vcpu_index -= 1; - } - - var vcpu_clos_item_added = vcpu_clos_item.clone(); - vcpu_clos_item_added.find("label:first").text(""); - vcpu_clos_item_added.find('.bootstrap-select').replaceWith(function() { return $('select', this); }); - vcpu_clos_item_added.find('.selectpicker').val('default').selectpicker('deselectAll');; - vcpu_clos_item_added.find('.selectpicker').selectpicker('render'); - vcpu_clos_item_added.insertAfter(vcpu_clos_item); - } - }); - - $(document).on('click', "button:contains('-')", function() { - if($(this).text() != '-') - return; - var config_item = $(this).parent().parent(); - var curr_item_id = $(this).attr('id'); - if(curr_item_id.indexOf('remove_vcpu')>=0) { - var config_vm = config_item.parent(); - var vcpu_index_list = []; - config_vm.children().each(function(){ - if($(this).find("button:contains('+')").size() > 0) { - var btn_del_vm_id = $(this).find("button:contains('+')").attr('id'); - vcpu_index_list.push(parseInt(btn_del_vm_id.substr(btn_del_vm_id.lastIndexOf('_')+1))); - } - }); - var curr_item_id = $(this).attr('id'); - var curr_id = parseInt(curr_item_id.substr(curr_item_id.lastIndexOf('_')+1)); - curr_vcpu_index = vcpu_index_list.indexOf(curr_id); - - var vcpu_clos_item = config_vm.find("label:contains('vcpu_clos')").first().parent(); - while(curr_vcpu_index > 0) { - vcpu_clos_item = vcpu_clos_item.next(); - curr_vcpu_index -= 1; - } - vcpu_clos_item.remove(); - } - else if(curr_item_id.indexOf('remove_communication_vuart')>=0) { - config_item.next().next().remove(); - config_item.next().remove(); - } - config_item.remove(); - }); -}) - - -$(window).load(function () { -  $("select#scenario_name").change(); -}); - - -function escape_str(str) { - var jquerySpecialChars = ["~", "`", "@", "#", "%", "&", "=", "'", "\"", - ":", ";", "<", ">", ",", "/"]; - for (var i = 0; i < jquerySpecialChars.length; i++) { - str = str.replace(new RegExp(jquerySpecialChars[i], - "g"), "\\" + jquerySpecialChars[i]); - } - return str; -} - - -function show_com_target(id, value) { - - if(id==null || id=='undefined') { - return - } - var id2 = id.replace('base', 'target_vm_id'); - var id3 = id.replace('base', 'target_uart_id'); - id2 = escape_str(id2); - id3 = escape_str(id3); - if (value == 'INVALID_COM_BASE') { - $('#'+id2+'_label1').hide(); - $('#'+id2+'_label2').hide(); - $('#'+id2+'_config').hide(); - $('#'+id2+'_err').hide(); - } - else if(value == 'INVALID_PCI_BASE') { - $('#'+id2+'_label1').hide(); - $('#'+id2+'_label2').hide(); - $('#'+id2+'_config').hide(); - $('#'+id2+'_err').hide(); - $('#'+id3+'_label1').hide(); - $('#'+id3+'_label2').hide(); - $('#'+id3+'_config').hide(); - $('#'+id3+'_err').hide(); - } - else if(value == 'PCI_VUART') { - $('#'+id2+'_label1').show(); - $('#'+id2+'_label2').show(); - $('#'+id2+'_config').show(); - $('#'+id2+'_err').show(); - $('#'+id3+'_label1').show(); - $('#'+id3+'_label2').show(); - $('#'+id3+'_config').show(); - $('#'+id3+'_err').show(); - } - else { - $('#'+id2+'_label1').show(); - $('#'+id2+'_label2').show(); - $('#'+id2+'_config').show(); - $('#'+id2+'_err').show(); - } -} - - -function update_vcpu_clos_option(id, value) { - if(value == 'y') { - $("select[ID$='clos,vcpu_clos']").each(function(){ - len = $(this).find('option').length; - option = $(this).find('option').first(); - for(i=0; i(len-1)/2){ - option.attr('disabled','disabled'); - } - option = option.next(); - } - $(this).selectpicker('render'); - }); - } else { - $("select[ID$='clos,vcpu_clos']").each(function(){ - len = $(this).find('option').length; - option = $(this).find('option').first(); - for(i=0; i(len-1)/2){ - option.removeAttr('disabled'); - } - option = option.next(); - } - $(this).selectpicker('render'); - }); - } -} - -function update_rdt_clos_mask(id, value) { - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../get_num_of_rdt_res_entries", - data : JSON.stringify({'cdp_enabled': value}), - success : function(result) { - console.log(result); - num_clos_mask = result.num_clos_mask; - num_mba_delay = result.num_mba_delay; - clos_mask_entries = [null]; - index = 0; - $("input[ID$='hv,FEATURES,RDT,CLOS_MASK']").each(function(){ - index += 1; - if(index<=num_clos_mask) { - clos_mask_entries[0] = $(this).parent().parent(); - } - if(index>num_clos_mask) { - clos_mask_entries.push($(this).parent().parent()); - } - }); - if(index<=num_clos_mask) { - last_clos_mask_entry = clos_mask_entries[0]; - for(i=0; i0; i--) { - clos_mask_entries[i].remove(); - } - } - mba_delay_entries = [null]; - index = 0; - $("input[ID$='hv,FEATURES,RDT,MBA_DELAY']").each(function(){ - index += 1; - if(index<=num_mba_delay) { - mba_delay_entries[0] = $(this).parent().parent(); - } - if(index>num_mba_delay) { - mba_delay_entries.push($(this).parent().parent()); - } - }); - if(index<=num_mba_delay) { - last_mba_delay_entry = mba_delay_entries[0]; - for(i=0; i0; i--) { - mba_delay_entries[i].remove(); - } - } - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.responseText); - } - }); -} - -function create_setting(type, default_name, name, mode){ - var board_info = $("text#board_type").text(); - if (board_info==null || board_info=='') { - alert("Please select one board info before this operation."); - return; - } - - create_config = { - board_info: board_info, - type: type, - default_name: default_name, - create_name: name, - src_path: '', - mode: mode - } - - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../check_setting_exist", - data : JSON.stringify(create_config), - success : function(result) { - exist = result.exist - create_flag = true - if(exist == "yes") { - overwrite_confirm_message = 'Setting name: ' + create_config['create_name'] + ' existed in ' + - 'acrn-hypervisor/../user_config/'+board_info+'/.\n'+ - 'Do you want to overwrite it?\nClick OK to overwrite it; click Cancel to rename it.' - if(!confirm(overwrite_confirm_message)) { - create_flag = false - } - } - if(create_flag == true) { - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../create_setting", - data : JSON.stringify(create_config), - success : function(result) { - console.log(result); - status = result.status - setting = result.setting - error_list = result.error_list - if (status == 'success' && (JSON.stringify(error_list)=='{}' || JSON.stringify(error_list)=='null')) { - alert('create a new setting successfully.'); - } else { - alert('create a new setting failed. \nError list:\n'+JSON.stringify(error_list)); - } - var href = window.location.href - if(href.endsWith("/scenario") || href.endsWith("/launch")) { - window.location = type + "/" + setting; - } else { - window.location = "../" + type + "/" + setting; - } - }, - error : function(e){ - $("#create_modal").modal("hide"); - $("#load_scenario_modal").modal("hide"); - $("#load_launch_modal").modal("hide"); - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); - } - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); - -} - - -function save_scenario(generator=null){ - var board_info = $("text#board_type").text(); - if (board_info==null || board_info=='') { - alert("Please select one board info before this operation."); - return; - } - - scenario_config = { - old_scenario_name: $("#old_scenario_name").text(), - generator: generator - } - - if(generator!=null && generator.indexOf('add_vm:')==0) { - scenario_config['new_scenario_name'] = $("#new_scenario_name2").val() - } else if(generator!=null && generator.indexOf('remove_vm:')==0) { - scenario_config['new_scenario_name'] = $("#old_scenario_name").text() - } else { - scenario_config['new_scenario_name'] = $("#new_scenario_name").val() - } - - $("input").each(function(){ - var id = $(this).attr('id'); - var value = $(this).val(); - if(id.indexOf('CLOS_MASK')>=0 || id.indexOf('MBA_DELAY')>=0 || id.indexOf('IVSHMEM_REGION')>=0) { - if(id in scenario_config) { - scenario_config[id].push(value); - } else { - scenario_config[id] = [value]; - } - } else if(id!='new_scenario_name' && id!='new_scenario_name2' && id!='board_info_file' && id!='board_info_upload' - && id!='scenario_file' && id!='create_name' && id!='load_scenario_name2' && id!='load_launch_name2') { - scenario_config[id] = value; - } - }) - - $("textarea").each(function(){ - var id = $(this).attr('id'); - var value = $(this).val(); - scenario_config[id] = value; - }) - - $("select").each(function(){ - var id = $(this).attr('id'); - var value = $(this).val(); - if(id.indexOf('pcpu_id')>=0 || id.indexOf('pci_dev')>=0 || id.indexOf('vcpu_clos')>=0) { - if(id in scenario_config) { - scenario_config[id].push(value); - } else { - scenario_config[id] = [value]; - } - } else if(id!='board_info' && id!='load_scenario_name' && id!='load_launch_name') { - scenario_config[id] = value; - } - }) - - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../check_setting_exist", - data : JSON.stringify(scenario_config), - success : function(result) { - exist = result.exist - create_flag = true - if(exist == "yes") { - overwrite_confirm_message = 'Setting name: ' + ' existed in current setting ' + - 'acrn-hypervisor/../user_config/'+board_info+'/.\n'+ - 'Do you want to overwrite it?\nClick OK to overwrite it; click Cancel to rename it.' - if(!confirm(overwrite_confirm_message)) { - create_flag = false - } - } - if(create_flag == true) { - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../save_scenario", - data : JSON.stringify(scenario_config), - success : function(result) { - error_list = result.error_list; - status = result.status; - var no_err = true; - $.each(error_list, function(index,item){ - no_err = false; - index = escape_str(index) - $("#"+index+"_err").parents(".form-group").addClass("has-error"); - $("#"+index+"_err").text(item); - }) - if(no_err == true && status == 'success') { - var src_path = $("input#src_path").val(); - if(src_path == null || src_path == '') { - xml_path = 'acrn-hypervisor/../user_config/'+board_info+'/.' - } else { - xml_path = src_path - } - file_name = result.file_name; - validate_message = 'Scenario setting saved successfully with name: ' - +file_name+'\ninto '+xml_path; - if(result.rename==true) { - validate_message = 'Scenario setting existed, saved successfully with a new name: ' - +file_name+'\ninto acrn-hypervisor/../user_config/'+board_info+'/.'; - } - if(generator=="generate_config_src") { - generate_flag = true; - if(src_path == null || src_path == '') { - overwrite_confirm_message = 'The Source Path for configuration files is not set.\n' + - 'Do you want to generate them into the default path: acrn-hypervisor/build/hypervisor/configs/board/ and acrn-hypervisor/build/hypervisor/configs/scenarios/,\n'+ - 'and overwrite the old ones?\nClick OK to overwrite them; click Cancel to edit the Source Path.' - if(!confirm(overwrite_confirm_message)) { - generate_flag = false - } - } - if(generate_flag) { - generator_config = { - type: generator, - board_info: $("select#board_info").val(), - board_setting: "board_setting", - scenario_setting: file_name, - src_path: src_path, - } - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../generate_src", - data : JSON.stringify(generator_config), - success : function(result) { - console.log(result); - status = result.status - error_list = result.error_list - if (status == 'success' && (JSON.stringify(error_list)=='{}' || JSON.stringify(error_list)=='null')) { - if(src_path==null || src_path=='') { - alert(generator+' successfully into acrn-hypervisor/build/hypervisor/configs/board/ and acrn-hypervisor/build/hypervisor/configs/scenarios/ '); - } else { - alert(generator+' successfully into '+src_path); - } - } else { - alert(generator+' failed. \nError list:\n'+JSON.stringify(error_list)); - } - window.location = "./" + file_name; - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); - } - } else { - alert(validate_message); - window.location = "./" + file_name; - } - } - else { - $("#save_modal").modal("hide"); - alert(JSON.stringify(error_list)); - } - }, - error : function(e){ - $("#save_modal").modal("hide"); - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); - } - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); -} - -function save_launch(generator=null) { - var board_info = $("text#board_type").text(); - var scenario_name = $("select#scenario_name").val(); - if (board_info==null || board_info=='' || scenario_name==null || scenario_name=='') { - alert("Please select one board and scenario before this operation."); - return; - } - - launch_config = { - old_launch_name: $("#old_launch_name").text(), - scenario_name: scenario_name, - generator: generator - } - - if(generator!=null && generator.indexOf('add_vm:')==0) { - launch_config['new_launch_name'] = $("#new_launch_name2").val() - } else if(generator!=null && generator.indexOf('remove_vm:')==0) { - launch_config['new_launch_name'] = $("#old_launch_name").text() - } else { - launch_config['new_launch_name'] = $("#new_launch_name").val() - } - - $("input").each(function(){ - var id = $(this).attr('id'); - var value = $(this).val(); - - if(id.indexOf('virtio_devices,network')>=0 || id.indexOf('virtio_devices,block')>=0 - || id.indexOf('virtio_devices,input')>=0) { - if(id in launch_config) { - launch_config[id].push(value); - } else { - launch_config[id] = [value]; - } - } else if(id!='new_launch_name' && id!='new_launch_name2' && id!='board_info_file' && id!='board_info_upload' - && id!="launch_file" && id!='create_name' && id!='load_scenario_name2' && id!='load_launch_name2') { - launch_config[id] = value; - } - }) - - $("select").each(function(){ - var id = $(this).attr('id'); - var value = $(this).val(); - if(id.indexOf('pcpu_id')>=0 || id.indexOf('shm_region')>=0 - || id.indexOf('communication_vuart')>=0 || id.indexOf('pci_dev')>=0) { - if(id in launch_config) { - launch_config[id].push(value); - } else { - launch_config[id] = [value]; - } - } else if(id!='board_info' && id!='load_scenario_name' && id!='load_launch_name') { - launch_config[id] = value; - } - }) - - $("textarea").each(function(){ - var id = $(this).attr('id'); - var value = $(this).val(); - launch_config[id] = value; - }) - - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../check_setting_exist", - data : JSON.stringify(launch_config), - success : function(result) { - exist = result.exist - create_flag = true - if(exist == "yes") { - overwrite_confirm_message = 'Setting name: existed in the XML path\n'+ - 'Do you want to overwrite it?\nClick OK to overwrite it; click Cancel to rename it.' - if(!confirm(overwrite_confirm_message)) { - create_flag = false - } - } - if(create_flag == true) { - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../save_launch", - data : JSON.stringify(launch_config), - success : function(result) { - console.log(result); - error_list = result.error_list; - status = result.status; - - var no_err = true; - $.each(error_list, function(index,item){ - no_err = false; - index = escape_str(index); - $("#"+index).parents(".form-group").addClass("has-error"); - $("#"+index+"_err").text(item); - }) - if(no_err == true && status == 'success') { - var src_path = $("input#src_path").val(); - if(src_path == null || src_path == '') { - xml_path = 'acrn-hypervisor/../user_config/'+board_info+'/.' - } else { - xml_path = src_path - } - file_name = result.file_name; - validate_message = 'Launch setting saved successfully with name: ' - +file_name+'\nto '+xml_path; - if(result.rename==true) { - validate_message = 'Launch setting existed, saved successfully with a new name: ' - +file_name+'\nto '+xml_path; - } - if(generator == 'generate_launch_script') { - generate_flag = true; - if(src_path == null || src_path == '') { - overwrite_confirm_message = 'The Source Path for launch scripts is not set.\n' + - 'Do you want to generate them into the default path: acrn-hypervisor/../user_config/'+board_info+'/output/,\n'+ - 'and overwrite the old ones?\nClick OK to overwrite them; click Cancel to edit the Source Path.' - if(!confirm(overwrite_confirm_message)) { - generate_flag = false - } - } - if(generate_flag) { - generator_config = { - type: generator, - board_info: $("select#board_info").val(), - board_setting: "board_setting", - scenario_setting: $("select#scenario_name").val(), - launch_setting: file_name, - src_path: src_path, - } - $.ajax({ - type : "POST", - contentType: "application/json;charset=UTF-8", - url : "../generate_src", - data : JSON.stringify(generator_config), - success : function(result) { - console.log(result); - status = result.status - error_list = result.error_list - if (status == 'success' && (JSON.stringify(error_list)=='{}' || JSON.stringify(error_list)=='null')) { - if(src_path==null || src_path==='') { - alert(generator+' successfully into '+ - 'acrn-hypervisor/../user_config'+board_info+'/output/.'); - } else { - alert(generator+' successfully into '+src_path); - } - } else { - alert(generator+' failed. \nError list:\n'+JSON.stringify(error_list)); - } - window.location = "./" + file_name; - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); - } - } else { - alert(validate_message); - window.location = "./" + file_name; - } - } - else { - $("#save_modal").modal("hide"); - alert(JSON.stringify(error_list)); - } - }, - error : function(e){ - $("#save_modal").modal("hide"); - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); - } - }, - error : function(e){ - console.log(e.status); - console.log(e.responseText); - alert(e.status+'\n'+e.responseText); - } - }); -} diff --git a/misc/config_tools/config_app/static/styles.css b/misc/config_tools/config_app/static/styles.css deleted file mode 100644 index 28c600123..000000000 --- a/misc/config_tools/config_app/static/styles.css +++ /dev/null @@ -1,8 +0,0 @@ -* { - font-size: 12px; - line-height: 1.428; -} - -ul.nav li.dropdown:hover ul.dropdown-menu { - display: block; -} diff --git a/misc/config_tools/config_app/templates/base.html b/misc/config_tools/config_app/templates/base.html deleted file mode 100644 index 8c240da42..000000000 --- a/misc/config_tools/config_app/templates/base.html +++ /dev/null @@ -1,210 +0,0 @@ - - - - - - {% block title %}{% endblock %} - - - - - - - - - - - - - - - - - - -
-
- -
- -
- - {{board_type if board_type != None else ''}} -
- - - - -
-
-
- - {{bios_info if bios_info != None else ''}} - - {{base_board_info if base_board_info != None else ''}} -
- -
- -{% block body_content %} - -{% endblock %} - - - - diff --git a/misc/config_tools/config_app/templates/launch.html b/misc/config_tools/config_app/templates/launch.html deleted file mode 100644 index 0ecd55f7e..000000000 --- a/misc/config_tools/config_app/templates/launch.html +++ /dev/null @@ -1,407 +0,0 @@ -{% extends 'base.html' %} - -{% block body_content %} - - - - - -
-
- -
- {{launch}} -
-
- {% if board_info != None %} - - - {% else %} - - - {% endif %} -
- {% if board_info != None and root != None %} -
- -
-
- -
- {% else %} -
- -
-
- -
- {% endif %} -
-
- - -
- - {% if board_info != None and root != None %} - - {% for vm in root|list %} - - - - - {% endfor %} - -
-
- - -
-
- - -
-
- -
-
- -
-
- {% for elem in vm|list %} - {% if elem|list == [] and ('configurable' not in elem.attrib or elem.attrib['configurable'] != - '0') %} -
- - - {% set elem_text = '' if elem.text == None else elem.text %} - {% if ','.join(['user_vm', elem.tag]) not in launch_item_values %} -
- {% if 'readonly' in elem.attrib and elem.attrib['readonly'] == 'true' %} - {% if elem.tag == 'kernel_cmdline' %} - - {% else %} - - {% endif %} - {% else %} - {% if elem.tag == 'kernel_cmdline' %} - - {% else %} - - {% endif %} - {% endif %} -
- {% else %} - - {% endif %} -

-
- {% elif elem|list != [] %} - {% if 'multiselect' not in elem.attrib or elem.attrib['multiselect'] != 'true' %} - {% set first_multi_child = {'block': 0, 'network': 0, 'input': 0, 'pcpu_id': 0, 'shm_region': 0, - 'passthrough_devices': 0, 'virtio_devices': 0, 'sriov_devices': 0, 'communication_vuart': 0} %} - {% for sub_elem in elem|list %} - {% set sub_elem_text = '' if sub_elem.text == None else sub_elem.text %} - {% if 'configurable' not in sub_elem.attrib or sub_elem.attrib['configurable'] != '0' %} -
- {% if 'id' not in elem.attrib %} - {% if elem.tag in first_multi_child.keys() and first_multi_child[elem.tag] == 0 %} - - {% do first_multi_child.update({elem.tag: first_multi_child[elem.tag]+1}) %} - {% elif sub_elem.tag in ['pcpu_id', 'shm_region', 'communication_vuart'] and first_multi_child[sub_elem.tag] == 0 %} - - {% else %} - - {% endif %} - - - - {% if ','.join(['user_vm', elem.tag, sub_elem.tag]) not in launch_item_values - and elem.tag not in ['cpu_affinity', 'shm_regions', 'communication_vuarts']%} -
- {% if 'readonly' in sub_elem.attrib and sub_elem.attrib['readonly'] == 'true' %} - - {% else %} - - {% endif %} -
- - {% if elem.tag in ['virtio_devices'] and sub_elem.tag in ['block', 'network', 'input'] %} -
- - {% if first_multi_child[sub_elem.tag] == 0 %} - - {% else %} - - {% endif %} -
- {% do first_multi_child.update({sub_elem.tag: first_multi_child[sub_elem.tag]+1}) %} - {% endif%} - - {% else %} - - {% if elem.tag == 'cpu_affinity' %} - {% set item_key = ','.join(['user_vm', elem.tag]) %} - {% elif elem.tag in ['shm_regions', 'communication_vuarts'] %} - {% set item_key = ','.join(['user_vm:id='+vm.attrib['id'], elem.tag, sub_elem.tag]) %} - {% else %} - {% set item_key = ','.join(['user_vm', elem.tag, sub_elem.tag]) %} - {% endif %} - - {% endif %} -

- {% else %} - {% if elem.tag in first_multi_child.keys() and first_multi_child[elem.tag] == 0 %} - {% do first_multi_child.update({elem.tag: first_multi_child[elem.tag]+1}) %} - - {% else %} - - {% endif %} - - - - {% if ','.join(['user_vm', elem.tag, sub_elem.tag]) not in launch_item_values %} -
- {% if 'readonly' in sub_elem.attrib and sub_elem.attrib['readonly'] == 'true' %} - - {% else %} - - {% endif %} -
- {% else %} - -

- {% endif %} - {% endif %} -
- {% endif %} - {% endfor %} - {% elif 'configurable' not in elem.attrib or elem.attrib['configurable'] != '0' %} -
- - - -

-
- {% endif %} - {% endif %} - {% endfor %} -
- -
- {% else %} - No setting available. Select one board info and make sure the launch xml - exists. - - {% endif %} -
- -{% endblock %} diff --git a/misc/config_tools/config_app/templates/scenario.html b/misc/config_tools/config_app/templates/scenario.html deleted file mode 100644 index c0e3597a3..000000000 --- a/misc/config_tools/config_app/templates/scenario.html +++ /dev/null @@ -1,482 +0,0 @@ -{% extends 'base.html' %} - -{% block body_content %} - - - - - -
-
- -
- {{scenario}} -
-
- {% if board_info != None %} - - - {% else %} - - - {% endif %} -
- {% if board_info != None and root != None and scenario_item_values %} -
- -
- {% else %} -
- -
- {% endif %} -
- - {% if board_info != None and root != None and scenario_item_values %} - - {% for vm in root|list %} - {% set first_multi_child = {'IVSHMEM_REGION': 0, 'communication_vuart': 1} %} - {% if xpath_dict['/'.join(['/acrn-config', vm.tag])]['configurable'] == 'y' or - vm.xpath(xpath_dict['/'.join(['/acrn-config', vm.tag])]['configurable'])%} - - - - - {% endif %} - {% endfor %} -
- {% if vm.tag != 'vm' %} - {% set vm_type = 'hv' %} -
- -
-
- -
- {% else %} - {% set vm_type = 'vm:id='+vm.attrib['id'] %} -
- - -
-
- -
-
- -
- {% endif %} -
- {% for elem in vm|list %} - {% set elem_text = elem.text if elem.text != None else '' %} - {% if elem|list == [] and (xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag])]['configurable'] - == 'y' or elem.xpath(xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag])]['configurable']))%} -
- - - - {% if ','.join([vm.tag, elem.tag]) not in scenario_item_values %} -
- {% if xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag])]['readonly'] == 'y' %} - - {% else %} - - {% endif %} -
- {% else %} - - {% endif %} -

-
- {% elif elem|list != [] and (xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag])]['configurable'] - == 'y' or elem.xpath(xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag])]['configurable']))%} - {% if xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag])]['multiselect'] != 'y' %} - {% set first_child = [] %} - {% for sub_elem in elem|list %} - {% set sub_elem_text = sub_elem.text if sub_elem.text != None else '' %} - - {% if sub_elem.tag in ['RDT', 'IVSHMEM', 'SSRAM'] %} - {% for sub_elem_2 in sub_elem|list %} - {% set sub_elem_2_text = sub_elem_2.text if sub_elem_2.text != None else '' %} - {% if ','.join([vm.tag, elem.tag, sub_elem.tag, sub_elem_2.tag]) in scenario_item_values %} -
- - - -

-
- {% else %} -
- - - {% if sub_elem_2.tag in ['IVSHMEM_REGION'] %} -
- {% else %} -
- {% endif %} - {% if xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag, sub_elem.tag, sub_elem_2.tag])]['readonly'] == 'y' %} - - {% else %} - - {% endif %} -
- {% if sub_elem_2.tag in ['IVSHMEM_REGION'] %} -
- - {% if first_multi_child[sub_elem_2.tag] == 0 %} - - {% else %} - - {% endif %} -
- {% do first_multi_child.update({sub_elem_2.tag: first_multi_child[sub_elem_2.tag]+1}) %} - {% endif%} - {% if sub_elem_2.tag in ['IVSHMEM_REGION'] %} -

- {% else %} -

- {% endif %} -
- {% endif %} - {% endfor %} - - {% else %} - - {% if xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag, sub_elem.tag])]['configurable'] == 'y' or - sub_elem.xpath(xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag, sub_elem.tag])]['configurable'])%} -
- {% if 'id' not in elem.attrib %} - {% if not first_child %} - - {% else %} - - {% endif %} - - - - {% if ','.join([vm.tag, elem.tag, sub_elem.tag]) not in scenario_item_values - and elem.tag != 'cpu_affinity' and elem.tag != 'pci_devs' %} - {% if sub_elem.tag in ['bootargs', 'kern_args'] %} -
- {% if xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag, sub_elem.tag])]['readonly'] == 'y' %} - - {% else %} - - {% endif %} -
- {% else %} -
- {% if xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag, sub_elem.tag])]['readonly'] == 'y' %} - - {% else %} - - {% endif %} -
- - {% endif %} - {% else %} - {% set item_key = ','.join([vm.tag, elem.tag, sub_elem.tag]) if elem.tag != 'cpu_affinity' - and elem.tag != 'pci_devs' else ','.join([vm.tag, elem.tag]) %} - - {% endif %} - {% do first_child.append(1) %} -

- {% else %} - {% if not first_child %} - {% do first_child.append(1) %} - - {% else %} - - {% endif %} - - - {% if (','.join([vm.tag, elem.tag, sub_elem.tag]) not in scenario_item_values) and - ((elem.tag!='vuart' and elem.tag!='legacy_vuart') or sub_elem.tag!='base') %} -
- {% if xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag, sub_elem.tag])]['readonly'] == 'y' %} - - {% else %} - - {% endif %} -
- {% else %} - - - {% endif %} -

- {% endif %} -
- {% endif %} - {% endif %} - {% endfor %} - {% elif xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag])]['configurable'] == 'y' or - elem.xpath(xpath_dict['/'.join(['/acrn-config', vm.tag, elem.tag])]['configurable'])%} -
- - - -

-
- {% endif %} - {% endif %} - {% endfor %} -
- {% else %} - No setting available. Select one board info and make sure the scenario xml - exists. - - {% endif %} -
- -{% endblock %} diff --git a/misc/config_tools/config_app/views.py b/misc/config_tools/config_app/views.py deleted file mode 100644 index 6163f2139..000000000 --- a/misc/config_tools/config_app/views.py +++ /dev/null @@ -1,1338 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. -# SPDX-License-Identifier: BSD-3-Clause - -"""View pages for config app. - -""" - -import os, copy -from datetime import datetime -from shutil import copyfile, move - -# flask: Copyright 2010 Pallets -# SPDX-License-Identifier: BSD-3-Clause -# Refer to https://github.com/pallets/flask/blob/master/LICENSE.rst for the permission notice. -from flask import request, render_template, Blueprint, redirect, url_for, current_app - -# werkzeug: Copyright 2007 Pallets -# SPDX-License-Identifier: BSD-3-Clause -# Refer to https://github.com/pallets/werkzeug/blob/master/LICENSE.rst for the permission notice. -from werkzeug.utils import secure_filename - -import common -from controller import * -from scenario_config.scenario_cfg_gen import get_scenario_item_values -from scenario_config.scenario_cfg_gen import validate_scenario_setting -from launch_config.launch_cfg_gen import get_launch_item_values -from launch_config.launch_cfg_gen import validate_launch_setting -import scenario_config.default_populator as default_populator - - -CONFIG_APP = Blueprint('CONFIG_APP', __name__, template_folder='templates') - - -@CONFIG_APP.route('/') -def index(): - """ - render the index page - :return: the render template of index page - """ - return redirect(url_for('CONFIG_APP.scenarios')) - - -@CONFIG_APP.route('/scenario', methods=['GET']) -def scenarios(): - """ - render the scenario parent setting page - :return: the render template of scenario setting parent page - """ - board_info, board_type, scenario_config, launch_config = get_xml_configs() - (bios_info, base_board_info) = get_board_info(board_info) - scenario_list = ([], []) - launch_list = ([], []) - if board_type is not None: - default_xml_config = XmlConfig(os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), board_type)) - xml_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), board_type)) - generic_config_list = get_generic_config_list() - if default_xml_config.list_all(xml_type='scenario')[0]: - scenario_list = ( - default_xml_config.list_all(xml_type='scenario')[0], xml_config.list_all(xml_type='scenario')[0]) - else: - scenario_list = ( - generic_config_list[0], xml_config.list_all(xml_type='scenario')[0]) - if default_xml_config.list_all(xml_type='user_vm_launcher')[0]: - launch_list = ( - default_xml_config.list_all(xml_type='user_vm_launcher')[0], - xml_config.list_all(xml_type='user_vm_launcher')[0]) - else: - launch_list = ( - generic_config_list[1], xml_config.list_all(xml_type='user_vm_launcher')[0]) - - return render_template('scenario.html', board_info_list=get_board_list(), - board_info=board_info, board_type=board_type, - bios_info=bios_info, base_board_info=base_board_info, - scenarios=scenario_list, - launches=launch_list, - scenario='', root=None) - - -@CONFIG_APP.route('/scenario/', methods=['GET']) -def scenario(scenario_name): - """ - render the specified scenario setting page - :param scenario_name: the scenario type - :return: the render template of the specified scenario setting page - """ - - board_info, board_type, scenario_config, launch_config = get_xml_configs() - (bios_info, base_board_info) = get_board_info(board_info) - scenario_list = ([], []) - launch_list = ([], []) - if board_type is not None: - default_xml_config = XmlConfig(os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), board_type)) - xml_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), board_type)) - generic_config_list = get_generic_config_list() - if default_xml_config.list_all(xml_type='scenario')[0]: - scenario_list = ( - default_xml_config.list_all(xml_type='scenario')[0], xml_config.list_all(xml_type='scenario')[0]) - else: - scenario_list = ( - generic_config_list[0], xml_config.list_all(xml_type='scenario')[0]) - if default_xml_config.list_all(xml_type='user_vm_launcher')[0]: - launch_list = ( - default_xml_config.list_all(xml_type='user_vm_launcher')[0], - xml_config.list_all(xml_type='user_vm_launcher')[0]) - else: - launch_list = ( - generic_config_list[1], xml_config.list_all(xml_type='user_vm_launcher')[0]) - - xpath_dict = get_xpath_dict_of_xsd() - - current_app.config.update(SCENARIO=scenario_name) - - scenario_config.set_curr(scenario_name) - - scenario_item_values = {} - if board_info is not None and board_type is not None: - scenario_file_path = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, - scenario_name + '.xml') - if os.path.isfile(scenario_file_path): - scenario_item_values = get_scenario_item_values( - os.path.join(current_app.config.get('CONFIG_PATH'), board_type, board_info+'.xml'), - scenario_file_path) - for xpath in xpath_dict: - if xpath_dict[xpath]['enumeration'] and len(xpath.split('/')) > 2: - scenario_item_values[','.join(xpath.split('/')[2:])] = xpath_dict[xpath]['enumeration'] - - return render_template('scenario.html', board_info_list=get_board_list(), - board_info=board_info, board_type=board_type, - bios_info=bios_info, base_board_info=base_board_info, - scenarios=scenario_list, - launches=launch_list, - scenario=scenario_name, root=scenario_config.get_curr_root(), - scenario_item_values=scenario_item_values, - xpath_dict=xpath_dict) - - -@CONFIG_APP.route('/launch', methods=['GET']) -def launches(): - """ - render the parent launch setting page - :return: the render template of launch setting page - """ - board_info, board_type, scenario_config, launch_config = get_xml_configs() - (bios_info, base_board_info) = get_board_info(board_info) - scenario_list = ([], []) - launch_list = ([], []) - if board_type is not None: - default_xml_config = XmlConfig(os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), board_type)) - xml_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), board_type)) - generic_config_list = get_generic_config_list() - if default_xml_config.list_all(xml_type='scenario')[0]: - scenario_list = ( - default_xml_config.list_all(xml_type='scenario')[0], xml_config.list_all(xml_type='scenario')[0]) - else: - scenario_list = ( - generic_config_list[0], xml_config.list_all(xml_type='scenario')[0]) - if default_xml_config.list_all(xml_type='user_vm_launcher')[0]: - launch_list = ( - default_xml_config.list_all(xml_type='user_vm_launcher')[0], - xml_config.list_all(xml_type='user_vm_launcher')[0]) - else: - launch_list = ( - generic_config_list[1], xml_config.list_all(xml_type='user_vm_launcher')[0]) - - return render_template('launch.html', board_info_list=get_board_list(), - board_info=board_info, board_type=board_type, - bios_info=bios_info, base_board_info=base_board_info, - scenarios=scenario_list, - launches=launch_list, - launch='', root=None) - - -@CONFIG_APP.route('/launch/', methods=['GET']) -def launch(launch_name): - """ - render the specified launch setting page - :param launch_name: the launch type - :return: the render template of specified launch setting page - """ - board_info, board_type, scenario_config, launch_config = get_xml_configs() - (bios_info, base_board_info) = get_board_info(board_info) - scenario_list = ([], []) - launch_list = ([], []) - if board_type is not None: - default_xml_config = XmlConfig(os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), board_type)) - xml_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), board_type)) - generic_config_list = get_generic_config_list() - if default_xml_config.list_all(xml_type='scenario')[0]: - scenario_list = ( - default_xml_config.list_all(xml_type='scenario')[0], xml_config.list_all(xml_type='scenario')[0]) - else: - scenario_list = ( - generic_config_list[0], xml_config.list_all(xml_type='scenario')[0]) - if default_xml_config.list_all(xml_type='user_vm_launcher')[0]: - launch_list = ( - default_xml_config.list_all(xml_type='user_vm_launcher')[0], - xml_config.list_all(xml_type='user_vm_launcher')[0]) - else: - launch_list = ( - generic_config_list[1], xml_config.list_all(xml_type='user_vm_launcher')[0]) - - launch_config.set_curr(launch_name) - - launch_item_values = {} - scenario_name = launch_config.get_curr_root().attrib['scenario'] - current_app.config.update(SCENARIO=scenario_name) - scenario_name = current_app.config.get('SCENARIO') - scenario_file = None - if board_info is not None and scenario_name is not None: - scenario_file = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, - scenario_name+'.xml') - if not os.path.isfile(scenario_file): - scenario_file = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, - scenario_name + '.xml') - if not os.path.isfile(scenario_file): - scenario_file = None - launch_item_values = get_launch_item_values( - os.path.join(current_app.config.get('CONFIG_PATH'), board_type, board_info + '.xml'), scenario_file) - - scenario_name = None - launch_config_root = launch_config.get_curr_root() - if launch_config_root is not None and 'scenario' in launch_config_root.attrib: - scenario_name = launch_config_root.attrib['scenario'] - post_launch_vm_list = get_post_launch_vm_list(scenario_name) - - return render_template('launch.html', board_info_list=get_board_list(), - board_info=board_info, board_type=board_type, - bios_info=bios_info, base_board_info=base_board_info, - scenarios=scenario_list, - launches=launch_list, - launch=launch_name, root=launch_config.get_curr_root(), - scenario=current_app.config.get('SCENARIO'), - post_launch_vm_list=post_launch_vm_list, - launch_item_values=launch_item_values) - - -@CONFIG_APP.route('/save_scenario', methods=['POST']) -def save_scenario(): - """ - save scenario setting. - :return: the error list for the edited scenario setting. - """ - scenario_config_data = request.json if request.method == "POST" else request.args - xml_configs = get_xml_configs() - board_type = xml_configs[1] - scenario_config = xml_configs[3] - - common.MAX_VM_NUM = int(scenario_config_data['hv,CAPACITIES,MAX_VM_NUM']) - if board_type is None or xml_configs[0] is None: - return {'status': 'fail', - 'error_list': {'error': 'Please select the board info before this operation.'}} - - scenario_path = os.path.join(current_app.config.get('CONFIG_PATH'), board_type) - old_scenario_name = scenario_config_data['old_scenario_name'] - scenario_config.set_curr(old_scenario_name) - - for vm in list(scenario_config.get_curr_root()): - if vm.tag == 'vm': - for elem in list(vm): - if elem.tag in ['communication_vuart', 'console_vuart']: - vuart_key = vm.tag+':id='+vm.attrib['id']+','+elem.tag + ':id='+elem.attrib['id'] - delete_flag = True - for key in scenario_config_data: - if key.find(vuart_key) >= 0: - delete_flag = False - break - if delete_flag: - scenario_config.delete_curr_elem(*tuple(vuart_key.split(','))) - - for key in scenario_config_data: - if scenario_config_data[key] in [None, 'None']: - scenario_config_data[key] = '' - - if key not in ['old_scenario_name', 'new_scenario_name', 'generator', 'add_vm_type', 'src_path']: - if isinstance(scenario_config_data[key], list): - scenario_config.set_curr_list(scenario_config_data[key], *tuple(key.split(','))) - elif key.find('communication_vuart') >= 0: - try: - scenario_config.get_curr_elem(*tuple(key.split(','))) - except: - communication_vuart_id = key.split(',')[1].split('=')[1].strip() - communication_vuart_1_item = scenario_config.get_curr_elem( - *tuple([key.split(',')[0], 'communication_vuart:id=1'])) - communication_vuart_i_item = copy.deepcopy(communication_vuart_1_item) - communication_vuart_i_item.attrib['id'] = communication_vuart_id - curr_index = 0 - elem_list = list(scenario_config.get_curr_elem(key.split(',')[0])) - for elem in reversed(elem_list): - curr_index += 1 - if elem.tag in ['communication_vuart', 'console_vuart']: - break - scenario_config.insert_curr_elem(len(elem_list)-curr_index+1, communication_vuart_i_item, key.split(',')[0]) - finally: - scenario_config.set_curr_value(scenario_config_data[key], *tuple(key.split(','))) - else: - scenario_config.set_curr_value(scenario_config_data[key], *tuple(key.split(','))) - - # how to put added vuart under vuart!!! - # delete vuart without key!!! - - generator = scenario_config_data['generator'] - if generator is not None: - if generator.startswith('add_vm:'): - vm_list = [] - for vm in list(scenario_config.get_curr_root()): - if vm.tag == 'vm': - vm_list.append(vm.attrib['id']) - if len(vm_list) >= common.MAX_VM_NUM: - return {'status': 'fail', - 'error_list': {'error': 'Cannot add a new VM. hv.CAPACITIES.MAX_VM_NUM is currently set to {}.'.format(common.MAX_VM_NUM)}} - curr_vm_id = generator.split(':')[1] - add_vm_type = scenario_config_data['add_vm_type'] - add_scenario_config = get_generic_scenario_config(scenario_config, add_vm_type) - vm_to_add = [] - if str(curr_vm_id) == '-1': - curr_vm_index = 1 - else: - curr_vm_index = len(vm_list) + 1 - for i in range(len(vm_list)): - if curr_vm_id == vm_list[i]: - curr_vm_index = i + 2 - break - if add_scenario_config is not None and add_scenario_config.tag == 'vm': - for i in range(0, common.MAX_VM_NUM): - if str(i) not in vm_list: - break - add_scenario_config.attrib['id'] = str(i) - vm_to_add.append(add_scenario_config) - for vm in vm_to_add: - scenario_config.insert_curr_elem(curr_vm_index, vm) - curr_vm_index += 1 - assign_vm_id(scenario_config) - elif generator.startswith('remove_vm:'): - remove_vm_id = generator.split(':')[1] - scenario_config.delete_curr_key('vm:id='+remove_vm_id.strip()) - assign_vm_id(scenario_config) - - scenario_config.set_curr_attr('board', board_type) - scenario_config.set_curr_attr('scenario', scenario_config_data['new_scenario_name']) - - tmp_scenario_file = os.path.join(scenario_path, - 'tmp_'+scenario_config_data['new_scenario_name']+'.xml') - - scenario_config.save('tmp_'+scenario_config_data['new_scenario_name']) - - # call validate function - error_list = {} - new_scenario_name = scenario_config_data['new_scenario_name'] - rename = False - try: - if generator is None or not (generator.startswith('add_vm:') or generator.startswith('remove_vm:')): - (error_list, vm_info) = validate_scenario_setting( - os.path.join(current_app.config.get('CONFIG_PATH'), board_type, xml_configs[0]+'.xml'), - tmp_scenario_file) - except Exception as error: - if os.path.isfile(tmp_scenario_file): - os.remove(tmp_scenario_file) - return {'status': 'fail', 'file_name': new_scenario_name, - 'rename': rename, 'error_list': {'error': str(error)}} - - if not error_list: - scenario_config.save(new_scenario_name) - - if os.path.isfile(tmp_scenario_file): - os.remove(tmp_scenario_file) - - src_path = scenario_config_data['src_path'] - if src_path is not None and str(src_path).strip() != '': - if not os.path.isdir(src_path): - os.makedirs(src_path) - copyfile(os.path.join(scenario_path, scenario_config_data['new_scenario_name']+'.xml'), - os.path.join(src_path, scenario_config_data['new_scenario_name']+'.xml')) - - return {'status': 'success', 'file_name': new_scenario_name, - 'rename': rename, 'error_list': error_list} - - -@CONFIG_APP.route('/save_launch', methods=['POST']) -def save_launch(): - """ - save launch setting. - :return: the error list of the edited launch setting. - """ - launch_config_data = request.json if request.method == "POST" else request.args - xml_configs = get_xml_configs() - launch_config = xml_configs[3] - - if xml_configs[1] is None or xml_configs[0] is None: - return {'status': 'fail', - 'error_list': {'error': 'Please select the board info before this operation.'}} - - old_launch_name = launch_config_data['old_launch_name'] - launch_config.set_curr(old_launch_name) - scenario_name = launch_config_data['scenario_name'] - scenario_file_path = os.path.join(current_app.config.get('CONFIG_PATH'), - current_app.config.get('BOARD_TYPE'), - scenario_name + '.xml') - # update VM_COUNT and MAX_VM_NUM - common.get_vm_num(scenario_file_path) - - for key in launch_config_data: - if launch_config_data[key] in [None, 'None']: - launch_config_data[key] = '' - if key not in ['old_launch_name', 'new_launch_name', 'generator', 'add_launch_type', 'scenario_name', 'src_path']: - if isinstance(launch_config_data[key], list): - launch_config.set_curr_list(launch_config_data[key], *tuple(key.split(','))) - else: - launch_config.set_curr_value(launch_config_data[key], *tuple(key.split(','))) - - generator = launch_config_data['generator'] - if generator is not None: - if generator.startswith('add_vm:'): - vm_list = [] - for vm in list(launch_config.get_curr_root()): - if vm.tag == 'user_vm': - vm_list.append(vm.attrib['id']) - if len(vm_list) >= common.MAX_VM_NUM: - return { - 'status': 'fail', - 'error_list': { - 'error': 'Cannot add a new VM. hv.CAPACITIES.MAX_VM_NUM ' - 'is currently set to {}.'.format(common.MAX_VM_NUM) - } - } - curr_vm_id = generator.split(':')[1].strip() - add_launch_type = launch_config_data['add_launch_type'] - if add_launch_type is None or len(add_launch_type.split('ID :')) < 2: - return {'status': 'fail', - 'error_list': {'error': 'No VM is selected. ' - 'Please select a scenario with available post launched VMs.'}} - add_vm_id = add_launch_type.split('ID :')[1].replace(')', '').strip() - add_launch_type = 'LAUNCH_' + add_launch_type.split()[0] - add_launch_id = 1 - post_vm_list = get_post_launch_vm_list(scenario_name) - for i in range(len(post_vm_list)): - vm_info = post_vm_list[i] - if add_vm_id == vm_info[0]: - add_launch_id = i + 1 - break - add_launch_config = get_generic_scenario_config(launch_config, add_launch_type) - vm_to_add = [] - if str(curr_vm_id) == '-1': - curr_vm_index = len(vm_list) - else: - curr_vm_index = 0 - for i in range(len(vm_list)): - if curr_vm_id == vm_list[i]: - curr_vm_index = i + 1 - break - if add_launch_config is not None and add_launch_config.tag == 'user_vm': - for i in range(1, common.MAX_VM_NUM): - if str(i) not in vm_list: - break - add_launch_config.attrib['id'] = str(add_launch_id) - vm_to_add.append(add_launch_config) - - for vm in vm_to_add: - launch_config.insert_curr_elem(curr_vm_index, vm) - elif generator.startswith('remove_vm:'): - remove_vm_id = generator.split(':')[1] - launch_config.delete_curr_key('user_vm:id='+remove_vm_id.strip()) - - launch_config.set_curr_attr('scenario', scenario_name) - launch_config.set_curr_attr('board', current_app.config.get('BOARD_TYPE')) - - launch_config.set_curr_attr('user_vm_launcher', str(len(list(launch_config.get_curr_root())))) - - tmp_launch_file = os.path.join(current_app.config.get('CONFIG_PATH'), xml_configs[1], - 'tmp_' + launch_config_data['new_launch_name'] + '.xml') - - launch_config.save('tmp_' + launch_config_data['new_launch_name']) - - # call validate function - error_list = {} - rename = False - try: - if generator is None or not (generator.startswith('add_vm:') or generator.startswith('remove_vm:')): - (error_list, pthru_sel, virtio, dm_value, sriov) = validate_launch_setting( - os.path.join(current_app.config.get('CONFIG_PATH'), xml_configs[1], xml_configs[0]+'.xml'), - scenario_file_path, - tmp_launch_file) - except Exception as error: - if os.path.isfile(tmp_launch_file): - os.remove(tmp_launch_file) - return {'status': 'fail', 'file_name': launch_config_data['new_launch_name'], - 'rename': rename, 'error_list': {'launch config error': str(error)}} - - if not error_list: - launch_config.save(launch_config_data['new_launch_name']) - - if os.path.isfile(tmp_launch_file): - os.remove(tmp_launch_file) - - src_path = launch_config_data['src_path'] - if src_path is not None and str(src_path).strip() != '': - if not os.path.isdir(src_path): - os.makedirs(src_path) - copyfile(os.path.join(current_app.config.get('CONFIG_PATH'), current_app.config.get('BOARD_TYPE'), - launch_config_data['new_launch_name'] + '.xml'), - os.path.join(src_path, launch_config_data['new_launch_name'] + '.xml')) - - return {'status': 'success', 'file_name': launch_config_data['new_launch_name'], - 'rename': rename, 'error_list': error_list} - - -@CONFIG_APP.route('/check_setting_exist', methods=['POST']) -def check_setting_exist(): - """ - check the setting exist or not. - :return: setting exist or not. - """ - config_data = request.json if request.method == "POST" else request.args - src_path = config_data['src_path'] - - board_info = current_app.config.get('BOARD_TYPE') - setting_path = os.path.join(current_app.config.get('CONFIG_PATH'), board_info) - if src_path is not None and str(src_path).strip() != '': - setting_path = src_path - - if 'old_scenario_name' in list(config_data.keys()) and 'new_scenario_name' in list(config_data.keys()): - if config_data['old_scenario_name'] != config_data['new_scenario_name'] and \ - os.path.isfile(os.path.join(setting_path, config_data['new_scenario_name'] + '.xml')): - return {'exist': 'yes'} - else: - return {'exist': 'no'} - elif 'old_launch_name' in list(config_data.keys()) and 'new_launch_name' in list(config_data.keys()): - if config_data['old_launch_name'] != config_data['new_launch_name'] and \ - os.path.isfile(os.path.join(setting_path, config_data['new_launch_name'] + '.xml')): - return {'exist': 'yes'} - else: - return {'exist': 'no'} - elif 'create_name' in list(config_data.keys()): - if os.path.isfile(os.path.join(setting_path, config_data['create_name'] + '.xml')): - return {'exist': 'yes'} - else: - return {'exist': 'no'} - else: - return {'exist': 'no'} - - -@CONFIG_APP.route('/create_setting', methods=['POST']) -def create_setting(): - """ - create a new scenario or launch setting. - :return: the status and error list of the created scenario or launch setting. - """ - create_config_data = request.json if request.method == "POST" else request.args - mode = create_config_data['mode'] - default_name = create_config_data['default_name'] - create_name = create_config_data['create_name'] - src_path = create_config_data['src_path'] - setting_type = create_config_data['type'] - - xml_configs = get_xml_configs() - board_info = xml_configs[0] - board_type = xml_configs[1] - scenario_config = xml_configs[2] - launch_config = xml_configs[3] - - if board_type is None or xml_configs[0] is None: - return {'status': 'fail', - 'error_list': {'error': 'Please select the board info before this operation.'}} - - setting_path = os.path.join(current_app.config.get('CONFIG_PATH'), board_info) - if not os.path.isdir(setting_path): - os.makedirs(setting_path) - - if src_path is not None and str(src_path).strip() != '': - setting_path = src_path - if not os.path.isdir(setting_path): - os.makedirs(setting_path) - - if create_config_data['type'] == 'launch': - launch_file = os.path.join(setting_path, create_name + '.xml') - - if mode == 'create': - template_file_name = 'hybrid_launch_2user_vm' - src_file_name = os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), 'generic_board', template_file_name + '.xml') - else: #load - src_file_name = os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), board_type, default_name + '.xml') - if os.path.isfile(src_file_name): - if os.path.isfile(launch_file): - os.remove(launch_file) - copyfile(src_file_name, - os.path.join(current_app.config.get('CONFIG_PATH'), board_type, create_name + '.xml')) - - launch_config.set_curr(create_name) - if mode == 'create': - launch_config.delete_curr_key('user_vm:id=2') - launch_config.delete_curr_key('user_vm:id=1') - launch_config.save(create_name) - if os.path.normcase(setting_path) != os.path.normcase(os.path.join(current_app.config.get('CONFIG_PATH'), board_type)): - copyfile(os.path.join(current_app.config.get('CONFIG_PATH'), board_type, create_name + '.xml'), - os.path.join(setting_path, create_name + '.xml')) - return {'status': 'success', 'setting': create_name, 'error_list': {}} - - elif create_config_data['type'] == 'scenario': - scenario_file = os.path.join(setting_path, create_name + '.xml') - - if mode == 'create': - template_file_name = 'shared' - src_file_name = os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), 'generic_board', template_file_name + '.xml') - else: # load - src_file_name = os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), board_type, - default_name + '.xml') - if not os.path.isfile(src_file_name): - src_file_name=os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), 'generic_board', default_name + '.xml') - - if os.path.isfile(src_file_name): - xsd_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'schema', 'config.xsd') - out_xml = os.path.join(os.path.dirname(os.path.abspath(__file__)), create_name + '.xml') - default_populator.main(xsd_path, src_file_name, out_xml) - if os.path.isfile(scenario_file): - os.remove(scenario_file) - copyfile(out_xml, - os.path.join(current_app.config.get('CONFIG_PATH'), board_type, - create_name + '.xml')) - os.remove(out_xml) - - if mode == 'create': - # update RDT->CLOS_MASK according to board xml - scenario_config.set_curr(create_name) - elem_clos_max = scenario_config.get_curr_elem('hv', 'FEATURES', 'RDT', 'CLOS_MASK') - # elem_mba_delay = scenario_config.get_curr_elem('hv', 'FEATURES', 'RDT', 'MBA_DELAY') - scenario_config.delete_curr_elem('hv', 'FEATURES', 'RDT', 'CLOS_MASK') - # scenario_config.delete_curr_elem('hv', 'FEATURES', 'RDT', 'MBA_DELAY') - cdp_enabled = scenario_config.get_curr_value('hv', 'FEATURES', 'RDT', 'CDP_ENABLED') - (num_clos_mask, num_mba_delay) = get_num_of_rdt_res(board_info, cdp_enabled) - for i in range(num_clos_mask): - scenario_config.clone_curr_elem(elem_clos_max, 'hv', 'FEATURES', 'RDT') - # for i in range(num_mba_delay): - # scenario_config.clone_curr_elem(elem_mba_delay, 'hv', 'FEATURES', 'RDT') - for i in range(7): - scenario_config.delete_curr_key('vm:id={}'.format(i)) - scenario_config = set_default_config(scenario_config) - scenario_config.save(create_name) - if os.path.normcase(setting_path) != os.path.normcase(os.path.join(current_app.config.get('CONFIG_PATH'), board_type)): - copyfile(os.path.join(current_app.config.get('CONFIG_PATH'), board_type, create_name + '.xml'), - os.path.join(setting_path, create_name + '.xml')) - return {'status': 'success', 'setting': create_name, 'error_list': {}} - - else: - return {'status': 'fail', 'error_list': {'name': 'Unsupported setting type. '}} - - -@CONFIG_APP.route('/remove_setting', methods=['POST']) -def remove_setting(): - """ - remove current setting from config app - :return: the return message - """ - remove_config_data = request.json if request.method == "POST" else request.args - - old_setting_name = remove_config_data['old_setting_name'] - - if current_app.config.get('BOARD_TYPE') is None: - return {'status': 'Board info not set before remove current setting'} - - old_setting_path = os.path.join(current_app.config.get('CONFIG_PATH'), - current_app.config.get('BOARD_TYPE'), - old_setting_name + '.xml') - - if os.path.isfile(old_setting_path): - os.remove(old_setting_path) - return {'status': 'success'} - - -@CONFIG_APP.route('/generate_src', methods=['POST']) -def generate_src(): - """ - generate board src or scenario src - :return: the error message - """ - generator_config_data = request.json if request.method == "POST" else request.args - - src_type = generator_config_data['type'] - board_info = generator_config_data['board_info'] - board_type = current_app.config.get('BOARD_TYPE') - board_info_xml = os.path.join(current_app.config.get('CONFIG_PATH'), - board_type, board_info+'.xml') - scenario_setting = generator_config_data['scenario_setting'] - scenario_setting_xml = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, - scenario_setting+'.xml') - src_path = generator_config_data['src_path'] - if src_path is None or str(src_path).strip() == '': - src_path = os.path.join(current_app.config.get('CONFIG_PATH')) - launch_setting_xml = None - if 'launch_setting' in generator_config_data: - launch_setting = generator_config_data['launch_setting'] - launch_setting_xml = os.path.join(current_app.config.get('CONFIG_PATH'), - board_type, launch_setting + '.xml') - msg = {} - error_list = {} - status = 'success' - if src_type == 'generate_config_src': - try: - from board_config.board_cfg_gen import ui_entry_api - error_list = ui_entry_api(board_info_xml, scenario_setting_xml, src_path) - except Exception as error: - status = 'fail' - error_list = {'board setting error': str(error)} - - try: - from scenario_config.scenario_cfg_gen import ui_entry_api - error_list = ui_entry_api(board_info_xml, scenario_setting_xml, src_path) - except Exception as error: - status = 'fail' - error_list = {'scenario setting error': str(error)} - elif src_type == 'generate_launch_script': - scenario_setting_xml = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, - scenario_setting + '.xml') - - try: - from launch_config.launch_cfg_gen import ui_entry_api - error_list = ui_entry_api(board_info_xml, scenario_setting_xml, launch_setting_xml, src_path) - except Exception as error: - status = 'fail' - error_list = {'launch setting error': str(error)} - else: - status = 'fail' - error_list = {'error': 'generator type not specified'} - - msg = {'status': status, 'error_list': error_list} - return msg - - -@CONFIG_APP.route('/upload_board_info', methods=['POST']) -def upload_board_info(): - """ - upload board info xml file - :return: the upload status - """ - if request.method == 'POST': - if 'file' not in request.files: - return {'status': 'Error: no file uploaded'} - file = request.files['file'] - if file and '.' in file.filename and file.filename.rsplit('.', 1)[1] in ['xml']: - filename = secure_filename(file.filename) - tmp_filename = 'tmp_' + filename - config_path = current_app.config.get('CONFIG_PATH') - default_config_path = current_app.config.get('DEFAULT_CONFIG_PATH') - save_tmp_board_path = os.path.join(config_path, tmp_filename) - file.save(save_tmp_board_path) - - board_type_list = [] - for config_name in os.listdir(default_config_path): - if os.path.isdir(os.path.join(default_config_path, config_name)) \ - and config_name not in ['generic_board', 'sample_launch_scripts']: - board_type_list.append(config_name) - - board_info_config = XmlConfig(config_path) - board_info_config.set_curr(tmp_filename.rsplit('.', 1)[0]) - board_info_root = board_info_config.get_curr_root() - board_type = None - if board_info_root is not None and 'board' in board_info_root.attrib \ - and 'scenario' not in board_info_root.attrib \ - and 'user_vm_launcher' not in board_info_root.attrib: - board_type = board_info_root.attrib['board'] - if not board_type: - os.remove(save_tmp_board_path) - return {'status': 'Error on parsing Board info\n' - 'check the xml syntax and whether there is only the board ' - 'attribute in the board info file'} - - board_path =os.path.join(config_path, board_type) - if not os.path.isdir(board_path): - os.makedirs(board_path) - move(save_tmp_board_path, os.path.join(board_path, filename)) - info = 'updated' - if board_type not in board_type_list: - info = board_type - for generic_name in os.listdir(os.path.join(default_config_path, 'generic_board')): - generic_file = os.path.join(default_config_path, 'generic_board', generic_name) - if os.path.isfile(generic_file): - new_file = os.path.join(board_path, generic_name) - copyfile(generic_file, new_file) - xml_config = XmlConfig(board_path) - xml_config.set_curr(generic_name.rsplit('.', 1)[0]) - xml_config.set_curr_attr('board', board_type) - xml_config_root = xml_config.get_curr_root() - if 'scenario' not in xml_config_root.attrib and 'user_vm_launcher' not in xml_config_root.attrib: - os.remove(new_file) - continue - # update RDT->CLOS_MASK according to board xml - # if 'board' in xml_config_root.attrib and 'scenario' in xml_config_root.attrib \ - # and 'uos_launcher' not in xml_config_root.attrib: - # cdp_enabled = xml_config.get_curr_value('hv', 'FEATURES', 'RDT', 'CDP_ENABLED') - # (num_clos_mask, num_mba_delay) = \ - # get_num_of_rdt_res(filename.rsplit('.', 1)[0], cdp_enabled) - # elem_clos_max = xml_config.get_curr_elem('hv', 'FEATURES', 'RDT', 'CLOS_MASK') - # elem_mba_delay = xml_config.get_curr_elem('hv', 'FEATURES', 'RDT', 'MBA_DELAY') - # xml_config.delete_curr_elem('hv', 'FEATURES', 'RDT', 'CLOS_MASK') - # xml_config.delete_curr_elem('hv', 'FEATURES', 'RDT', 'MBA_DELAY') - # for i in range(num_clos_mask): - # xml_config.clone_curr_elem(elem_clos_max, 'hv', 'FEATURES', 'RDT') - # for i in range(num_mba_delay): - # xml_config.clone_curr_elem(elem_mba_delay, 'hv', 'FEATURES', 'RDT') - # xml_config = set_default_config(xml_config) - xml_config.save(generic_name.rsplit('.', 1)[0], user_defined=False) - - board_info = os.path.splitext(file.filename)[0] - current_app.config.update(BOARD_INFO=board_info) - current_app.config.update(BOARD_TYPE=board_type) - - return {'status': 'success', 'info': info} - - return {'status': 'Error: upload failed'} - - -@CONFIG_APP.route('/select_board', methods=['POST']) -def select_board(): - """ - select one board info - :return: the selected board info - """ - data = request.json if request.method == "POST" else request.args - board_info = data['board_info'] - current_app.config.update(BOARD_INFO=board_info) - - board_type = get_board_type(board_info) - current_app.config.update(BOARD_TYPE=board_type) - if board_type: - return board_type - - return '' - - -@CONFIG_APP.route('/upload_scenario', methods=['POST']) -def upload_scenario(): - """ - upload scenario setting xml file - :return: the upload status - """ - if request.method == 'POST': - if 'file' not in request.files: - return {'status': 'no file uploaded'} - file = request.files['file'] - if file and '.' in file.filename and file.filename.rsplit('.', 1)[1] in ['xml']: - filename = secure_filename(file.filename) - scenario_file_name = os.path.splitext(file.filename)[0] - board_type = current_app.config.get('BOARD_TYPE') - - tmp_scenario_name = 'tmp_' + scenario_file_name + '.xml' - tmp_scenario_file = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, tmp_scenario_name) - tmp_scenario_folder = os.path.dirname(tmp_scenario_file) - if not os.path.exists(tmp_scenario_folder): - os.makedirs(tmp_scenario_folder) - if os.path.isfile(tmp_scenario_file): - os.remove(tmp_scenario_file) - - file.save(tmp_scenario_file) - - tmp_xml_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), - board_type)) - tmp_xml_config.set_curr(tmp_scenario_name[:-4]) - status = None - if tmp_xml_config.get_curr_root() is None: - status = 'Error on parsing the scenario xml file, \n' \ - 'check the xml syntax and config items.' - else: - tmp_root = tmp_xml_config.get_curr_root() - if 'board' not in tmp_root.attrib or 'scenario' not in tmp_root.attrib \ - or 'user_vm_launcher' in tmp_root.attrib: - status = 'Invalid scenario xml file, \nonly board and scenario ' \ - 'need to be configured.' - elif tmp_root.attrib['board'] != current_app.config.get('BOARD_TYPE'): - status = 'Current board: {} mismatched with the board in the scenario file,' \ - '\nplease reselect or upload the board info: {}'\ - .format(current_app.config.get('BOARD_TYPE'), tmp_root.attrib['board']) - if status is not None: - if os.path.isfile(tmp_scenario_file): - os.remove(tmp_scenario_file) - return {'status': status} - - error_list = {} - new_scenario_name = scenario_file_name - rename = False - if not error_list: - new_scenario_path = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, - scenario_file_name + '.xml') - if os.path.isfile(new_scenario_path): - new_scenario_name = new_scenario_name + '_' \ - + datetime.now().strftime('%Y%m%d%H%M%S') - rename = True - - xsd_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'schema', 'config.xsd') - default_populator.main(xsd_path, tmp_scenario_file, tmp_scenario_file) - os.rename(tmp_scenario_file, os.path.join(current_app.config.get('CONFIG_PATH'), - board_type, new_scenario_name + '.xml')) - - return {'status': 'success', 'file_name': new_scenario_name, - 'rename': rename, 'error_list': error_list} - - return {'status': 'unsupported method'} - - -@CONFIG_APP.route('/upload_launch', methods=['POST']) -def upload_launch(): - """ - upload scenario setting xml file - :return: the upload status - """ - if request.method == 'POST': - if 'file' not in request.files: - return {'status': 'no file uploaded'} - file = request.files['file'] - if file and '.' in file.filename and file.filename.rsplit('.', 1)[1] in ['xml']: - filename = secure_filename(file.filename) - launch_file_name = os.path.splitext(file.filename)[0] - board_type = current_app.config.get('BOARD_TYPE') - - tmp_launch_name = 'tmp_' + launch_file_name + '.xml' - tmp_launch_file = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, - tmp_launch_name) - if os.path.isfile(tmp_launch_file): - os.remove(tmp_launch_file) - - file.save(tmp_launch_file) - - tmp_xml_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), - board_type)) - tmp_xml_config.set_curr(tmp_launch_name[:-4]) - status = None - if tmp_xml_config.get_curr_root() is None: - status = 'Error on parsing the scenario xml file, \n' \ - 'check the xml syntax and config items.' - else: - tmp_root = tmp_xml_config.get_curr_root() - if 'board' not in tmp_root.attrib or 'scenario' not in tmp_root.attrib \ - or 'user_vm_launcher' not in tmp_root.attrib: - status = 'Invalid launch xml file, \nboard, scenario,' \ - 'and user_vm_launcher need to be configured.' - elif tmp_root.attrib['board'] != current_app.config.get('BOARD_TYPE'): - status = 'Current board: {} mismatched with the board in the launch file,' \ - '\nplease reselect or upload the board info: {}' \ - .format(current_app.config.get('BOARD_TYPE'), tmp_root.attrib['board']) - if status is not None: - if os.path.isfile(tmp_launch_file): - os.remove(tmp_launch_file) - return {'status': status} - - error_list = {} - new_launch_name = launch_file_name - rename = False - if not error_list: - new_launch_path = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, - launch_file_name + '.xml') - if os.path.isfile(new_launch_path): - new_launch_name = new_launch_name + '_' + \ - datetime.now().strftime('%Y%m%d%H%M%S') - rename = True - - os.rename(tmp_launch_file, os.path.join(current_app.config.get('CONFIG_PATH'), - board_type, new_launch_name + '.xml')) - - return {'status': 'success', 'file_name': new_launch_name, - 'rename': rename, 'error_list': error_list} - - return {'status': 'unsupported method'} - - -@CONFIG_APP.route('/get_post_launch_vms', methods=['POST']) -def get_post_launch_vms(): - """ - get vm list for the scenario setting - :return: the vm list - """ - data = request.json if request.method == "POST" else request.args - scenario_name = data['scenario_name'] - current_app.config.update(SCENARIO=scenario_name) - - vm_list = get_post_launch_vm_list(scenario_name) - - user_vmid_list = [] - launch_name = data['launch_name'] - xml_configs = get_xml_configs() - launch_config = xml_configs[3] - launch_config.set_curr(launch_name) - if launch_config is not None and launch_config.get_curr_root() is not None: - for user_vm in list(launch_config.get_curr_root()): - if 'id' in user_vm.attrib: - user_vmid_list.append(int(user_vm.attrib['id'])-1) - - vm_list_index = [i for i in range(len(vm_list))] - vm_list_index = set(vm_list_index) - user_vmid_list = set(user_vmid_list) - index = list(vm_list_index - user_vmid_list) - vm_list = [vm_list[i] for i in index] - - return {'vm_list': vm_list} - - -@CONFIG_APP.route('/get_num_of_rdt_res_entries', methods=['POST']) -def get_num_of_rdt_res_entries(): - """ - get the number of rdt res entries - :return: the number of CLOS_MASK and MBA_DELAY entries - """ - data = request.json if request.method == "POST" else request.args - cdp_enabled = data['cdp_enabled'] - board_info = current_app.config.get('BOARD_INFO') - (num_clos_mask, num_mba_delay) = get_num_of_rdt_res(board_info, cdp_enabled) - return {'num_clos_mask': num_clos_mask, 'num_mba_delay': num_mba_delay} - - -def get_post_launch_vm_list(scenario_name): - """ - get post launch VM list - :param scenario_name: - :return: vm_list - """ - xml_configs = get_xml_configs() - scenario_config = xml_configs[3] - scenario_config.set_curr(scenario_name) - vm_list = [] - if scenario_config is not None and scenario_config.get_curr_root() is not None: - for vm in list(scenario_config.get_curr_root()): - if vm.tag == 'vm' and 'id' in vm.attrib: - vm_id = vm.attrib['id'] - for item in list(vm): - if item.tag == 'vm_type' and item.text in ['POST_STD_VM', 'POST_RT_VM']: - vm_list.append((vm_id, item.text)) - break - return vm_list - - -def get_board_list(): - """ - get all available board info files - :return: the file list of board info - """ - config_path = current_app.config.get('CONFIG_PATH') - board_type_list = [] - for config_name in os.listdir(config_path): - if os.path.isdir(os.path.join(config_path, config_name)) \ - and config_name not in ['generic_board', 'sample_launch_scripts']: - board_type_list.append(config_name) - - return board_type_list - - -def get_xml_configs(user_defined=False): - """ - get xml config related variables - :return: board_info, board_config, scenario_config, launch_config - """ - - config_path = None - board_info = current_app.config.get('BOARD_INFO') - board_type = get_board_type(board_info) - if board_type is not None: - config_path = os.path.join(current_app.config.get('CONFIG_PATH'), board_type) - - scenario_config = XmlConfig(config_path, not user_defined) - launch_config = XmlConfig(config_path, not user_defined) - - return board_info, board_type, scenario_config, launch_config - - -def get_generic_scenario_config(scenario_config, add_vm_type=None): - - if add_vm_type is not None: - vm_dict = { - 'PRE_STD_VM': ('partitioned', 'vm:id=0'), - 'PRE_RT_VM': ('hybrid_rt', 'vm:id=0'), - 'SAFETY_VM': ('hybrid', 'vm:id=0'), - 'SERVICE_VM': ('shared', 'vm:id=0'), - 'POST_STD_VM': ('shared', 'vm:id=1'), - 'POST_RT_VM': ('shared', 'vm:id=2'), - 'LAUNCH_POST_STD_VM': ('hybrid_launch_2user_vm', 'user_vm:id=1'), - 'LAUNCH_POST_RT_VM': ('shared_launch_6user_vm', 'user_vm:id=2') - } - config_path = os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), 'generic_board') - xml_path = os.path.join(config_path, vm_dict[add_vm_type][0] + '.xml') - if os.path.isfile(xml_path): - xsd_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'schema', 'config.xsd') - output_xml = os.path.join(config_path, vm_dict[add_vm_type][0] + '_1' + '.xml') - default_populator.main(xsd_path, xml_path, output_xml) - generic_scenario_config = XmlConfig(config_path) - generic_scenario_config.set_curr(vm_dict[add_vm_type][0] + '_1') - generic_scenario_config = set_default_config(generic_scenario_config) - os.remove(output_xml) - return generic_scenario_config.get_curr_elem(vm_dict[add_vm_type][1]) - else: - return None - config_path = os.path.join(current_app.config.get('CONFIG_PATH'), 'generic_board') - generic_scenario_config = XmlConfig(config_path) - for file in os.listdir(config_path): - if os.path.isfile(os.path.join(config_path, file)) and \ - os.path.splitext(file)[1] == '.xml': - generic_scenario_config.set_curr(os.path.splitext(file)[0]) - generic_scenario_config_root = generic_scenario_config.get_curr_root() - if 'scenario' in generic_scenario_config_root.attrib \ - and 'user_vm_launcher' not in generic_scenario_config_root.attrib \ - and generic_scenario_config_root.attrib['scenario'] == \ - scenario_config.get_curr_root().attrib['scenario']: - return generic_scenario_config - - return None - - -def get_board_config(board_info): - """ - get board config - :param board_info: the board info file - :return: the board type - """ - board_config = None - if board_info is not None: - board_config = XmlConfig(os.path.join(current_app.config.get('CONFIG_PATH'), board_info), board_info) - board_config.set_curr(board_info) - - return board_config - - -def get_board_type(board_info): - """ - get board info type - :param board_info: the board info file - :return: the board type - """ - board_config = get_board_config(board_info) - board_type = None - - if board_config is not None: - board_info_root = board_config.get_curr_root() - if board_info_root is not None and 'board' in board_info_root.attrib: - board_type = board_info_root.attrib['board'] - - return board_type - - -def get_board_info(board_info): - """ - get board info type - :param board_info: the board info file - :return: the board info - """ - board_config = get_board_config(board_info) - bios_info = None - base_board_info = None - if board_config is not None: - board_info_root = board_config.get_curr_root() - if board_info_root is not None: - for item in list(board_info_root): - if item.tag == 'BIOS_INFO': - for line in item.text.split('\n'): - if line.strip() != '': - if bios_info is None: - bios_info = line.strip() - else: - bios_info += ('\n' + line.strip()) - elif item.tag == 'BASE_BOARD_INFO': - for line in item.text.split('\n'): - if line.strip() != '': - if base_board_info is None: - base_board_info = line.strip() - else: - base_board_info += ('\n' + line.strip()) - - return (bios_info, base_board_info) - - -def get_num_of_rdt_res(board_file_name, cdp_enalbed): - """ - get the number of rdt res entries - :param board_file_name: the file name of the board - :param cdp_enalbed: cdp enalbed or not - :return: the number of rdt res entries - """ - dict_rdt_res_clos_max = get_board_rdt_res_clos_max(board_file_name) - - num_clos_max = 0 - num_mba_delay = 0 - - if 'MBA' not in dict_rdt_res_clos_max.keys(): - num_mba_delay = 0 - if 'L2' not in dict_rdt_res_clos_max.keys() and 'L3' not in dict_rdt_res_clos_max.keys(): - num_clos_max = 0 - else: - num_clos_max = min(dict_rdt_res_clos_max.values()) - else: - if 'L2' not in dict_rdt_res_clos_max.keys() and 'L3' not in dict_rdt_res_clos_max.keys(): - num_clos_max = 0 - num_mba_delay = dict_rdt_res_clos_max['MBA'] - else: - if cdp_enalbed is not None and cdp_enalbed.strip().lower() == 'y': - for key in dict_rdt_res_clos_max.keys(): - if key not in ['MBA']: - dict_rdt_res_clos_max[key] = int(dict_rdt_res_clos_max[key] / 2) - common_clos_max = min(dict_rdt_res_clos_max.values()) - num_clos_max = common_clos_max * 2 - num_mba_delay = common_clos_max - else: - common_clos_max = min(dict_rdt_res_clos_max.values()) - num_clos_max = common_clos_max - num_mba_delay = common_clos_max - - return (num_clos_max, num_mba_delay) - - -def get_board_rdt_res_clos_max(board_file_name): - """ - get rdt res clos max of the board - :param board_file_name: the file name of the board - :return: the rdt res clos max - """ - board_config = get_board_config(board_file_name) - rdt_res_supported = [] - rdt_res_clos_max = [] - - if board_config is not None: - board_info_root = board_config.get_curr_root() - if board_info_root is not None: - for item in list(board_info_root): - if item.tag == 'CLOS_INFO': - for line in item.text.split('\n'): - line = line.strip() - if line.startswith('rdt resources supported'): - try: - rdt_res_supported = line.split(':')[1].split(',') - except: - pass - if line.startswith('rdt resource clos max:'): - try: - rdt_res_clos_max = line.split(':')[1].split(',') - break - except: - pass - if len(rdt_res_clos_max) < len(rdt_res_supported): - for i in range(len(rdt_res_supported) - len(rdt_res_clos_max)): - rdt_res_clos_max.append(0) - dict_rdt_res_clos_max = {} - for i in range(len(rdt_res_supported)): - try: - clos_max = int(rdt_res_clos_max[i].strip()) - except: - clos_max = 0 - if clos_max > 0: - dict_rdt_res_clos_max[rdt_res_supported[i].strip()] = clos_max - return dict_rdt_res_clos_max - - -def assign_vm_id(scenario_config): - """ - assign vm ids for the scenario setting. - :param scenario_config: - :return: - """ - root = scenario_config.get_curr_root() - pre_launched_vm_num = 0 - sos_vm_num = 0 - post_launched_vm_num = 0 - - for vm in list(root): - if vm.tag == 'vm': - for item in list(vm): - if item.tag == 'vm_type': - if item.text in ['PRE_STD_VM', 'SAFETY_VM', 'PRE_RT_VM']: - pre_launched_vm_num += 1 - elif item.text in ['SERVICE_VM']: - sos_vm_num += 1 - elif item.text in ['POST_STD_VM', 'POST_RT_VM']: - post_launched_vm_num += 1 - - pre_launched_vm_index = 0 - sos_vm_index = pre_launched_vm_num - post_launched_vm_index = pre_launched_vm_num + sos_vm_num - for vm in list(root): - if vm.tag == 'vm': - for item in list(vm): - if item.tag == 'vm_type': - if item.text in ['PRE_STD_VM', 'SAFETY_VM', 'PRE_RT_VM']: - vm.attrib['id'] = str(pre_launched_vm_index) - pre_launched_vm_index += 1 - elif item.text in ['SERVICE_VM']: - vm.attrib['id'] = str(sos_vm_index) - sos_vm_index += 1 - elif item.text in ['POST_STD_VM', 'POST_RT_VM']: - vm.attrib['id'] = str(post_launched_vm_index) - post_launched_vm_index += 1 - - -def get_xpath_dict_of_xsd(): - """ - get xpath_dict of the xsd config - :return: xpath dict - """ - acrn_config_element_root = get_acrn_config_element( - os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'schema', 'config.xsd')) - xpath_dict = acrn_config_element_2_xpath_dict(acrn_config_element_root, {}) - return xpath_dict - - -def set_default_config(config): - ''' - set default values for current config - :param config: the current config - :return: the return config setting with default values - ''' - xpath_dict = get_xpath_dict_of_xsd() - config_root = config.get_curr_root() - - return set_default_config_for_curr_layer(config, config_root, '/'+config_root.tag, xpath_dict) - - -def set_default_config_for_curr_layer(config, elem, key, xpath_dict): - for sub_elem in list(elem): - sub_key = key+'/'+sub_elem.tag - if sub_key in xpath_dict.keys() and xpath_dict[sub_key] and xpath_dict[sub_key]['default']: - config.set_curr_value(xpath_dict[sub_key]['default'], *tuple(sub_key.split('/')[2:])) - set_default_config_for_curr_layer(config, sub_elem, sub_key, xpath_dict) - return config - - -def get_generic_config_list(): - default_config_path = os.path.join(current_app.config.get('DEFAULT_CONFIG_PATH'), 'generic_board') - default_xml_config = XmlConfig(default_config_path) - secenario_config_list = [] - launch_config_list = [] - for config_name in os.listdir(default_config_path): - if os.path.isfile(os.path.join(default_config_path, config_name)): - default_xml_config.set_curr(config_name.rsplit('.', 1)[0]) - xml_config_root = default_xml_config.get_curr_root() - if 'scenario' in xml_config_root.attrib and 'user_vm_launcher' not in xml_config_root.attrib: - secenario_config_list.append(config_name.rsplit('.', 1)[0]) - elif 'scenario' in xml_config_root.attrib and 'user_vm_launcher' in xml_config_root.attrib: - launch_config_list.append(config_name.rsplit('.', 1)[0]) - - return (secenario_config_list, launch_config_list) - - -@CONFIG_APP.context_processor -def utility_functions(): - def print_in_console(message): - print(str(message)) - - return dict(mdebug=print_in_console)