public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-esxi-import-tools] fix #6347: do not break vm listing on invalid configs
@ 2025-04-23 13:03 Daniel Herzig
  2025-04-23 13:28 ` Daniel Kral
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Herzig @ 2025-04-23 13:03 UTC (permalink / raw)
  To: pve-devel

Move the queries for vCLS machines and empty datastore strings into
the already existing try-except routine to save `listvms.py` from
breaking when `vm.config` is `None`.

Do not store the result of the `any` function in a variable anymore,
do the same for the datastore query to shorten code.

Prepare more verbose logging.

Signed-off-by: Daniel Herzig <d.herzig@proxmox.com>
---
 listvms.py | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/listvms.py b/listvms.py
index 89ddfb2..4995975 100755
--- a/listvms.py
+++ b/listvms.py
@@ -265,21 +265,19 @@ def main():
     with connect_to_esxi_host(connection_args) as connection:
         data = {}
         for vm in list_vms(connection):
-            # drop vCLS machines
-            vCLS = any(cfg.key == "HDCS.agent"
-                       and cfg.value.lower() == "true"
-                       for cfg in vm.config.extraConfig)
-            if vCLS:
-                continue
-            # drop vms with empty datastore
-            datastore_name, relative_vmx_path = parse_file_path(
-                vm.config.files.vmPathName
-            )
-            if not datastore_name:
-                print(f"Skipping VM (no datastore value): {vm.name}",
-                      file=sys.stderr)
-                continue
             try:
+                # drop vCLS machines
+                if any(cfg.key == "HDCS.agent"
+                       and cfg.value.lower() == "true"
+                       for cfg in vm.config.extraConfig):
+                    print(f"Skipping ESXI VM (VMware internals): {vm.name}",
+                          file=sys.stderr)
+                    continue
+                # drop vms with empty datastore
+                if not parse_file_path(vm.config.files.vmPathName)[0]:
+                    print(f"Skipping ESXI VM (no datastore value): {vm.name}",
+                          file=sys.stderr)
+                    continue
                 fetch_and_update_vm_data(vm, data)
             except Exception as err:
                 print(
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-23 15:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-23 13:03 [pve-devel] [PATCH pve-esxi-import-tools] fix #6347: do not break vm listing on invalid configs Daniel Herzig
2025-04-23 13:28 ` Daniel Kral
2025-04-23 14:04   ` Daniel Herzig
2025-04-23 14:45     ` Daniel Kral
2025-04-23 15:17       ` Daniel Herzig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal