Skip to content

Commit

Permalink
providers/supermicro/supermicro.go: Fix bmcQueryor to properly match …
Browse files Browse the repository at this point in the history
…queryor to model
  • Loading branch information
splaspood committed Sep 3, 2024
1 parent 7607864 commit 3d1fe09
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions providers/supermicro/supermicro.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,36 @@ func (c *Client) ResetBiosConfiguration(ctx context.Context) (err error) {
}

func (c *Client) bmcQueryor(ctx context.Context) (bmcQueryor, error) {
x11 := newX11Client(c.serviceClient, c.log)
x12 := newX12Client(c.serviceClient, c.log)
x13 := newX13Client(c.serviceClient, c.log)
x11bmc := newX11Client(c.serviceClient, c.log)
x12bmc := newX12Client(c.serviceClient, c.log)
x13bmc := newX13Client(c.serviceClient, c.log)

var queryor bmcQueryor

for _, bmc := range []bmcQueryor{x11, x12, x13} {
expected := func(deviceModel string, bmc bmcQueryor) bool {
deviceModel = strings.ToLower(deviceModel)
switch bmc.(type) {
case *x11:
if strings.HasPrefix(deviceModel, "x11") {
return true
}
case *x12:
if strings.HasPrefix(deviceModel, "x12") {
return true
}
case *x13:
if strings.HasPrefix(deviceModel, "x13") {
return true
}
}

return false
}

for _, bmc := range []bmcQueryor{x11bmc, x12bmc, x13bmc} {
var err error

_, err = bmc.queryDeviceModel(ctx)
deviceModel, err := bmc.queryDeviceModel(ctx)
if err != nil {
if errors.Is(err, ErrXMLAPIUnsupported) {
continue
Expand All @@ -300,6 +320,11 @@ func (c *Client) bmcQueryor(ctx context.Context) (bmcQueryor, error) {
return nil, errors.Wrap(ErrModelUnknown, err.Error())
}

// ensure the device model matches the expected queryor
if !expected(deviceModel, bmc) {
continue
}

queryor = bmc
break
}
Expand Down

0 comments on commit 3d1fe09

Please sign in to comment.