|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import argparse |
| 4 | +import contextlib |
4 | 5 | import enum |
5 | 6 | import functools |
6 | 7 | import io |
@@ -2411,19 +2412,20 @@ def main() -> None: |
2411 | 2412 | target_path = f"{target_path}?{target_query}" |
2412 | 2413 | target_paths.append(target_path) |
2413 | 2414 |
|
| 2415 | + # Use esxi_memory_context_manager only if running on ESXi host |
| 2416 | + if platform.system().lower() == "vmkernel": |
| 2417 | + context_mgr = esxi_memory_context_manager() |
| 2418 | + else: |
| 2419 | + context_mgr = contextlib.nullcontext() |
| 2420 | + |
2414 | 2421 | try: |
2415 | 2422 | target_name = "Unknown" # just in case open_all already fails |
2416 | | - for target in Target.open_all(target_paths): |
2417 | | - target_name = "Unknown" # overwrite previous target name |
2418 | | - target_name = target.name |
2419 | | - log.info("Loading target %s", target_name) |
2420 | | - log.info(target) |
2421 | | - if target.os == "esxi" and target.name == "local": |
2422 | | - # Loader found that we are running on an esxi host |
2423 | | - # Perform operations to "enhance" memory |
2424 | | - with esxi_memory_context_manager(): |
2425 | | - files_to_upload = acquire_children_and_targets(target, args) |
2426 | | - else: |
| 2423 | + with context_mgr: |
| 2424 | + for target in Target.open_all(target_paths): |
| 2425 | + target_name = "Unknown" # overwrite previous target name |
| 2426 | + target_name = target.name |
| 2427 | + log.info("Loading target %s", target_name) |
| 2428 | + log.info(target) |
2427 | 2429 | files_to_upload = acquire_children_and_targets(target, args) |
2428 | 2430 | except Exception: |
2429 | 2431 | log.error("Failed to acquire target: %s", target_name) # noqa: TRY400 |
|
0 commit comments