From 3392d53a32964274b8b8e1b06ff6684a9e185ff4 Mon Sep 17 00:00:00 2001 From: Ricardo Bartels Date: Thu, 2 Sep 2021 22:37:10 +0200 Subject: [PATCH] fixes issue with cliustername if strip_host_domain_name is set #75 refs: #75 --- module/sources/vmware/connection.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/module/sources/vmware/connection.py b/module/sources/vmware/connection.py index 605d7a3..a9279d5 100644 --- a/module/sources/vmware/connection.py +++ b/module/sources/vmware/connection.py @@ -1446,7 +1446,8 @@ def add_host(self, obj): log.error(e) # handle standalone hosts - if cluster_name == name: + if cluster_name == name or (self.strip_host_domain_name is True and cluster_name.split(".")[0] == name): + cluster_name = cluster_name.split(".")[0] log.debug2(f"Host name and cluster name are equal '{cluster_name}'. " f"Assuming this host is a 'standalone' host.") @@ -1957,9 +1958,14 @@ def add_virtual_machine(self, obj): self.processed_vm_uuid.append(vm_uuid) parent_name = get_string_or_none(grab(obj, "runtime.host.name")) + cluster_name = get_string_or_none(grab(obj, "runtime.host.parent.name")) + + # honor strip_host_domain_name + if cluster_name is not None and self.strip_host_domain_name is True and \ + parent_name.split(".")[0] == cluster_name.split(".")[0]: + cluster_name = cluster_name.split(".")[0] # check VM cluster - cluster_name = get_string_or_none(grab(obj, "runtime.host.parent.name")) if cluster_name is None: log.error(f"Requesting cluster for Virtual Machine '{name}' failed. Skipping.") return