Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions module/sources/common/source_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,23 @@ def map_object_interfaces_to_current_interfaces(self, device_vm_object, interfac

return return_data

def get_vmware_guest_info(self, vmware_object):
"""
Return the guest info of a VMware VM. Reading it is a round trip to vCenter, sources which already
retrieved it can return their copy.

Parameters
----------
vmware_object: vim.VirtualMachine
the VM

Returns
-------
vim.vm.GuestInfo, None: the guest info
"""

return grab(vmware_object, "guest")

def return_longest_matching_prefix_for_ip(self, ip_to_match=None, site_name=None) -> Optional[NBPrefix]:
"""
This is a lazy approach to find the longest matching prefix to an IP address.
Expand Down Expand Up @@ -539,10 +556,14 @@ def add_update_interface(self, interface_object, device_object, interface_data,

interface_object.update(data={"primary_mac_address": primary_mac_address_object}, source=self)

vmware_guest_info = None
if type(device_object) == NBVM:
vmware_guest_info = self.get_vmware_guest_info(vmware_object)

# skip handling of IPs for VMs with not installed/running guest tools
skip_ip_handling = False
if type(device_object) == NBVM and vmware_object is not None and \
grab(vmware_object, 'guest.toolsRunningStatus') != "guestToolsRunning":
grab(vmware_guest_info, 'toolsRunningStatus') != "guestToolsRunning":
log.debug(f"VM '{device_object.name}' guest tool status is 'NotRunning', skipping IP handling")
skip_ip_handling = True

Expand Down Expand Up @@ -818,7 +839,7 @@ def add_update_interface(self, interface_object, device_object, interface_data,
# (seen on old TMOS releases), not a statement that every address is gone. Keep what is
# in NetBox instead of tearing it off on every run. A real removal still reports the
# interface, just without an address, so that case is unaffected
reported_interfaces = grab(vmware_object, "guest.net")
reported_interfaces = grab(vmware_guest_info, "net")
if type(device_object) == NBVM and isinstance(reported_interfaces, list) and \
len(reported_interfaces) == 0:
log.debug(f"VM '{device_object.name}' guest tools report no network interface at all, "
Expand Down
Loading
Loading