1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 class CpuSysCores(object):
18 def __init__(self, connection=""):
20 self.connection = connection
22 def _open_cpuinfo(self):
24 lines = self.connection.execute("cat /proc/cpuinfo")[1].split(u'\n')
27 def _get_core_details(self, lines):
32 name, value = line.split(":", 1)
33 core_lines[name.strip()] = value.strip()
35 core_details.append(core_lines)
40 def get_core_socket(self):
41 lines = self.connection.execute("lscpu")[1].split(u'\n')
42 num_cores = self._get_core_details(lines)
44 self.core_map["cores_per_socket"] = num["Core(s) per socket"]
45 self.core_map["thread_per_core"] = num["Thread(s) per core"]
47 lines = self._open_cpuinfo()
48 core_details = self._get_core_details(lines)
49 for core in core_details:
50 for k, v in core.items():
51 if k == "physical id":
52 if core["physical id"] not in self.core_map:
53 self.core_map[core['physical id']] = []
54 self.core_map[core['physical id']].append(
59 def validate_cpu_cfg(self, vnf_cfg=None):
64 'worker_config': '1C/1T',
67 if self.core_map["thread_per_core"] == 1 and \
68 vnf_cfg["worker_config"] == "1C/2T":
71 if vnf_cfg['lb_config'] == 'SW':
72 num_cpu = int(vnf_cfg["worker_threads"]) + 5
73 if int(self.core_map["cores_per_socket"]) < num_cpu: