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

Update redfish system name matching #401

Merged
merged 2 commits into from
Oct 28, 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
4 changes: 2 additions & 2 deletions internal/redfishwrapper/boot_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *Client) SystemBootDeviceSet(_ context.Context, bootDevice string, setPe
return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

systems, err := c.client.Service.Systems()
systems, err := c.Systems()
if err != nil {
return false, err
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func (c *Client) GetBootDeviceOverride(_ context.Context) (override bmc.BootDevi
return override, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

systems, err := c.client.Service.Systems()
systems, err := c.Systems()
if err != nil {
return override, err
}
Expand Down
22 changes: 8 additions & 14 deletions internal/redfishwrapper/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (c *Client) BMCReset(ctx context.Context, resetType string) (ok bool, err e
return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

managers, err := c.client.Service.Managers()
managers, err := c.Managers(ctx)
if err != nil {
return false, err
}
Expand All @@ -57,8 +57,7 @@ func (c *Client) SystemPowerOn(ctx context.Context) (ok bool, err error) {
return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

service := c.client.Service
ss, err := service.Systems()
ss, err := c.Systems()
if err != nil {
return false, err
}
Expand All @@ -84,8 +83,7 @@ func (c *Client) SystemPowerOff(ctx context.Context) (ok bool, err error) {
return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

service := c.client.Service
ss, err := service.Systems()
ss, err := c.Systems()
if err != nil {
return false, err
}
Expand All @@ -112,8 +110,7 @@ func (c *Client) SystemReset(ctx context.Context) (ok bool, err error) {
return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

service := c.client.Service
ss, err := service.Systems()
ss, err := c.Systems()
if err != nil {
return false, err
}
Expand Down Expand Up @@ -147,8 +144,7 @@ func (c *Client) SystemPowerCycle(ctx context.Context) (ok bool, err error) {
return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

service := c.client.Service
ss, err := service.Systems()
ss, err := c.Systems()
if err != nil {
return false, err
}
Expand Down Expand Up @@ -180,8 +176,7 @@ func (c *Client) SystemPowerStatus(ctx context.Context) (result string, err erro
return result, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

service := c.client.Service
ss, err := service.Systems()
ss, err := c.Systems()
if err != nil {
return "", err
}
Expand All @@ -199,8 +194,7 @@ func (c *Client) SystemForceOff(ctx context.Context) (ok bool, err error) {
return false, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

service := c.client.Service
ss, err := service.Systems()
ss, err := c.Systems()
if err != nil {
return false, err
}
Expand All @@ -227,7 +221,7 @@ func (c *Client) SendNMI(_ context.Context) error {
return errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

ss, err := c.client.Service.Systems()
ss, err := c.Systems()
if err != nil {
return err
}
Expand Down
19 changes: 18 additions & 1 deletion internal/redfishwrapper/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,24 @@ func (c *Client) Managers(ctx context.Context) ([]*redfish.Manager, error) {
return nil, errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error())
}

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

for _, m := range ms {
sys, err := m.ManagerForServers()
if err != nil {
continue
}
for _, s := range sys {
if s.Name == c.systemName {
return []*redfish.Manager{m}, nil
}
}
}

return ms, nil
}

// Chassis gets the chassis instances managed by this service.
Expand Down
8 changes: 8 additions & 0 deletions internal/redfishwrapper/virtual_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@ func (c *Client) SetVirtualMedia(ctx context.Context, kind string, mediaURL stri
}

for _, vm := range virtualMedia {
var ejected bool
if vm.Inserted {
if err := vm.EjectMedia(); err != nil {
return false, err
}
ejected = true
}
if mediaURL == "" {
// Only ejecting the media was requested.
// For BMC's that don't support the "inserted" property, we need to eject the media if it's not already ejected.
if !ejected {
if err := vm.EjectMedia(); err != nil {
return false, err
}
}
return true, nil
}
if !slices.Contains(vm.MediaTypes, mediaKind) {
Expand Down
Loading