Skip to content

Commit

Permalink
Client opts fixes (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 25, 2023
2 parents fd15a4a + f0cdcfa commit d2aac70
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 27 deletions.
84 changes: 61 additions & 23 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,59 +145,63 @@ 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{
redfish.WithHttpClient(&gfHttpClient),
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),
intelamt.WithPort(c.providerConfig.intelamt.Port),
}
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{
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions providers/redfish/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

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

0 comments on commit d2aac70

Please sign in to comment.