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

Allow specifying the Redfish system name: #400

Merged
merged 2 commits into from
Oct 22, 2024
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
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func (c *Client) registerGofishProvider() {
redfish.WithUseBasicAuth(c.providerConfig.gofish.UseBasicAuth),
redfish.WithPort(c.providerConfig.gofish.Port),
redfish.WithEtagMatchDisabled(c.providerConfig.gofish.DisableEtagMatch),
redfish.WithSystemName(c.providerConfig.gofish.SystemName),
}

driverGoFish := redfish.New(c.Auth.Host, c.Auth.User, c.Auth.Pass, c.Logger, gofishOpts...)
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
7 changes: 7 additions & 0 deletions internal/redfishwrapper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Client struct {
port string
user string
pass string
systemName string
basicAuth bool
disableEtagMatch bool
versionsNotCompatible []string // a slice of redfish versions to ignore as incompatible
Expand Down Expand Up @@ -90,6 +91,12 @@ func WithLogger(l *logr.Logger) Option {
}
}

func WithSystemName(name string) Option {
return func(c *Client) {
c.systemName = name
}
}

// NewClient returns a redfishwrapper client
func NewClient(host, port, user, pass string, opts ...Option) *Client {
if !strings.HasPrefix(host, "https://") && !strings.HasPrefix(host, "http://") {
Expand Down
17 changes: 16 additions & 1 deletion internal/redfishwrapper/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ func (c *Client) Systems() ([]*redfish.ComputerSystem, error) {
return nil, err
}

return c.client.Service.Systems()
s, err := c.client.Service.Systems()
if err != nil {
return nil, err
}

return c.matchingSystem(s), nil
Copy link
Member

@joelrebel joelrebel Oct 22, 2024

Choose a reason for hiding this comment

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

edit: ignore this comment - I now see the method defaults to returning all Systems.

We'd want to keep the default behavior here - to return all Systems - when c.systemName was not specified

Suggested change
return c.matchingSystem(s), nil
if c.systemName != "" {
return c.matchingSystem(s), nil
}
return s, nil

}

// Managers gets the manager instances of this service.
Expand All @@ -55,3 +60,13 @@ func (c *Client) Chassis(ctx context.Context) ([]*redfish.Chassis, error) {

return c.client.Service.Chassis()
}

func (c *Client) matchingSystem(systems []*redfish.ComputerSystem) []*redfish.ComputerSystem {
for _, s := range systems {
if s.Name == c.systemName {
return []*redfish.ComputerSystem{s}
}
}

return systems
}
2 changes: 1 addition & 1 deletion lint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LINTERS :=
FIXERS :=

GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
GOLANGCI_LINT_VERSION ?= v1.53.3
GOLANGCI_LINT_VERSION ?= v1.61.0
GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
$(GOLANGCI_LINT_BIN):
mkdir -p $(LINT_ROOT)/out/linters
Expand Down
6 changes: 6 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func WithRedfishEtagMatchDisabled(d bool) Option {
}
}

func WithRedfishSystemName(name string) Option {
return func(args *Client) {
args.providerConfig.gofish.SystemName = name
}
}

func WithIntelAMTHostScheme(hostScheme string) Option {
return func(args *Client) {
args.providerConfig.intelamt.HostScheme = hostScheme
Expand Down
9 changes: 9 additions & 0 deletions providers/redfish/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Config struct {
UseBasicAuth bool
// DisableEtagMatch disables the If-Match Etag header from being included by the Gofish driver.
DisableEtagMatch bool
SystemName string
}

// Option for setting optional Client values
Expand Down Expand Up @@ -96,6 +97,12 @@ func WithUseBasicAuth(useBasicAuth bool) Option {
}
}

func WithSystemName(name string) Option {
return func(c *Config) {
c.SystemName = name
}
}

// WithEtagMatchDisabled disables the If-Match Etag header from being included by the Gofish driver.
//
// As of the current implementation this disables the header for POST/PATCH requests to the System entity endpoints.
Expand All @@ -120,6 +127,8 @@ func New(host, user, pass string, log logr.Logger, opts ...Option) *Conn {
redfishwrapper.WithHTTPClient(defaultConfig.HttpClient),
redfishwrapper.WithVersionsNotCompatible(defaultConfig.VersionsNotCompatible),
redfishwrapper.WithEtagMatchDisabled(defaultConfig.DisableEtagMatch),
redfishwrapper.WithBasicAuthEnabled(defaultConfig.UseBasicAuth),
Copy link
Member

Choose a reason for hiding this comment

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

thanks for fixing this

redfishwrapper.WithSystemName(defaultConfig.SystemName),
}

if defaultConfig.RootCAs != nil {
Expand Down
Loading