Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ASRockRack provider #196

Merged
merged 42 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a9e2dff
Add methods, initial work to probe for ASRR BMCs
joelrebel Feb 9, 2021
d7ddf5d
providers/asrockrack: Implment BMC firmware update, version info methods
joelrebel Feb 9, 2021
323d4d6
bmc: Add firmware update/getter interface methods
joelrebel Feb 9, 2021
096dd80
lint fixes
joelrebel Feb 9, 2021
7307fa0
asrockrack: firmware updates
joelrebel Feb 11, 2021
9ba38e6
asrockrack: implement bmclib (older) v0 interface methods for compati…
joelrebel Feb 11, 2021
3d049a5
asrockrack: update info logging
joelrebel Feb 11, 2021
04bd8fd
asrockrack: add skipLogout bool to ignore Close() invocation
joelrebel Feb 11, 2021
08f6ec4
discover: fix ASRR probe test and rename file for consistency
joelrebel Feb 11, 2021
4e6ac59
asrockrack: fix minor lint issues
joelrebel Feb 11, 2021
acb54b4
providers: implement stub Firmware interface methods
joelrebel Feb 11, 2021
6b41052
bmc/firmware: Add BIOS firmware interface methods
joelrebel Feb 12, 2021
d2c1eaa
examples: purge testing leftovers
joelrebel Feb 12, 2021
a51c581
client: Add remaining FirmwareBIOS* interface methods
joelrebel Feb 12, 2021
c7a10f6
asrockrack: update log levels to 1
joelrebel Feb 12, 2021
2dcefc2
asrockrack: Add BIOS firmware update support
joelrebel Feb 12, 2021
22835e5
Add v1, v2 bmclib client examples
joelrebel Feb 12, 2021
8422ccd
devices/interfaces: purge Firmware interface, its now made available …
joelrebel Feb 17, 2021
d311fd6
Add context paramter to Close()
joelrebel Feb 11, 2021
6441553
Add methods, initial work to probe for ASRR BMCs
joelrebel Feb 9, 2021
5c150f7
lint fixes
joelrebel Feb 9, 2021
01f8923
providers: implement stub Firmware interface methods
joelrebel Feb 11, 2021
2b52025
providers/asrockrack: various linting fixes
joelrebel Feb 21, 2021
39b616a
providers/asrockrack: move test init into TestMain
joelrebel Feb 21, 2021
9070351
client: move asrockrack registry
joelrebel Feb 21, 2021
f099ec7
providers/asrockrack: implement the registrar.Verifier interface
joelrebel Feb 16, 2021
a688310
client: register asrockrack driver
joelrebel Feb 16, 2021
a09e661
examples/v2: clean up since the provider driver is registered
joelrebel Feb 16, 2021
fa8e5f5
client: point registry logger after opts are set
joelrebel Feb 23, 2021
7e81b00
examples/v2: pass in logger to NewClient
joelrebel Feb 23, 2021
f574d21
bmc: update firmware interface to accept an io.Reader
joelrebel Feb 23, 2021
2081cd9
providers/asrockrack: accept a io.Reader interface
joelrebel Feb 23, 2021
bb6568f
purge asrockrack references from the older discover/probe methods
joelrebel Feb 23, 2021
3bb9a04
examples/v2: update to include the BMC FW flash example
joelrebel Feb 23, 2021
229dca9
examples: fix example versions
joelrebel Mar 8, 2021
c0c4dfc
providers/asrockrack: purge unused consts
joelrebel Mar 8, 2021
56ed33d
go mod tidy
joelrebel Mar 8, 2021
a514cb6
client: fix misalligned comment
joelrebel Mar 8, 2021
bb18bfe
providers/asrockrack: purge unused context from struct
joelrebel Mar 9, 2021
09da9d4
devices/interfaces: purge older Firmware interface that crept back in…
joelrebel Mar 9, 2021
3a22d5e
client, providers/asrockrack: purge unused context variable
joelrebel Mar 21, 2021
8c2ffa9
providers/asrockrack: fix redundant error checks
joelrebel Mar 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions bmc/firmware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
package bmc

import (
"context"
"errors"
"fmt"
"io"

"github.com/hashicorp/go-multierror"
)

// BMCVersionGetter retrieves the current BMC firmware version information
type BMCVersionGetter interface {
GetBMCVersion(ctx context.Context) (version string, err error)
}

// BMCFirmwareUpdater upgrades the BMC firmware
type BMCFirmwareUpdater interface {
FirmwareUpdateBMC(ctx context.Context, fileReader io.Reader) (err error)
}

// BIOSVersionGetter retrieves the current BIOS firmware version information
type BIOSVersionGetter interface {
GetBIOSVersion(ctx context.Context) (version string, err error)
}

// BIOSFirmwareUpdater upgrades the BIOS firmware
type BIOSFirmwareUpdater interface {
FirmwareUpdateBIOS(ctx context.Context, fileReader io.Reader) (err error)
}

// GetBMCVersion returns the BMC firmware version, trying all interface implementations passed in
func GetBMCVersion(ctx context.Context, p []BMCVersionGetter) (version string, err error) {
Loop:
for _, elem := range p {
select {
case <-ctx.Done():
err = multierror.Append(err, ctx.Err())
break Loop
default:
if elem != nil {
version, vErr := elem.GetBMCVersion(ctx)
if vErr != nil {
err = multierror.Append(err, vErr)
continue
}
return version, nil
}
}
}

return version, multierror.Append(err, errors.New("failed to get BMC version"))
}

// GetBMCVersionFromInterfaces pass through to library function
func GetBMCVersionFromInterfaces(ctx context.Context, generic []interface{}) (version string, err error) {
bmcVersionGetter := make([]BMCVersionGetter, 0)
for _, elem := range generic {
switch p := elem.(type) {
case BMCVersionGetter:
bmcVersionGetter = append(bmcVersionGetter, p)
default:
e := fmt.Sprintf("not a BMCVersionGetter implementation: %T", p)
err = multierror.Append(err, errors.New(e))
}
}
if len(bmcVersionGetter) == 0 {
return version, multierror.Append(err, errors.New("no BMCVersionGetter implementations found"))
}

return GetBMCVersion(ctx, bmcVersionGetter)
}

// UpdateBMCFirmware upgrades the BMC firmware, trying all interface implementations passed ini
func UpdateBMCFirmware(ctx context.Context, fileReader io.Reader, p []BMCFirmwareUpdater) (err error) {
Loop:
for _, elem := range p {
select {
case <-ctx.Done():
err = multierror.Append(err, ctx.Err())
break Loop
default:
if elem != nil {
uErr := elem.FirmwareUpdateBMC(ctx, fileReader)
if uErr != nil {
err = multierror.Append(err, uErr)
continue
}
return nil
}
}
}

return multierror.Append(err, errors.New("failed to update BMC firmware"))

}

// UpdateBMCFirmwareFromInterfaces pass through to library function
func UpdateBMCFirmwareFromInterfaces(ctx context.Context, fileReader io.Reader, generic []interface{}) (err error) {
bmcFirmwareUpdater := make([]BMCFirmwareUpdater, 0)
for _, elem := range generic {
switch p := elem.(type) {
case BMCFirmwareUpdater:
bmcFirmwareUpdater = append(bmcFirmwareUpdater, p)
default:
e := fmt.Sprintf("not a BMCFirmwareUpdater implementation: %T", p)
err = multierror.Append(err, errors.New(e))
}
}
if len(bmcFirmwareUpdater) == 0 {
return multierror.Append(err, errors.New("no BMCFirmwareUpdater implementations found"))
}

return UpdateBMCFirmware(ctx, fileReader, bmcFirmwareUpdater)
}

// GetBIOSVersion returns the BMC firmware version, trying all interface implementations passed in
func GetBIOSVersion(ctx context.Context, p []BIOSVersionGetter) (version string, err error) {
Loop:
for _, elem := range p {
select {
case <-ctx.Done():
err = multierror.Append(err, ctx.Err())
break Loop
default:
if elem != nil {
version, vErr := elem.GetBIOSVersion(ctx)
if vErr != nil {
err = multierror.Append(err, vErr)
continue
}
return version, nil
}
}
}

return version, multierror.Append(err, errors.New("failed to get BIOS version"))
}

// GetBIOSVersionFromInterfaces pass through to library function
func GetBIOSVersionFromInterfaces(ctx context.Context, generic []interface{}) (version string, err error) {
biosVersionGetter := make([]BIOSVersionGetter, 0)
for _, elem := range generic {
switch p := elem.(type) {
case BIOSVersionGetter:
biosVersionGetter = append(biosVersionGetter, p)
default:
e := fmt.Sprintf("not a BIOSVersionGetter implementation: %T", p)
err = multierror.Append(err, errors.New(e))
}
}
if len(biosVersionGetter) == 0 {
return version, multierror.Append(err, errors.New("no BIOSVersionGetter implementations found"))
}

return GetBIOSVersion(ctx, biosVersionGetter)
}

// UpdateBIOSFirmware upgrades the BIOS firmware, trying all interface implementations passed ini
func UpdateBIOSFirmware(ctx context.Context, fileReader io.Reader, p []BIOSFirmwareUpdater) (err error) {
Loop:
for _, elem := range p {
select {
case <-ctx.Done():
err = multierror.Append(err, ctx.Err())
break Loop
default:
if elem != nil {
uErr := elem.FirmwareUpdateBIOS(ctx, fileReader)
if uErr != nil {
err = multierror.Append(err, uErr)
continue
}
return nil
}
}
}

return multierror.Append(err, errors.New("failed to update BIOS firmware"))

}

// GetBMCVersionFromInterfaces pass through to library function
func UpdateBIOSFirmwareFromInterfaces(ctx context.Context, fileReader io.Reader, generic []interface{}) (err error) {
biosFirmwareUpdater := make([]BIOSFirmwareUpdater, 0)
for _, elem := range generic {
switch p := elem.(type) {
case BIOSFirmwareUpdater:
biosFirmwareUpdater = append(biosFirmwareUpdater, p)
default:
e := fmt.Sprintf("not a BIOSFirmwareUpdater implementation: %T", p)
err = multierror.Append(err, errors.New(e))
}
}
if len(biosFirmwareUpdater) == 0 {
return multierror.Append(err, errors.New("no BIOSFirmwareUpdater implementations found"))
}

return UpdateBIOSFirmware(ctx, fileReader, biosFirmwareUpdater)
}
Loading