From 8ce1b4dc1064ed62e53c86ac35a889085635de1e Mon Sep 17 00:00:00 2001 From: Nataliia Solomko Date: Wed, 5 Feb 2025 16:13:31 +0200 Subject: [PATCH] T7069: Add function to get available cpus --- python/vyos/utils/cpu.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python/vyos/utils/cpu.py b/python/vyos/utils/cpu.py index 3bea5ac127..8ace77d155 100644 --- a/python/vyos/utils/cpu.py +++ b/python/vyos/utils/cpu.py @@ -99,3 +99,18 @@ def get_core_count(): core_count += 1 return core_count + + +def get_available_cpus(): + """ List of cpus with ids that are available in the system + Uses 'lscpu' command + + Returns: list[dict[str, str | int | bool]]: cpus details + """ + import json + + from vyos.utils.process import cmd + + out = json.loads(cmd('lscpu --extended -b --json')) + + return out['cpus']