From 654d30e9d9ecf346ebe3b4f506274b8c184a1ccb Mon Sep 17 00:00:00 2001 From: "ricardo.bartels@telekom.de" Date: Mon, 21 Oct 2024 09:21:13 +0200 Subject: [PATCH] adds VM IPv6 as primary IPv6 if only one candidate was found #394 --- module/sources/vmware/connection.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/module/sources/vmware/connection.py b/module/sources/vmware/connection.py index deb90f3..f8f8bfd 100644 --- a/module/sources/vmware/connection.py +++ b/module/sources/vmware/connection.py @@ -2499,6 +2499,26 @@ def add_virtual_machine(self, obj): nic_data[int_full_name] = vm_nic_data + # if VM has only one IPv6 on all interfaces, use it as primary IPv6 address + if vm_primary_ip6 is None or True: + all_ips = [y for xs in nic_ips.values() for y in xs] + potential_primary_ipv6_list = list() + + for ip in all_ips: + # noinspection PyBroadException + try: + ip_address_object = ip_interface(ip) + except Exception: + continue + + if ip_address_object.version == 6: + potential_primary_ipv6_list.append(ip_address_object) + + if len(potential_primary_ipv6_list) == 1: + log.debug(f"Found one IPv6 '{potential_primary_ipv6_list[0]}' address on all interfaces of " + f"VM '{name}', using it as primary IPv6.") + vm_primary_ip6 = potential_primary_ipv6_list[0] + # add VM to inventory self.add_device_vm_to_inventory(NBVM, object_data=vm_data, vnic_data=nic_data, nic_ips=nic_ips, p_ipv4=vm_primary_ip4, p_ipv6=vm_primary_ip6,