Skip to content

Commit

Permalink
internal/sum: Convert providers/sum into an internal package
Browse files Browse the repository at this point in the history
  • Loading branch information
splaspood committed Jul 23, 2024
1 parent b7cfefb commit 89997ce
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 49 deletions.
24 changes: 0 additions & 24 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -111,7 +109,6 @@ func NewClient(host, user, pass string, opts ...Option) *Client {
openbmc: openbmc.Config{
Port: "443",
},
sum: sum.Exec{},
},
}

Expand Down Expand Up @@ -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.
Expand All @@ -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()
Expand Down
27 changes: 2 additions & 25 deletions providers/sum/sum.go → internal/sum/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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 {
Expand Down
42 changes: 42 additions & 0 deletions providers/supermicro/supermicro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -51,6 +52,10 @@ var (
providers.FeaturePowerSet,
providers.FeaturePowerState,
providers.FeatureBmcReset,
providers.FeatureGetBiosConfiguration,
providers.FeatureSetBiosConfiguration,
providers.FeatureSetBiosConfigurationFromFile,
providers.FeatureResetBiosConfiguration,
}
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 89997ce

Please sign in to comment.