diff --git a/pkg/util/redfish/driver.go b/pkg/util/redfish/driver.go index c9eb82666d..5b69046238 100644 --- a/pkg/util/redfish/driver.go +++ b/pkg/util/redfish/driver.go @@ -107,7 +107,7 @@ func NewRedfishDriver(ctx context.Context, endpoint string, username, password s drv := factory.NewApi(endpoint, username, password, debug) err := drv.Probe(ctx) if err == nil { - log.Infof("Found %s Redfish REST Api Driver", k) + log.Infof("Found %s Redfish REST Api Driver for endpoint %q", k, endpoint) return drv } } @@ -117,9 +117,9 @@ func NewRedfishDriver(ctx context.Context, endpoint string, username, password s drv := defaultFactory.NewApi(endpoint, username, password, debug) err := drv.Probe(ctx) if err == nil { - log.Infof("Use generic Redfish REST Api Driver") + log.Infof("Use generic Redfish REST Api Driver for endpoint %q", endpoint) return drv } - log.Errorf("No Redfish driver found") + log.Errorf("No Redfish driver found of endpoint %q", endpoint) return nil } diff --git a/pkg/util/redfish/redfish.go b/pkg/util/redfish/redfish.go index 3281c114eb..9ec76f24b5 100644 --- a/pkg/util/redfish/redfish.go +++ b/pkg/util/redfish/redfish.go @@ -445,18 +445,11 @@ func (r *SBaseRedfishClient) GetSystemInfo(ctx context.Context) (string, SSystem if err != nil { return path, sysInfo, errors.Wrapf(err, "Get EthernetInterface[%d] error", i) } - var macAddr string - for _, key := range []string{ - "MacAddress", - "MACAddress", - "PermanentMACAddress", - } { - macAddr, _ = nicInfo.GetString(key) - if len(macAddr) > 0 { - break - } + macAddr, err := r.parseMAC(nicInfo) + if err != nil { + log.Warningf("GetSystemInfo parseMAC error: %v", err) } - sysInfo.EthernetNICs[i] = netutils.FormatMacAddr(macAddr) + sysInfo.EthernetNICs[i] = netutils.FormatMacAddr(macAddr.String()) } } } @@ -791,6 +784,24 @@ func (r *SBaseRedfishClient) GetConsoleJNLP(ctx context.Context) (string, error) return "", httperrors.ErrNotImplemented } +func (r *SBaseRedfishClient) parseMAC(ethJson jsonutils.JSONObject) (net.HardwareAddr, error) { + for _, key := range []string{ + "MacAddress", + "MACAddress", + "PermanentMACAddress", + } { + mac, _ := ethJson.GetString(key) + if len(mac) > 0 { + macAddr, err := net.ParseMAC(mac) + if err != nil { + return nil, errors.Wrapf(err, "ParseMAC %q", mac) + } + return macAddr, nil + } + } + return nil, errors.Errorf("Not found mac address from %s", ethJson.PrettyString()) +} + func (r *SBaseRedfishClient) GetLanConfigs(ctx context.Context) ([]types.SIPMILanConfig, error) { _, ethIfsJson, err := r.GetResource(ctx, "Managers", "0", "EthernetInterfaces") if err != nil { @@ -835,8 +846,11 @@ func (r *SBaseRedfishClient) GetLanConfigs(ctx context.Context) ([]types.SIPMILa src = "static" } conf.IPSrc = strings.ToLower(src) - mac, _ := ethJson.GetString("MACAddress") - conf.Mac, _ = net.ParseMAC(mac) + macAddr, err := r.parseMAC(ethJson) + if err != nil { + log.Warningf("parseMAC error: %v", err) + } + conf.Mac = macAddr var vlanId int64 if ethJson.Contains("VLAN") { vlanId, _ = ethJson.Int("VLAN", "VLANId")