diff --git a/bmc/bios.go b/bmc/bios.go index 13c9d3a8..87da3eb7 100644 --- a/bmc/bios.go +++ b/bmc/bios.go @@ -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 { @@ -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: @@ -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 { diff --git a/client.go b/client.go index e9bd76ca..cd4f4d95 100644 --- a/client.go +++ b/client.go @@ -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()