fix(baremetal): mac address of BMC not found

This commit is contained in:
Zexi Li
2022-12-15 11:33:21 +08:00
parent e465a65dcc
commit 4e53f95ca6
2 changed files with 30 additions and 16 deletions
+3 -3
View File
@@ -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
}
+27 -13
View File
@@ -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")