Skip to content

Commit

Permalink
adds VM IPv6 as primary IPv6 if only one candidate was found #394
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-Ricardo committed Oct 21, 2024
1 parent dde3fe4 commit 654d30e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions module/sources/vmware/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 654d30e

Please sign in to comment.