From 89997ce911345c66e3e948c0f98a31ea461b15a2 Mon Sep 17 00:00:00 2001 From: "James W. Brinkerhoff" Date: Tue, 23 Jul 2024 12:16:35 -0400 Subject: [PATCH] internal/sum: Convert providers/sum into an internal package --- client.go | 24 ----------------- {providers => internal}/sum/sum.go | 27 ++----------------- providers/supermicro/supermicro.go | 42 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 49 deletions(-) rename {providers => internal}/sum/sum.go (88%) diff --git a/client.go b/client.go index 7ed7d5aa..e9bd76ca 100644 --- a/client.go +++ b/client.go @@ -23,7 +23,6 @@ import ( "github.com/bmc-toolbox/bmclib/v2/providers/openbmc" "github.com/bmc-toolbox/bmclib/v2/providers/redfish" "github.com/bmc-toolbox/bmclib/v2/providers/rpc" - "github.com/bmc-toolbox/bmclib/v2/providers/sum" "github.com/bmc-toolbox/bmclib/v2/providers/supermicro" "github.com/bmc-toolbox/common" "github.com/go-logr/logr" @@ -73,7 +72,6 @@ type providerConfig struct { supermicro supermicro.Config rpc rpc.Provider openbmc openbmc.Config - sum sum.Exec } // NewClient returns a new Client struct @@ -111,7 +109,6 @@ func NewClient(host, user, pass string, opts ...Option) *Client { openbmc: openbmc.Config{ Port: "443", }, - sum: sum.Exec{}, }, } @@ -265,23 +262,6 @@ func (c *Client) registerOpenBMCProvider() { c.Registry.Register(openbmc.ProviderName, openbmc.ProviderProtocol, openbmc.Features, nil, driver) } -// register sum provider -func (c *Client) registerSumProvider() error { - sumOpts := []sum.Option{ - sum.WithLogger(c.Logger), - sum.WithSumPath(c.providerConfig.sum.SumPath), - } - - driverSum, err := sum.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, sumOpts...) - if err != nil { - return err - } - - c.Registry.Register(sum.ProviderName, sum.ProviderProtocol, sum.Features, nil, driverSum) - - return nil -} - func (c *Client) registerProviders() { // register the rpc provider // without the consumer URL there is no way to send RPC requests. @@ -299,10 +279,6 @@ func (c *Client) registerProviders() { c.Logger.Info("ipmitool provider not available", "error", err.Error()) } - if err := c.registerSumProvider(); err != nil { - c.Logger.Info("sum provider not available", "error", err.Error()) - } - c.registerASRRProvider() c.registerGofishProvider() c.registerIntelAMTProvider() diff --git a/providers/sum/sum.go b/internal/sum/sum.go similarity index 88% rename from providers/sum/sum.go rename to internal/sum/sum.go index 330bebda..5db01a31 100644 --- a/providers/sum/sum.go +++ b/internal/sum/sum.go @@ -6,28 +6,9 @@ import ( "os/exec" "strings" - "github.com/bmc-toolbox/bmclib/v2/providers" "github.com/bmc-toolbox/common" "github.com/bmc-toolbox/common/config" "github.com/go-logr/logr" - "github.com/jacobweinstock/registrar" -) - -const ( - // ProviderName for the provider implementation - ProviderName = "sum" - // ProviderProtocol for the provider implementation - ProviderProtocol = "sum" -) - -var ( - // Features implemented by SUM - Features = registrar.Features{ - providers.FeatureGetBiosConfiguration, - providers.FeatureSetBiosConfiguration, - providers.FeatureSetBiosConfigurationFromFile, - providers.FeatureResetBiosConfiguration, - } ) // Conn for Sum connection details @@ -92,10 +73,6 @@ func (c *Exec) Close(ctx context.Context) (err error) { return nil } -func (c *Exec) Name() string { - return ProviderName -} - func (s *Exec) run(ctx context.Context, command string, additionalArgs ...string) (output string, err error) { // TODO(splaspood) use a tmp file here (as sum supports) to read the password sumArgs := []string{"-i", s.Host, "-u", s.Username, "-p", s.Password, "-c", command} @@ -249,10 +226,10 @@ func (s *Exec) SetBiosConfiguration(ctx context.Context, biosConfig map[string]s return } - return s.SetBIOSConfigurationFromFile(ctx, xmlData) + return s.SetBiosConfigurationFromFile(ctx, xmlData) } -func (s *Exec) SetBIOSConfigurationFromFile(ctx context.Context, cfg string) (err error) { +func (s *Exec) SetBiosConfigurationFromFile(ctx context.Context, cfg string) (err error) { // Open tmp file to hold cfg inputConfigTmpFile, err := os.CreateTemp("", "bmclib") if err != nil { diff --git a/providers/supermicro/supermicro.go b/providers/supermicro/supermicro.go index 902aa94f..0f24f2b5 100644 --- a/providers/supermicro/supermicro.go +++ b/providers/supermicro/supermicro.go @@ -19,6 +19,7 @@ import ( "github.com/bmc-toolbox/bmclib/v2/constants" "github.com/bmc-toolbox/bmclib/v2/internal/httpclient" "github.com/bmc-toolbox/bmclib/v2/internal/redfishwrapper" + "github.com/bmc-toolbox/bmclib/v2/internal/sum" "github.com/bmc-toolbox/bmclib/v2/providers" "github.com/bmc-toolbox/common" @@ -51,6 +52,10 @@ var ( providers.FeaturePowerSet, providers.FeaturePowerState, providers.FeatureBmcReset, + providers.FeatureGetBiosConfiguration, + providers.FeatureSetBiosConfiguration, + providers.FeatureSetBiosConfigurationFromFile, + providers.FeatureResetBiosConfiguration, } ) @@ -235,6 +240,42 @@ func (c *Client) Inventory(ctx context.Context) (device *common.Device, err erro return c.serviceClient.redfish.Inventory(ctx, false) } +// GetBiosConfiguration return bios configuration +func (c *Client) GetBiosConfiguration(ctx context.Context) (biosConfig map[string]string, err error) { + if c.serviceClient == nil || c.serviceClient.sum == nil { + return nil, errors.Wrap(bmclibErrs.ErrLoginFailed, "client not initialized") + } + + return c.serviceClient.sum.GetBiosConfiguration(ctx) +} + +// SetBiosConfiguration set bios configuration +func (c *Client) SetBiosConfiguration(ctx context.Context, biosConfig map[string]string) (err error) { + if c.serviceClient == nil || c.serviceClient.sum == nil { + return errors.Wrap(bmclibErrs.ErrLoginFailed, "client not initialized") + } + + return c.serviceClient.sum.SetBiosConfiguration(ctx, biosConfig) +} + +// SetBiosConfigurationFromFile sets the bios configuration from a raw vendor config file +func (c *Client) SetBIOSConfigurationFromFile(ctx context.Context, cfg string) (err error) { + if c.serviceClient == nil || c.serviceClient.sum == nil { + return errors.Wrap(bmclibErrs.ErrLoginFailed, "client not initialized") + } + + return c.serviceClient.sum.SetBiosConfigurationFromFile(ctx, cfg) +} + +// ResetBiosConfiguration sets the bios configuration back to "factory" defaults +func (c *Client) ResetBiosConfiguration(ctx context.Context) (err error) { + if c.serviceClient == nil || c.serviceClient.sum == nil { + return errors.Wrap(bmclibErrs.ErrLoginFailed, "client not initialized") + } + + return c.serviceClient.sum.ResetBiosConfiguration(ctx) +} + func (c *Client) bmcQueryor(ctx context.Context) (bmcQueryor, error) { x11 := newX11Client(c.serviceClient, c.log) x12 := newX12Client(c.serviceClient, c.log) @@ -393,6 +434,7 @@ type serviceClient struct { csrfToken string client *http.Client redfish *redfishwrapper.Client + sum *sum.Exec } func newBmcServiceClient(host, port, user, pass string, client *http.Client) *serviceClient {