aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/CpuUtils.py
diff options
context:
space:
mode:
authorMiroslav Miklus <mmiklus@cisco.com>2016-07-28 13:33:18 +0200
committerMiroslav Miklus <mmiklus@cisco.com>2016-08-10 11:31:25 +0000
commit72be8262ea5dc0136a21032402b7f4ffa5ff4576 (patch)
tree73708f944e30f37dfe36ac02ab8f5d35fd13d88f /resources/libraries/python/CpuUtils.py
parentb2841cae8eb34a0a0c5b26cf344d6a0d39a1af3e (diff)
CSIT-321 L2 Cross-connect - baseline - NIC-to-NIC(XL710)
Change-Id: I0c78d17242eedbfa573f1e2c20dc491a71b8dd4a Signed-off-by: Miroslav Miklus <mmiklus@cisco.com>
Diffstat (limited to 'resources/libraries/python/CpuUtils.py')
-rw-r--r--resources/libraries/python/CpuUtils.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/resources/libraries/python/CpuUtils.py b/resources/libraries/python/CpuUtils.py
index a8698dfd54..85c2e843e4 100644
--- a/resources/libraries/python/CpuUtils.py
+++ b/resources/libraries/python/CpuUtils.py
@@ -98,3 +98,36 @@ class CpuUtils(object):
raise RuntimeError("Node cpuinfo not available.")
return cpulist
+
+ @staticmethod
+ def cpu_list_per_node_str(node, cpu_node, skip_cnt=0,
+ cpu_cnt=0, sep=","):
+ """Return string of node related list of CPU numbers.
+
+ :param node: Node dictionary with cpuinfo.
+ :param cpu_node: Numa node number.
+ :param skip_cnt: Skip first "skip_cnt" CPUs.
+ :param cpu_cnt: Count of cpus to return, if 0 then return all.
+ :param sep: Separator, default: 1,2,3,4,....
+ :type node: dict
+ :type cpu_node: int
+ :type skip_cnt: int
+ :type cpu_cnt: int
+ :type sep: str
+ :return: Cpu numbers related to numa from argument.
+ :rtype: str
+ """
+
+ cpu_list = CpuUtils.cpu_list_per_node(node, cpu_node)
+ cpu_list_len = len(cpu_list)
+ cpu_flist = ""
+ if cpu_cnt == 0:
+ cpu_cnt = cpu_list_len - skip_cnt
+
+ if cpu_cnt + skip_cnt > cpu_list_len:
+ raise RuntimeError("cpu_cnt + skip_cnt > length(cpu list).")
+
+ cpu_flist = sep.join(str(a) for a in
+ cpu_list[skip_cnt:skip_cnt+cpu_cnt])
+
+ return cpu_flist