Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client opts fixes #354

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 61 additions & 23 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,59 +145,63 @@
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)

Check warning on line 162 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L162

Added line #L162 was not covered by tests

return nil

Check warning on line 164 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L164

Added line #L164 was not covered by tests
}

// 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 @@
}
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

Check warning on line 241 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L238-L241

Added lines #L238 - L241 were not covered by tests
}
c.Logger.Info("failed to register rpc provider, falling back to registering all other providers", "error", err.Error())

Check warning on line 243 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L243

Added line #L243 was not covered by tests
}

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 WithRedfishEtagMatchDisabled(d bool) Option {
return func(args *Client) {
args.providerConfig.gofish.DisableEtagMatch = d

Check warning on line 116 in option.go

View check run for this annotation

Codecov / codecov/patch

option.go#L114-L116

Added lines #L114 - L116 were not covered by tests
}
}

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 @@
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 @@
// 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

Check warning on line 103 in providers/redfish/redfish.go

View check run for this annotation

Codecov / codecov/patch

providers/redfish/redfish.go#L103

Added line #L103 was not covered by tests
}
}

Expand All @@ -118,7 +118,7 @@
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