From 915a2afbed06f8d74e77464edd8da1f94ac645ab Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 5 Nov 2021 08:24:01 -0400 Subject: [PATCH] Detect 'default' nic by matching connection address This carries forward the configure 'default' nic for systems that nominally have multiple interfaces. Change-Id: I5916efde5aa57d7682fe08eff0fdc8864d79aa52 --- pyghmi/redfish/command.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pyghmi/redfish/command.py b/pyghmi/redfish/command.py index f64c4411..5ec29368 100644 --- a/pyghmi/redfish/command.py +++ b/pyghmi/redfish/command.py @@ -254,6 +254,11 @@ class Command(object): self._varfwinventory = None self._oem = None self._gpool = pool + for addrinf in socket.getaddrinfo(bmc, 0, 0, socket.SOCK_STREAM): + if addrinf[0] == socket.AF_INET: + self._bmcv4ip = socket.inet_pton(addrinf[0], addrinf[-1][0]) + elif addrinf[0] == socket.AF_INET6: + self._bmcv6ip = socket.inet_pton(addrinf[0], addrinf[-1][0]) self.wc.set_header('Accept', 'application/json') self.wc.set_header('User-Agent', 'pyghmi') self.wc.set_header('Accept-Encoding', 'gzip') @@ -807,6 +812,16 @@ class Command(object): if not nicinfo.get('InterfaceEnabled', True): # skip disabled interfaces continue + for addrs in nicinfo.get('IPv4Addresses', []): + v4addr = socket.inet_pton( + socket.AF_INET, addrs.get('Address', '0.0.0.0')) + if self._bmcv4ip == v4addr: + return curl + for addrs in nicinfo.get('IPv6Addresses', []): + v6addr = socket.inet_pton( + socket.AF_INET6, addrs.get('Address', '::')) + if self._bmcv6ip == v6addr: + return curl foundnics += 1 lastnicurl = curl if name is None and foundnics != 1: