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

Supermicro redfish inventory support #299

Merged
merged 3 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 20 additions & 14 deletions providers/redfish/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors"
"github.com/bmc-toolbox/bmclib/v2/internal/redfishwrapper"
"github.com/pkg/errors"

"github.com/bmc-toolbox/common"
"github.com/pkg/errors"
gofishrf "github.com/stmcginnis/gofish/redfish"
)

Expand All @@ -29,34 +29,40 @@ var (
systemsOdataIDs = []string{
// Dells
"/redfish/v1/Systems/System.Embedded.1",
// Supermicros
"/redfish/v1/Systems/1",
}

// Supported Manager Odata IDs (BMCs)
managerOdataIDs = []string{
"/redfish/v1/Managers/iDRAC.Embedded.1",
// Supermicros
"/redfish/v1/Managers/1",
}
)

// inventory struct wraps redfish connection
type inventory struct {
client *redfishwrapper.Client
failOnError bool
softwareInventory []*gofishrf.SoftwareInventory
}

func (c *Conn) Inventory(ctx context.Context) (device *common.Device, err error) {
// initialize inventory object
// the redfish client is assigned here to perform redfish Get/Delete requests
inv := &inventory{client: c.redfishwrapper}
inv := &inventory{client: c.redfishwrapper, failOnError: c.failInventoryOnError}

// TODO: this can soft fail
updateService, err := c.redfishwrapper.UpdateService()
if err != nil {
if err != nil && inv.failOnError {
return nil, errors.Wrap(bmclibErrs.ErrRedfishSoftwareInventory, err.Error())
}

inv.softwareInventory, err = updateService.FirmwareInventories()
if err != nil {
return nil, errors.Wrap(bmclibErrs.ErrRedfishSoftwareInventory, err.Error())
if updateService != nil {
inv.softwareInventory, err = updateService.FirmwareInventories()
if err != nil && inv.failOnError {
return nil, errors.Wrap(bmclibErrs.ErrRedfishSoftwareInventory, err.Error())
}
}

// initialize device to be populated with inventory
Expand All @@ -65,19 +71,19 @@ func (c *Conn) Inventory(ctx context.Context) (device *common.Device, err error)

// populate device Chassis components attributes
err = inv.chassisAttributes(ctx, device)
if err != nil {
if err != nil && inv.failOnError {
return nil, err
}

// populate device System components attributes
err = inv.systemAttributes(ctx, device)
if err != nil {
if err != nil && inv.failOnError {
return nil, err
}

// populate device BMC component attributes
err = inv.bmcAttributes(ctx, device)
if err != nil {
if err != nil && inv.failOnError {
return nil, err
}

Expand Down Expand Up @@ -149,19 +155,19 @@ func (i *inventory) chassisAttributes(ctx context.Context, device *common.Device
compatible++

err = i.collectEnclosure(ch, device)
if err != nil {
if err != nil && i.failOnError {
return err
}

err = i.collectPSUs(ch, device)
if err != nil {
if err != nil && i.failOnError {
return err
}

}

err = i.collectCPLDs(device)
if err != nil {
if err != nil && i.failOnError {
return err
}

Expand Down Expand Up @@ -207,7 +213,7 @@ func (i *inventory) systemAttributes(ctx context.Context, device *common.Device)
// execute collector methods
for _, f := range funcs {
err := f(sys, device)
if err != nil {
if err != nil && i.failOnError {
return err
}
}
Expand Down
25 changes: 18 additions & 7 deletions providers/redfish/inventory_collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func (i *inventory) collectEnclosure(ch *gofishrf.Chassis, device *common.Device
Description: ch.Description,
Vendor: common.FormatVendorName(ch.Manufacturer),
Model: ch.Model,
Serial: ch.SerialNumber,
Status: &common.Status{
Health: string(ch.Status.Health),
State: string(ch.Status.State),
Expand All @@ -27,6 +28,10 @@ func (i *inventory) collectEnclosure(ch *gofishrf.Chassis, device *common.Device
ChassisType: string(ch.ChassisType),
}

if e.Model == "" && ch.PartNumber != "" {
e.Model = ch.PartNumber
}

// include additional firmware attributes from redfish firmware inventory
i.firmwareAttributes(common.SlugEnclosure, e.ID, e.Firmware)

Expand Down Expand Up @@ -117,13 +122,16 @@ func (i *inventory) collectNICs(sys *gofishrf.ComputerSystem, device *common.Dev
}

for _, nic := range nics {

// collect network interface adaptor information
adapter, err := nic.NetworkAdapter()
if err != nil {
return err
}

if adapter == nil {
continue
}

n := &common.NIC{
Common: common.Common{
Vendor: common.FormatVendorName(adapter.Manufacturer),
Expand Down Expand Up @@ -167,20 +175,23 @@ func (i *inventory) collectNICs(sys *gofishrf.ComputerSystem, device *common.Dev
}

func (i *inventory) collectBIOS(sys *gofishrf.ComputerSystem, device *common.Device) (err error) {
bios, err := sys.Bios()
if err != nil {
return err
}

device.BIOS = &common.BIOS{
Common: common.Common{
Description: bios.Description,
Firmware: &common.Firmware{
Installed: sys.BIOSVersion,
},
},
}

bios, err := sys.Bios()
if err != nil {
return err
}

if bios != nil {
device.BIOS.Description = bios.Description
}

// include additional firmware attributes from redfish firmware inventory
i.firmwareAttributes(common.SlugBIOS, "BIOS", device.BIOS.Firmware)

Expand Down
10 changes: 6 additions & 4 deletions providers/redfish/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ var (

// Conn details for redfish client
type Conn struct {
redfishwrapper *redfishwrapper.Client
Log logr.Logger
redfishwrapper *redfishwrapper.Client
failInventoryOnError bool
Log logr.Logger
}

// New returns connection with a redfish client initialized
func New(host, port, user, pass string, log logr.Logger, opts ...redfishwrapper.Option) *Conn {
return &Conn{
Log: log,
redfishwrapper: redfishwrapper.NewClient(host, port, user, pass, opts...),
Log: log,
failInventoryOnError: false,
redfishwrapper: redfishwrapper.NewClient(host, port, user, pass, opts...),
}
}

Expand Down