Skip to content

Commit

Permalink
Add SetBiosConfigurationFromFile client functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans committed Oct 1, 2024
1 parent da8a93f commit 0d0db62
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
55 changes: 55 additions & 0 deletions bmc/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type biosConfigurationGetterProvider struct {

type BiosConfigurationSetter interface {
SetBiosConfiguration(ctx context.Context, biosConfig map[string]string) (err error)
SetBiosConfigurationFromFile(ctx context.Context, cfg string) (err error)
}

type biosConfigurationSetterProvider struct {
Expand Down Expand Up @@ -92,6 +93,34 @@ Loop:
return metadata, multierror.Append(err, errors.New("failure to set bios configuration"))
}

func setBiosConfigurationFromFile(ctx context.Context, generic []biosConfigurationSetterProvider, cfg string) (metadata Metadata, err error) {
metadata = newMetadata()
Loop:
for _, elem := range generic {
if elem.BiosConfigurationSetter == nil {
continue
}
select {
case <-ctx.Done():
err = multierror.Append(err, ctx.Err())
break Loop
default:
metadata.ProvidersAttempted = append(metadata.ProvidersAttempted, elem.name)
vErr := elem.SetBiosConfigurationFromFile(ctx, cfg)
if vErr != nil {
err = multierror.Append(err, errors.WithMessagef(vErr, "provider: %v", elem.name))
err = multierror.Append(err, vErr)
continue

}
metadata.SuccessfulProvider = elem.name
return metadata, nil
}
}

return metadata, multierror.Append(err, errors.New("failure to set bios configuration from file"))
}

func resetBiosConfiguration(ctx context.Context, generic []biosConfigurationResetterProvider) (metadata Metadata, err error) {
metadata = newMetadata()
Loop:
Expand Down Expand Up @@ -172,6 +201,32 @@ func SetBiosConfigurationInterfaces(ctx context.Context, generic []interface{},
return setBiosConfiguration(ctx, implementations, biosConfig)
}

func SetBiosConfigurationFromFileInterfaces(ctx context.Context, generic []interface{}, cfg string) (metadata Metadata, err error) {
implementations := make([]biosConfigurationSetterProvider, 0)
for _, elem := range generic {
temp := biosConfigurationSetterProvider{name: getProviderName(elem)}
switch p := elem.(type) {
case BiosConfigurationSetter:
temp.BiosConfigurationSetter = p
implementations = append(implementations, temp)
default:
e := fmt.Sprintf("not a BiosConfigurationSetter implementation: %T", p)
err = multierror.Append(err, errors.New(e))
}
}
if len(implementations) == 0 {
return metadata, multierror.Append(
err,
errors.Wrap(
bmclibErrs.ErrProviderImplementation,
("no BiosConfigurationSetter implementations found"),
),
)
}

return setBiosConfigurationFromFile(ctx, implementations, cfg)
}

func ResetBiosConfigurationInterfaces(ctx context.Context, generic []interface{}) (metadata Metadata, err error) {
implementations := make([]biosConfigurationResetterProvider, 0)
for _, elem := range generic {
Expand Down
11 changes: 11 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,17 @@ func (c *Client) SetBiosConfiguration(ctx context.Context, biosConfig map[string
return err
}

func (c *Client) SetBiosConfigurationFromFile(ctx context.Context, cfg string) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "SetBiosConfigurationFromFile")
defer span.End()

metadata, err := bmc.SetBiosConfigurationFromFileInterfaces(ctx, c.registry().GetDriverInterfaces(), cfg)
c.setMetadata(metadata)
metadata.RegisterSpanAttributes(c.Auth.Host, span)

return err
}

func (c *Client) ResetBiosConfiguration(ctx context.Context) (err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "ResetBiosConfiguration")
defer span.End()
Expand Down

0 comments on commit 0d0db62

Please sign in to comment.