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 2 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
109 changes: 86 additions & 23 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,50 +145,56 @@
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() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this func will never return an error. i would suggest not having any return value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was mainly keeping the pattern from the above function since I was looking into if these could be turned into an interface method which providers implement to register themselves so this can be moved into each provider.

I can remove the extra error returns for now.

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
return nil
}

// register gofish provider
func (c *Client) registerGofishProvider() error {
joelrebel marked this conversation as resolved.
Show resolved Hide resolved
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
return nil
}

// register Intel AMT provider
func (c *Client) registerIntelAMTProvider() error {
joelrebel marked this conversation as resolved.
Show resolved Hide resolved

iamtOpts := []intelamt.Option{
intelamt.WithLogger(c.Logger),
intelamt.WithHostScheme(c.providerConfig.intelamt.HostScheme),
Expand All @@ -197,7 +203,11 @@
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
return nil
}

// register Dell gofish provider
func (c *Client) registerDellProvider() error {
joelrebel marked this conversation as resolved.
Show resolved Hide resolved
dellGofishHttpClient := *c.httpClient
//dellGofishHttpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone()
dellGofishOpts := []dell.Option{
Expand All @@ -209,11 +219,64 @@
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
return nil
}

// register supermicro vendorapi provider
func (c *Client) registerSupermicroProvider() error {
joelrebel marked this conversation as resolved.
Show resolved Hide resolved
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)

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

Check warning on line 251 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L248-L251

Added lines #L248 - L251 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 253 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L253

Added line #L253 was not covered by tests
}

if err := c.registerIPMIProvider(); err != nil {
c.Logger.Info("ipmitool provider not available", "error", err.Error())
}

if err := c.registerASRRProvider(); err != nil {
c.Logger.Info("ASRR provider not available", "error", err.Error())

Check warning on line 261 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L261

Added line #L261 was not covered by tests
}

if err := c.registerGofishProvider(); err != nil {
c.Logger.Info("Gofish provider not available", "error", err.Error())

Check warning on line 265 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L265

Added line #L265 was not covered by tests
}

if err := c.registerIntelAMTProvider(); err != nil {
c.Logger.Info("Intel AMT provider not available", "error", err.Error())

Check warning on line 269 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L269

Added line #L269 was not covered by tests
}

if err := c.registerDellProvider(); err != nil {
c.Logger.Info("Dell provider not available", "error", err.Error())

Check warning on line 273 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L273

Added line #L273 was not covered by tests
}

if err := c.registerSupermicroProvider(); err != nil {
c.Logger.Info("Supermicro provider not available", "error", err.Error())

Check warning on line 277 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L277

Added line #L277 was not covered by tests
}

}

// GetMetadata returns the metadata that is populated after each BMC function/method call
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