diff --git a/client.go b/client.go index 437a919d..ba170551 100644 --- a/client.go +++ b/client.go @@ -145,38 +145,35 @@ func (c *Client) registerRPCProvider() error { return nil } -func (c *Client) registerProviders() { - // register the rpc provider - // without the consumer URL there is no way to send RPC requests. - if c.providerConfig.rpc.ConsumerURL != "" { - // when the rpc provider is to be used, we won't register any other providers. - err := c.registerRPCProvider() - if err == nil { - c.Logger.Info("note: with the rpc provider registered, no other providers will be registered and available") - return - } - c.Logger.Info("failed to register rpc provider, falling back to registering all other providers", "error", err.Error()) - } - // register ipmitool provider +// register ipmitool provider +func (c *Client) registerIPMIProvider() error { ipmiOpts := []ipmitool.Option{ ipmitool.WithLogger(c.Logger), ipmitool.WithPort(c.providerConfig.ipmitool.Port), ipmitool.WithCipherSuite(c.providerConfig.ipmitool.CipherSuite), ipmitool.WithIpmitoolPath(c.providerConfig.ipmitool.IpmitoolPath), } - if driverIpmitool, err := ipmitool.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, ipmiOpts...); err == nil { - c.Registry.Register(ipmitool.ProviderName, ipmitool.ProviderProtocol, ipmitool.Features, nil, driverIpmitool) - } else { - c.Logger.Info("ipmitool provider not available", "error", err.Error()) + + driverIpmitool, err := ipmitool.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, ipmiOpts...) + if err != nil { + return err } - // register ASRR vendorapi provider + c.Registry.Register(ipmitool.ProviderName, ipmitool.ProviderProtocol, ipmitool.Features, nil, driverIpmitool) + + return nil +} + +// register ASRR vendorapi provider +func (c *Client) registerASRRProvider() { asrHttpClient := *c.httpClient asrHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone() driverAsrockrack := asrockrack.NewWithOptions(c.Auth.Host+":"+c.providerConfig.asrock.Port, c.Auth.User, c.Auth.Pass, c.Logger, asrockrack.WithHTTPClient(&asrHttpClient)) c.Registry.Register(asrockrack.ProviderName, asrockrack.ProviderProtocol, asrockrack.Features, nil, driverAsrockrack) +} - // register gofish provider +// register gofish provider +func (c *Client) registerGofishProvider() { gfHttpClient := *c.httpClient gfHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone() gofishOpts := []redfish.Option{ @@ -184,11 +181,16 @@ func (c *Client) registerProviders() { redfish.WithVersionsNotCompatible(c.providerConfig.gofish.VersionsNotCompatible), redfish.WithUseBasicAuth(c.providerConfig.gofish.UseBasicAuth), redfish.WithPort(c.providerConfig.gofish.Port), + redfish.WithEtagMatchDisabled(c.providerConfig.gofish.DisableEtagMatch), } + driverGoFish := redfish.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, c.Logger, gofishOpts...) c.Registry.Register(redfish.ProviderName, redfish.ProviderProtocol, redfish.Features, nil, driverGoFish) +} + +// register Intel AMT provider +func (c *Client) registerIntelAMTProvider() { - // register Intel AMT provider iamtOpts := []intelamt.Option{ intelamt.WithLogger(c.Logger), intelamt.WithHostScheme(c.providerConfig.intelamt.HostScheme), @@ -196,8 +198,10 @@ func (c *Client) registerProviders() { } driverAMT := intelamt.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, iamtOpts...) c.Registry.Register(intelamt.ProviderName, intelamt.ProviderProtocol, intelamt.Features, nil, driverAMT) +} - // register Dell gofish provider +// register Dell gofish provider +func (c *Client) registerDellProvider() { dellGofishHttpClient := *c.httpClient //dellGofishHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone() dellGofishOpts := []dell.Option{ @@ -208,14 +212,48 @@ func (c *Client) registerProviders() { } driverGoFishDell := dell.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, c.Logger, dellGofishOpts...) c.Registry.Register(dell.ProviderName, redfish.ProviderProtocol, dell.Features, nil, driverGoFishDell) +} - // register supermicro vendorapi provider +// register supermicro vendorapi provider +func (c *Client) registerSupermicroProvider() { smcHttpClient := *c.httpClient smcHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone() - driverSupermicro := supermicro.NewClient(c.Auth.Host, c.Auth.User, c.Auth.Pass, c.Logger, supermicro.WithHttpClient(&smcHttpClient), supermicro.WithPort(c.providerConfig.supermicro.Port)) + driverSupermicro := supermicro.NewClient( + c.Auth.Host, + c.Auth.User, + c.Auth.Pass, + c.Logger, + supermicro.WithHttpClient(&smcHttpClient), + supermicro.WithPort(c.providerConfig.supermicro.Port), + ) + c.Registry.Register(supermicro.ProviderName, supermicro.ProviderProtocol, supermicro.Features, nil, driverSupermicro) } +func (c *Client) registerProviders() { + // register the rpc provider + // without the consumer URL there is no way to send RPC requests. + if c.providerConfig.rpc.ConsumerURL != "" { + // when the rpc provider is to be used, we won't register any other providers. + err := c.registerRPCProvider() + if err == nil { + c.Logger.Info("note: with the rpc provider registered, no other providers will be registered and available") + return + } + c.Logger.Info("failed to register rpc provider, falling back to registering all other providers", "error", err.Error()) + } + + if err := c.registerIPMIProvider(); err != nil { + c.Logger.Info("ipmitool provider not available", "error", err.Error()) + } + + c.registerASRRProvider() + c.registerGofishProvider() + c.registerIntelAMTProvider() + c.registerDellProvider() + c.registerSupermicroProvider() +} + // GetMetadata returns the metadata that is populated after each BMC function/method call func (c *Client) GetMetadata() bmc.Metadata { if c.metadata != nil { diff --git a/option.go b/option.go index f79cab5f..79447e40 100644 --- a/option.go +++ b/option.go @@ -111,6 +111,12 @@ func WithRedfishUseBasicAuth(useBasicAuth bool) Option { } } +func WithRedfishEtagMatchDisabled(d bool) Option { + return func(args *Client) { + args.providerConfig.gofish.DisableEtagMatch = d + } +} + func WithIntelAMTHostScheme(hostScheme string) Option { return func(args *Client) { args.providerConfig.intelamt.HostScheme = hostScheme diff --git a/providers/redfish/redfish.go b/providers/redfish/redfish.go index 22fc4e19..1a982af0 100644 --- a/providers/redfish/redfish.go +++ b/providers/redfish/redfish.go @@ -58,8 +58,8 @@ type Config struct { VersionsNotCompatible []string RootCAs *x509.CertPool UseBasicAuth bool - // WithEtagMatchDisabled disables the If-Match Etag header from being included by the Gofish driver. - disableEtagMatch bool + // DisableEtagMatch disables the If-Match Etag header from being included by the Gofish driver. + DisableEtagMatch bool } // Option for setting optional Client values @@ -100,7 +100,7 @@ func WithUseBasicAuth(useBasicAuth bool) Option { // As of the current implementation this disables the header for POST/PATCH requests to the System entity endpoints. func WithEtagMatchDisabled(d bool) Option { return func(c *Config) { - c.disableEtagMatch = d + c.DisableEtagMatch = d } } @@ -118,7 +118,7 @@ func New(host, user, pass string, log logr.Logger, opts ...Option) *Conn { rfOpts := []redfishwrapper.Option{ redfishwrapper.WithHTTPClient(defaultConfig.HttpClient), redfishwrapper.WithVersionsNotCompatible(defaultConfig.VersionsNotCompatible), - redfishwrapper.WithEtagMatchDisabled(defaultConfig.disableEtagMatch), + redfishwrapper.WithEtagMatchDisabled(defaultConfig.DisableEtagMatch), } if defaultConfig.RootCAs != nil {