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.her...@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

Reply via email to