Skip to content

Commit

Permalink
Allow specifying the Redfish system name:
Browse files Browse the repository at this point in the history
For Redfish implementations that manage multiple
systems bening able to specify the system name
is required. This is the case with sushy-tools,
which is a redfish emulator for libvirt and others.

Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
  • Loading branch information
jacobweinstock committed Oct 21, 2024
1 parent 8c2a500 commit b3e4d1a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
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
}

// 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
}
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),
redfishwrapper.WithSystemName(defaultConfig.SystemName),
}

if defaultConfig.RootCAs != nil {
Expand Down

0 comments on commit b3e4d1a

Please sign in to comment.