Skip to content

Commit

Permalink
supermicro: fallback to identifying model number from the board ID
Browse files Browse the repository at this point in the history
for when neither the XML or Redfish APIs indicate the device model
number
  • Loading branch information
joelrebel committed Jan 12, 2025
1 parent 8023a68 commit 105a48a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
dario.cat/mergo v1.0.1
github.com/Jeffail/gabs/v2 v2.7.0
github.com/bmc-toolbox/common v0.0.0-20241031162543-6b96e5981a0d
github.com/bmc-toolbox/common v0.0.0-20250112191656-b6de52e8303d
github.com/bombsimon/logrusr/v2 v2.0.1
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v1.4.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22 h1:a0MBqYm44o0N
github.com/VictorLowther/soap v0.0.0-20150314151524-8e36fca84b22/go.mod h1:/B7V22rcz4860iDqstGvia/2+IYWXf3/JdQCVd/1D2A=
github.com/bmc-toolbox/common v0.0.0-20241031162543-6b96e5981a0d h1:dMmFDAAEpXizInaNwPSa5LM6tX/xDIPKjL6v9jYfMxo=
github.com/bmc-toolbox/common v0.0.0-20241031162543-6b96e5981a0d/go.mod h1:Cdnkm+edb6C0pVkyCrwh3JTXAe0iUF9diDG/DztPI9I=
github.com/bmc-toolbox/common v0.0.0-20250112191656-b6de52e8303d h1:5c0jhS9jNLm1t3GVEESsWv+p6recFRLGW90zp8HDIDs=
github.com/bmc-toolbox/common v0.0.0-20250112191656-b6de52e8303d/go.mod h1:Cdnkm+edb6C0pVkyCrwh3JTXAe0iUF9diDG/DztPI9I=
github.com/bombsimon/logrusr/v2 v2.0.1 h1:1VgxVNQMCvjirZIYaT9JYn6sAVGVEcNtRE0y4mvaOAM=
github.com/bombsimon/logrusr/v2 v2.0.1/go.mod h1:ByVAX+vHdLGAfdroiMg6q0zgq2FODY2lc5YJvzmOJio=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand Down
1 change: 1 addition & 0 deletions providers/supermicro/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
ErrXMLAPIUnsupported = errors.New("XML API is unsupported")
ErrModelUnknown = errors.New("Model number unknown")
ErrModelUnsupported = errors.New("Model not supported")
ErrBoardIDUnknown = errors.New("BoardID could not be identified")
ErrUnexpectedResponse = errors.New("Unexpected response content")
ErrUnexpectedStatusCode = errors.New("Unexpected status code")
)
Expand Down
56 changes: 53 additions & 3 deletions providers/supermicro/x11.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/bmc-toolbox/common"
"github.com/go-logr/logr"
"github.com/pkg/errors"
"github.com/stmcginnis/gofish/oem/smc"
"github.com/stmcginnis/gofish/redfish"
)

Expand All @@ -36,6 +37,23 @@ func (c *x11) deviceModel() string {
}

func (c *x11) queryDeviceModel(ctx context.Context) (string, error) {
model, err := c.deviceModelFromFruInfo(ctx)
if err != nil {
// Identify BoardID from Redfish since fru info failed to return the information
model, err2 := c.deviceModelFromBoardID(ctx)
if err2 != nil {
return "", errors.Wrap(err, err2.Error())
}

c.model = model
return model, nil
}

c.model = model
return model, nil
}

func (c *x11) deviceModelFromFruInfo(ctx context.Context) (string, error) {
errBoardPartNumUnknown := errors.New("baseboard part number unknown")
data, err := c.fruInfo(ctx)
if err != nil {
Expand All @@ -47,14 +65,46 @@ func (c *x11) queryDeviceModel(ctx context.Context) (string, error) {
}

partNum := strings.TrimSpace(data.Board.PartNum)

if data.Board == nil || partNum == "" {
return "", errors.Wrap(errBoardPartNumUnknown, "baseboard part number empty")
}

c.model = common.FormatProductName(partNum)
return common.FormatProductName(partNum), nil
}

func (c *x11) deviceModelFromBoardID(ctx context.Context) (string, error) {
if err := c.redfishSession(ctx); err != nil {
return "", err
}

chassis, err := c.redfish.Chassis(ctx)
if err != nil {
return "", err
}

var boardID string
for _, ch := range chassis {
smcChassis, err := smc.FromChassis(ch)
if err != nil {
return "", errors.Wrap(ErrBoardIDUnknown, err.Error())
}

if smcChassis.BoardID != "" {
boardID = smcChassis.BoardID
break
}
}

if boardID == "" {
return "", ErrBoardIDUnknown
}

model := common.SupermicroModelFromBoardID(boardID)
if model == "" {
return "", errors.Wrap(ErrModelUnknown, "unable to identify model from board ID: "+boardID)
}

return c.model, nil
return model, nil
}

func (c *x11) fruInfo(ctx context.Context) (*FruInfo, error) {
Expand Down

0 comments on commit 105a48a

Please sign in to comment.