Skip to content

Commit b389c3c

Browse files
committed
support detect vmware esxi
1 parent f1bb82e commit b389c3c

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

lisa/executable.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
if TYPE_CHECKING:
2727
from lisa.node import Node
2828

29-
3029
T = TypeVar("T")
3130

3231

@@ -168,6 +167,10 @@ def create(cls, node: Node, *args: Any, **kwargs: Any) -> Tool:
168167
freebsd_tool = cls._freebsd_tool()
169168
if freebsd_tool:
170169
tool_cls = freebsd_tool
170+
elif "VMWareESXi" in node.os.name:
171+
vmware_esxi_tool = cls._vmware_esxi_tool()
172+
if vmware_esxi_tool:
173+
tool_cls = vmware_esxi_tool
171174
return tool_cls(node, *args, **kwargs)
172175

173176
@classmethod
@@ -184,11 +187,21 @@ def _freebsd_tool(cls) -> Optional[Type[Tool]]:
184187
"""
185188
return None
186189

190+
@classmethod
191+
def _vmware_esxi_tool(cls) -> Optional[Type[Tool]]:
192+
"""
193+
return a vmware esxi version tool class, if it's needed
194+
"""
195+
return None
196+
187197
def command_exists(self, command: str) -> Tuple[bool, bool]:
188198
exists = False
189199
use_sudo = False
190200
if self.node.is_posix:
191-
where_command = "command -v"
201+
if "VMWareESXi" in self.node.os.name:
202+
where_command = "which"
203+
else:
204+
where_command = "command -v"
192205
else:
193206
where_command = "where"
194207
where_command = f"{where_command} {command}"

lisa/operating_system.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ class OperatingSystem:
128128
__release_pattern = re.compile(r"^DISTRIB_ID='?([^ \n']+).*$", re.M)
129129
__suse_release_pattern = re.compile(r"^(SUSE).*$", re.M)
130130
__bmc_release_pattern = re.compile(r".*(wcscli).*$", re.M)
131+
# VMware ESXi 8.0.2 build-23305546
132+
# VMware ESXi 8.0 Update 2
133+
__vmware_esxi_release_pattern = re.compile(r"^(VMware ESXi).*$", re.M)
131134

132135
__posix_factory: Optional[Factory[Any]] = None
133136

@@ -250,6 +253,9 @@ def _get_detect_string(cls, node: Any) -> Iterable[str]:
250253
cmd_result = typed_node.execute(cmd="wcscli", no_error_log=True)
251254
yield get_matched_str(cmd_result.stdout, cls.__bmc_release_pattern)
252255

256+
cmd_result = typed_node.execute(cmd="vmware -lv", no_error_log=True)
257+
yield get_matched_str(cmd_result.stdout, cls.__vmware_esxi_release_pattern)
258+
253259
# try best from distros'family through ID_LIKE
254260
yield get_matched_str(
255261
cmd_result_os_release.stdout, cls.__os_release_pattern_idlike
@@ -681,6 +687,12 @@ def name_pattern(cls) -> Pattern[str]:
681687
return re.compile("^wcscli$")
682688

683689

690+
class VMWareESXi(Posix):
691+
@classmethod
692+
def name_pattern(cls) -> Pattern[str]:
693+
return re.compile("^VMware ESXi$")
694+
695+
684696
class MacOS(Posix):
685697
@classmethod
686698
def name_pattern(cls) -> Pattern[str]:

lisa/tools/lscpu.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def command(self) -> str:
107107
def _windows_tool(cls) -> Optional[Type[Tool]]:
108108
return WindowsLscpu
109109

110+
@classmethod
111+
def _vmware_esxi_tool(cls) -> Optional[Type[Tool]]:
112+
return VMWareESXiLscpu
113+
110114
@classmethod
111115
def _freebsd_tool(cls) -> Optional[Type[Tool]]:
112116
return BSDLscpu
@@ -438,3 +442,40 @@ def calculate_vcpu_count(self, force_run: bool = False) -> int:
438442
* self.get_cluster_count()
439443
* self.get_thread_per_core_count()
440444
)
445+
446+
447+
class VMWareESXiLscpu(Lscpu):
448+
# CPU Threads: 208
449+
__cpu_threads = re.compile(r"CPU Threads:[ ]+([\d]+)?", re.M)
450+
# CPU Packages: 2
451+
__cpu_packages = re.compile(r"CPU Packages:[ ]+([\d]+)?", re.M)
452+
# CPU Cores: 104
453+
__cpu_cores = re.compile(r"CPU Cores:[ ]+([\d]+)?", re.M)
454+
455+
@property
456+
def command(self) -> str:
457+
return "esxcli"
458+
459+
def get_core_count(self, force_run: bool = False) -> int:
460+
result = self.run("hardware cpu global get", force_run)
461+
matched = self.__cpu_threads.findall(result.stdout)
462+
assert_that(
463+
len(matched),
464+
f"cpu thread should have exact one line, but got {matched}",
465+
).is_equal_to(1)
466+
self._core_count = int(matched[0])
467+
return self._core_count
468+
469+
def calculate_vcpu_count(self, force_run: bool = False) -> int:
470+
result = self.run("hardware cpu global get", force_run)
471+
matched_cpu_packages = self.__cpu_packages.findall(result.stdout)
472+
assert_that(
473+
len(matched_cpu_packages),
474+
f"cpu packages should have exact one line, but got {matched_cpu_packages}",
475+
).is_equal_to(1)
476+
matched_cpu_cores = self.__cpu_cores.findall(result.stdout)
477+
assert_that(
478+
len(matched_cpu_cores),
479+
f"cpu cores should have exact one line, but got {matched_cpu_cores}",
480+
).is_equal_to(1)
481+
return int(matched_cpu_packages[0]) * int(matched_cpu_cores[0])

0 commit comments

Comments
 (0)