Skip to content

Instantly share code, notes, and snippets.

@joelrebel
Created August 29, 2024 13:24
Show Gist options
  • Save joelrebel/0718ca468900dbc4eeeaf1a51809b937 to your computer and use it in GitHub Desktop.
Save joelrebel/0718ca468900dbc4eeeaf1a51809b937 to your computer and use it in GitHub Desktop.
diff --git a/providers/supermicro/supermicro.go b/providers/supermicro/supermicro.go
index 2de6bdf..dac82b9 100644
--- a/providers/supermicro/supermicro.go
+++ b/providers/supermicro/supermicro.go
@@ -197,7 +197,6 @@ func (c *Client) Open(ctx context.Context) (err error) {
c.serviceClient.setCsrfToken(csrfToken)
c.bmc, err = c.bmcQueryor(ctx)
-
if err != nil {
return closeWithError(ctx, errors.Wrap(bmclibErrs.ErrLoginFailed, err.Error()))
}
@@ -282,16 +281,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
@@ -300,6 +319,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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment