+ def get_host_epa(specs):
+ host_epa = {}
+ if 'cpu_model' in specs:
+ host_epa["cpu-model"] = specs['cpu_model'].upper()
+ if 'cpu_arch' in specs:
+ host_epa["cpu-arch"] = specs['cpu_arch'].upper()
+ if 'cpu_vendor' in specs:
+ host_epa["cpu-vendor"] = specs['cpu_vendor'].upper()
+ if 'cpu_socket_count' in specs:
+ host_epa["cpu-socket-count"] = specs['cpu_socket_count']
+ if 'cpu_core_count' in specs:
+ host_epa["cpu-core-count"] = specs['cpu_core_count']
+ if 'cpu_core_thread_count' in specs:
+ host_epa["cpu-core-thread-count"] = specs['cpu_core_thread_count']
+ if 'om_cpu_model_string' in specs:
+ host_epa["om-cpu-model-string"] = specs['om_cpu_model_string']
+ if 'cpu_feature' in specs:
+ cpu_feature_prop = []
+ for spec in specs['cpu_feature']:
+ cpu_feature_prop.append({'feature':spec.upper()})
+ host_epa['cpu-feature'] = cpu_feature_prop
+ if 'om_cpu_feature' in specs:
+ cpu_feature_prop = []
+ for spec in specs['om_cpu_feature']:
+ cpu_feature_prop.append({'feature':spec})
+ host_epa['om-cpu-feature'] = cpu_feature_prop
+ return host_epa;
+
+ def get_vswitch_epa(specs):
+ vswitch_epa = {}
+ if 'ovs_acceleration' in specs:
+ vswitch_epa['ovs-acceleration'] = specs['ovs_acceleration'].upper()
+ if 'ovs_offload' in specs:
+ vswitch_epa['ovs-offload'] = specs['ovs_offload'].upper()
+ return vswitch_epa
+
+ def get_hypervisor_epa(specs):
+ hypervisor_epa = {}
+ if 'type' in specs:
+ hypervisor_epa['type'] = specs['type'].upper()
+ if 'version' in specs:
+ hypervisor_epa['version'] = specs['version']
+
+ return hypervisor_epa
+
+ def get_guest_epa(specs):
+ guest_epa = {}
+ guest_epa['numa-node-policy'] = {}
+ guest_epa['numa-node-policy']['node'] = []
+ if 'mem_policy' in specs:
+ guest_epa['numa-node-policy']['mem-policy'] = specs['mem_policy'].upper()
+ if 'node_cnt' in specs:
+ guest_epa['numa-node-policy']['node-cnt'] = specs['node_cnt']
+ if 'node' in specs:
+ for node in specs['node']:
+ node_prop = {}
+ if 'id' in node:
+ node_prop['id'] = node['id']
+ if 'mem_size' in node:
+ if 'MiB' in node['mem_size'] or 'MB' in node['mem_size']:
+ node_prop['memory-mb'] = int(node['mem_size'].replace('MB',''))
+ else:
+ err_msg = "Specify mem_size of NUMA extension should be in MB"
+ raise ValidationError(message=err_msg)
+ if 'om_numa_type' in node:
+ numa_type = node['om_numa_type']
+ if 'paired-threads' == numa_type:
+ node_prop['paired_threads'] = {}
+ node_prop['paired_threads']['num_paired_threads'] = node['paired_threads']['num_paired_threads']
+ elif 'threads' == numa_type:
+ if 'num_threads' in node:
+ node_prop['num_threads'] = node['num_threads']
+ elif 'cores' == numa_type:
+ if 'num_cores' in node:
+ node_prop['num_cores'] = node['num_cores']
+ else:
+ err_msg = "om_numa_type should be among cores, paired-threads or threads"
+ raise ValidationError(message=err_msg)
+ guest_epa['numa-node-policy']['node'].append(node_prop)
+ return guest_epa
+