From e14321b647739d9747225139e359c08fad4cf960 Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Mon, 27 Nov 2023 14:36:51 +0100 Subject: [PATCH] providers/dell: adds a helper method and implements Inventory(), PowerSet(), PowerStateGet() methods --- providers/dell/idrac.go | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/providers/dell/idrac.go b/providers/dell/idrac.go index f1282f5e..c47dee3b 100644 --- a/providers/dell/idrac.go +++ b/providers/dell/idrac.go @@ -40,12 +40,8 @@ var ( ) type Config struct { - HttpClient *http.Client - Port string - // VersionsNotCompatible is the list of incompatible redfish versions. - // - // With this option set, The bmclib.Registry.FilterForCompatible(ctx) method will not proceed on - // devices with the given redfish version(s). + HttpClient *http.Client + Port string VersionsNotCompatible []string RootCAs *x509.CertPool UseBasicAuth bool @@ -126,19 +122,26 @@ func (c *Conn) Open(ctx context.Context) (err error) { // because this uses the redfish interface and the redfish interface // is available across various BMC vendors, we verify the device we're connected to is dell. - manufacturer, err := c.deviceManufacturer(ctx) - if err != nil { + if err := c.deviceSupported(ctx); err != nil { if er := c.redfishwrapper.Close(ctx); er != nil { return fmt.Errorf("%v: %w", err, er) } + return err } - if !strings.Contains(strings.ToLower(manufacturer), common.VendorDell) { - if er := c.redfishwrapper.Close(ctx); er != nil { - return fmt.Errorf("%v: %w", err, er) - } - return bmclibErrs.ErrIncompatibleProvider + return nil +} + +func (c *Conn) deviceSupported(ctx context.Context) error { + manufacturer, err := c.deviceManufacturer(ctx) + if err != nil { + return err + } + + m := strings.ToLower(manufacturer) + if !strings.Contains(m, common.VendorDell) { + return errors.Wrap(bmclibErrs.ErrIncompatibleProvider, m) } return nil @@ -192,6 +195,16 @@ func (c *Conn) PowerStateGet(ctx context.Context) (state string, err error) { return c.redfishwrapper.SystemPowerStatus(ctx) } +// PowerSet sets the power state of a server +func (c *Conn) PowerSet(ctx context.Context, state string) (ok bool, err error) { + return c.redfishwrapper.PowerSet(ctx, state) +} + +// Inventory collects hardware inventory and install firmware information +func (c *Conn) Inventory(ctx context.Context) (device *common.Device, err error) { + return c.redfishwrapper.Inventory(ctx, false) +} + var errManufacturerUnknown = errors.New("error identifying device manufacturer") // deviceManufacturer returns the device manufacturer and model attributes