Skip to content

Commit 4a61095

Browse files
committed
adds CDP info to ESXi host nic description if available #350
1 parent c6d617c commit 4a61095

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

module/sources/vmware/connection.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,14 @@ def add_host(self, obj):
17681768

17691769
# now iterate over all physical interfaces and collect data
17701770
pnic_data_dict = dict()
1771+
pnic_hints = dict()
1772+
# noinspection PyBroadException
1773+
try:
1774+
for hint in obj.configManager.networkSystem.QueryNetworkHint(""):
1775+
pnic_hints[hint.device] = hint
1776+
except Exception:
1777+
pass
1778+
17711779
for pnic in grab(obj, "config.network.pnic", fallback=list()):
17721780

17731781
pnic_name = grab(pnic, "device")
@@ -1820,7 +1828,6 @@ def add_host(self, obj):
18201828

18211829
# check vlans on this pnic
18221830
pnic_vlans = list()
1823-
18241831
for pg_name, pg_data in self.network_data["host_pgroup"][name].items():
18251832

18261833
if pnic_name in pg_data.get("nics", list()):
@@ -1831,6 +1838,15 @@ def add_host(self, obj):
18311838

18321839
pnic_mac_address = normalize_mac_address(grab(pnic, "mac"))
18331840

1841+
if pnic_hints.get(pnic_name) is not None:
1842+
pnic_switch_port = grab(pnic_hints.get(pnic_name), 'connectedSwitchPort')
1843+
if pnic_switch_port is not None:
1844+
pnic_sp_sys_name = grab(pnic_switch_port, 'systemName')
1845+
if pnic_sp_sys_name is None:
1846+
pnic_sp_sys_name = grab(pnic_switch_port, 'devId')
1847+
if pnic_sp_sys_name is not None:
1848+
pnic_description += f" (conn: {pnic_sp_sys_name} - {grab(pnic_switch_port, 'portId')})"
1849+
18341850
if self.settings.host_nic_exclude_by_mac_list is not None and \
18351851
pnic_mac_address in self.settings.host_nic_exclude_by_mac_list:
18361852
log.debug2(f"Host NIC with MAC '{pnic_mac_address}' excluded from sync. Skipping")

0 commit comments

Comments
 (0)