diff --git a/misc/config_tools/config_app/views.py b/misc/config_tools/config_app/views.py
index 15fe80d3a..be0d9f3d3 100644
--- a/misc/config_tools/config_app/views.py
+++ b/misc/config_tools/config_app/views.py
@@ -66,9 +66,7 @@ def scenario(scenario_name):
board_info, board_type, scenario_config, launch_config = get_xml_configs()
(bios_info, base_board_info) = get_board_info(board_info)
- 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, {})
+ xpath_dict = get_xpath_dict_of_xsd()
current_app.config.update(SCENARIO=scenario_name)
@@ -256,8 +254,7 @@ def save_scenario():
'error_list': {'error': 'Can not add a new VM. Max VM number is {}.'.format(MAX_VM_NUM)}}
curr_vm_id = generator.split(':')[1]
add_vm_type = scenario_config_data['add_vm_type']
- generic_scenario_config = get_generic_scenario_config(scenario_config, add_vm_type)
- generic_scenario_config_root = generic_scenario_config.get_curr_root()
+ 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
@@ -267,13 +264,12 @@ def save_scenario():
if curr_vm_id == vm_list[i]:
curr_vm_index = i + 2
break
- for vm in list(generic_scenario_config_root):
- if vm.tag == 'vm':
- for i in range(0, MAX_VM_NUM):
- if str(i) not in vm_list:
- break
- vm.attrib['id'] = str(i)
- vm_to_add.append(vm)
+ if add_scenario_config and add_scenario_config.tag == 'vm':
+ for i in range(0, 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
@@ -376,8 +372,7 @@ def save_launch():
if add_vm_id == vm_info[0]:
add_launch_id = i + 1
break
- generic_scenario_config = get_generic_scenario_config(launch_config, add_launch_type)
- generic_scenario_config_root = generic_scenario_config.get_curr_root()
+ 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)
@@ -387,13 +382,12 @@ def save_launch():
if curr_vm_id == vm_list[i]:
curr_vm_index = i + 1
break
- for vm in list(generic_scenario_config_root):
- if vm.tag == 'uos':
- for i in range(1, MAX_VM_NUM):
- if str(i) not in vm_list:
- break
- vm.attrib['id'] = str(add_launch_id)
- vm_to_add.append(vm)
+ if add_launch_config and add_launch_config.tag == 'uos':
+ for i in range(1, 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)
@@ -503,8 +497,8 @@ def create_setting():
os.remove(launch_file)
if mode == 'create':
- template_file_name = 'LAUNCH_POST_STD_VM'
- src_file_name = os.path.join(current_app.config.get('CONFIG_PATH'), 'template', template_file_name+'.xml')
+ template_file_name = 'industry_launch_2uos'
+ src_file_name = os.path.join(current_app.config.get('CONFIG_PATH'), 'generic', template_file_name + '.xml')
else:
src_file_name = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, default_name + '.xml')
copyfile(src_file_name,
@@ -512,6 +506,7 @@ def create_setting():
launch_config.set_curr(create_name)
if mode == 'create':
+ launch_config.delete_curr_key('uos:id=2')
launch_config.delete_curr_key('uos:id=1')
launch_config.save(create_name)
return {'status': 'success', 'setting': create_name, 'error_list': {}}
@@ -522,8 +517,8 @@ def create_setting():
os.remove(scenario_file)
if mode == 'create':
- template_file_name = 'HV'
- src_file_name = os.path.join(current_app.config.get('CONFIG_PATH'), 'template', template_file_name+'.xml')
+ template_file_name = 'industry'
+ src_file_name = os.path.join(current_app.config.get('CONFIG_PATH'), 'generic', template_file_name + '.xml')
else:
src_file_name = os.path.join(current_app.config.get('CONFIG_PATH'), board_type, default_name + '.xml')
copyfile(src_file_name,
@@ -542,6 +537,9 @@ def create_setting():
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(8):
+ scenario_config.delete_curr_key('vm:id={}'.format(i))
+ scenario_config = set_default_config(scenario_config)
scenario_config.save(create_name)
return {'status': 'success', 'setting': create_name, 'error_list': {}}
@@ -969,11 +967,23 @@ def get_xml_configs(user_defined=True):
def get_generic_scenario_config(scenario_config, add_vm_type=None):
if add_vm_type is not None:
- config_path = os.path.join(current_app.config.get('CONFIG_PATH'), 'template')
+ vm_dict = {
+ 'PRE_STD_VM': ('logical_partition', 'vm:id=0'),
+ 'PRE_RT_VM': ('hybrid_rt', 'vm:id=0'),
+ 'SAFETY_VM': ('hybrid', 'vm:id=0'),
+ 'SOS_VM': ('industry', 'vm:id=0'),
+ 'POST_STD_VM': ('industry', 'vm:id=1'),
+ 'POST_RT_VM': ('industry', 'vm:id=2'),
+ 'KATA_VM': ('industry', 'vm:id=1'),
+ 'LAUNCH_POST_STD_VM': ('industry_launch_2uos', 'uos:id=1'),
+ 'LAUNCH_POST_RT_VM': ('industry_launch_2uos', 'uos:id=2')
+ }
+ config_path = os.path.join(current_app.config.get('CONFIG_PATH'), 'generic')
generic_scenario_config = XmlConfig(config_path)
- if os.path.isfile(os.path.join(config_path, add_vm_type + '.xml')):
- generic_scenario_config.set_curr(add_vm_type)
- return generic_scenario_config
+ if os.path.isfile(os.path.join(config_path, vm_dict[add_vm_type][0] + '.xml')):
+ generic_scenario_config.set_curr(vm_dict[add_vm_type][0])
+ generic_scenario_config = set_default_config(generic_scenario_config)
+ 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')
@@ -1172,6 +1182,39 @@ def assign_vm_id(scenario_config):
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
+
+
@CONFIG_APP.context_processor
def utility_functions():
def print_in_console(message):
diff --git a/misc/config_tools/data/generic_board/hybrid.xml b/misc/config_tools/data/generic_board/hybrid.xml
index 66942a545..08e829bd5 100644
--- a/misc/config_tools/data/generic_board/hybrid.xml
+++ b/misc/config_tools/data/generic_board/hybrid.xml
@@ -33,6 +33,7 @@
0xfff
0xfff
0xfff
+ 0
y
n
diff --git a/misc/config_tools/data/generic_board/hybrid_rt.xml b/misc/config_tools/data/generic_board/hybrid_rt.xml
index 428f9ec1d..38e5eb3b4 100644
--- a/misc/config_tools/data/generic_board/hybrid_rt.xml
+++ b/misc/config_tools/data/generic_board/hybrid_rt.xml
@@ -33,6 +33,7 @@
0xfff
0xfff
0xfff
+ 0
y
n
diff --git a/misc/config_tools/data/generic_board/industry.xml b/misc/config_tools/data/generic_board/industry.xml
index e6b65f843..1a44444d3 100644
--- a/misc/config_tools/data/generic_board/industry.xml
+++ b/misc/config_tools/data/generic_board/industry.xml
@@ -33,6 +33,7 @@
0xfff
0xfff
0xfff
+ 0
y
n
diff --git a/misc/config_tools/data/generic_board/logical_partition.xml b/misc/config_tools/data/generic_board/logical_partition.xml
index b67e8a0cb..f5b06494b 100644
--- a/misc/config_tools/data/generic_board/logical_partition.xml
+++ b/misc/config_tools/data/generic_board/logical_partition.xml
@@ -33,6 +33,7 @@
0xfff
0xfff
0xfff
+ 0
y
n