[RFC PATCH] misc: Add new acrn:widget-options: ui-applicable-vms


Liu, Yifan1
 

From: Yifan Liu <yifan1.liu@...>

In some cases we would like the "acrn:applicable-vms" property to be
effective only in UI. E.g., we would like to hide cpu affinity
configurations from Service VM, but acrn:applicable-vms would prevent
from configuring via XML too.

This patch adds support for a new option 'ui-applicable-vms' under
acrn:widget-option, with the same usage as acrn:applicable-vms.

Signed-off-by: Yifan Liu <yifan1.liu@...>
---
.../configurator/pyodide/loadBoard.py | 23 ++++++++++++++++++-
misc/config_tools/schema/config.xsd | 2 +-
2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/misc/config_tools/configurator/pyodide/loadBoard.py b/misc/config_tools/configurator/pyodide/loadBoard.py
index 41441bf88..46220c23e 100644
--- a/misc/config_tools/configurator/pyodide/loadBoard.py
+++ b/misc/config_tools/configurator/pyodide/loadBoard.py
@@ -58,6 +58,21 @@ def get_dynamic_scenario(board):
obj['enum'] = dynamic_enum(**enum_setting)
return obj

+ def ui_element_slicer(obj, vm_type, config_type):
+ def is_element_needed(ele):
+ if isinstance(ele, dict) and 'ui:options' in ele.keys():
+ if isinstance(ele['ui:options'], dict) and 'ui-applicable-vms' in ele['ui:options']:
+ if vm_type not in [t.strip() for t in ele['ui:options']['ui-applicable-vms'].split(',')]:
+ return False
+ return True
+
+ if isinstance(obj, list):
+ return [ui_element_slicer(e, vm_type, config_type) for e in obj if is_element_needed(e)]
+ elif isinstance(obj, dict):
+ return {k: ui_element_slicer(v, vm_type, config_type) for k, v in obj.items() if is_element_needed(v)}
+ else:
+ return obj
+
data = json.loads(scenario_json_schema, object_hook=dynamic_enum_apply)

form_schemas = {}
@@ -70,7 +85,13 @@ def get_dynamic_scenario(board):
current_form_type_schema_obj = form_schema['definitions'][f'{tab_type}{form_type}']
for key in ['type', 'required', 'properties']:
form_schema[key] = current_form_type_schema_obj[key]
- form_schemas[tab_type][form_type] = form_schema
+ vm_type = {
+ 'HV': 'HV',
+ 'PreLaunchedVM': 'pre-launched',
+ 'ServiceVM': 'service-vm',
+ 'PostLaunchedVM': 'post-launched',
+ }[tab_type]
+ form_schemas[tab_type][form_type] = ui_element_slicer(form_schema, vm_type, form_type)

return form_schemas

diff --git a/misc/config_tools/schema/config.xsd b/misc/config_tools/schema/config.xsd
index efebaa863..5ae93fc8c 100644
--- a/misc/config_tools/schema/config.xsd
+++ b/misc/config_tools/schema/config.xsd
@@ -377,7 +377,7 @@ Refer to :ref:`vuart_config` for detailed vUART settings.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="cpu_affinity" type="CPUAffinityConfigurations" minOccurs="0">
- <xs:annotation acrn:title="Physical CPU affinity" acrn:views="basic">
+ <xs:annotation acrn:title="Physical CPU affinity" acrn:views="basic" acrn:widget-options="'ui-applicable-vms': 'pre-launched, post-launched'">
<xs:documentation>Select a subset of physical CPUs that this VM can use. More than one can be selected.</xs:documentation>
</xs:annotation>
</xs:element>
--
2.32.0.windows.2

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.