Skip to content

Commit

Permalink
LED works for redfish and dell
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Nov 21, 2024
1 parent 9fa30f1 commit 3632375
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 17 deletions.
12 changes: 6 additions & 6 deletions cli/led.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ var ledCmd = &cli.Command{
if err != nil {
return err
}
board, err := c.Board()
ledstate, err := c.GetIdentifyLED()
if err != nil {
return err
}
log.Infow("lead", "state", board.IndicatorLED)
log.Infow("led", "state", ledstate.String())
return nil
},
Subcommands: []*cli.Command{
Expand All @@ -36,11 +36,11 @@ var ledCmd = &cli.Command{
return err
}
log.Infow("led state set to on")
board, err := c.Board()
ledstate, err := c.GetIdentifyLED()
if err != nil {
return err
}
log.Infow("lead", "state", board.IndicatorLED)
log.Infow("led", "state", ledstate.String())
return nil
},
},
Expand All @@ -58,11 +58,11 @@ var ledCmd = &cli.Command{
return err
}
log.Infow("led state set to off")
board, err := c.Board()
ledstate, err := c.GetIdentifyLED()
if err != nil {
return err
}
log.Infow("lead", "state", board.IndicatorLED)
log.Infow("led", "state", ledstate.String())
return nil
},
},
Expand Down
2 changes: 1 addition & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func main() {
log.Infow("go hal cli", "host", host, "port", port, "password", password, "bandtype", bandtype)

if err := app.Run(os.Args); err != nil {
panic(err)
log.Errorw("execution failed", "error", err)
}

if outBandBMCConnection != nil {
Expand Down
3 changes: 3 additions & 0 deletions hal.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ type Hal interface {
// PowerCycle cycle the power state of the server
PowerCycle() error

GetIdentifyLED() (IdentifyLEDState, error)
// IdentifyLEDState get the identify LED state
IdentifyLEDState(IdentifyLEDState) error
// IdentifyLEDOn set the identify LED to on
Expand Down Expand Up @@ -144,6 +145,7 @@ type InBand interface {
// PowerCycle cycle the power state of the server
PowerCycle() error

GetIdentifyLED() (IdentifyLEDState, error)
// IdentifyLEDState get the identify LED state
IdentifyLEDState(IdentifyLEDState) error
// IdentifyLEDOn set the identify LED to on
Expand Down Expand Up @@ -194,6 +196,7 @@ type OutBand interface {
// PowerCycle cycle the power state of the server
PowerCycle() error

GetIdentifyLED() (IdentifyLEDState, error)
// IdentifyLEDState get the identify LED state
IdentifyLEDState(IdentifyLEDState) error
// IdentifyLEDOn set the identify LED to on
Expand Down
23 changes: 14 additions & 9 deletions internal/redfish/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"sort"
"strings"
Expand Down Expand Up @@ -412,11 +413,10 @@ func (c *APIClient) IdentifyLEDState(state hal.IdentifyLEDState) error {
case hal.IdentifyLEDStateUnknown:
return fmt.Errorf("unknown LED state:%s", state)
}
resp, err := c.Gofish.Patch("/redfish/v1/Chassis/System.Embedded.1", payload)
_, err := c.Gofish.Patch("/redfish/v1/Chassis/System.Embedded.1", payload)

Check failure on line 416 in internal/redfish/redfish.go

View workflow job for this annotation

GitHub Actions / build

response body must be closed (bodyclose)
if err != nil {
c.log.Errorw("unable to set led", "error", err)
}
c.log.Infow("set led", "response", resp.Body)

return nil
}
Expand All @@ -428,23 +428,28 @@ func (c *APIClient) GetIdentifyLED() (hal.IdentifyLEDState, error) {
c.log.Errorw("unable to get led", "error", err)
return hal.IdentifyLEDStateUnknown, err
}
c.log.Infow("set led", "response", resp.Body)
var ledstate map[string]string
err = json.NewDecoder(resp.Body).Decode(ledstate)
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return hal.IdentifyLEDStateUnknown, err
}

var parsedBody map[string]any
err = json.Unmarshal(body, &parsedBody)
if err != nil {
c.log.Errorw("unable to parse led state", "error", err)
return hal.IdentifyLEDStateUnknown, err
}

state, ok := ledstate["LocationIndicatorActive"]
state, ok := parsedBody["LocationIndicatorActive"]
if !ok {
return hal.IdentifyLEDStateUnknown, fmt.Errorf("ledstate does not contain a LocationIndicatorActive key")
}

switch state {
case "true":
switch state.(bool) {
case true:
return hal.IdentifyLEDStateOn, nil
case "false":
case false:
return hal.IdentifyLEDStateOff, nil
}
return hal.IdentifyLEDStateUnknown, fmt.Errorf("unknown state:%s", state)
Expand Down
4 changes: 4 additions & 0 deletions internal/vendors/dell/dell.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (o *outBand) IPMIConnection() (ip string, port int, user string, password s
panic("unimplemented")
}

func (o *outBand) GetIdentifyLED() (hal.IdentifyLEDState, error) {
return o.Redfish.GetIdentifyLED()
}

// IdentifyLEDOff implements hal.OutBand.
func (o *outBand) IdentifyLEDOff() error {
return o.Redfish.IdentifyLEDState(hal.IdentifyLEDStateOff)
Expand Down
7 changes: 7 additions & 0 deletions internal/vendors/lenovo/lenovo.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func (ib *inBand) PowerCycle() error {
func (ib *inBand) PowerReset() error {
return ib.IpmiTool.SetChassisControl(ipmi.ChassisControlHardReset)
}
func (o *inBand) GetIdentifyLED() (hal.IdentifyLEDState, error) {
return hal.IdentifyLEDStateUnknown, nil
}

func (ib *inBand) IdentifyLEDState(state hal.IdentifyLEDState) error {
return ib.IpmiTool.SetChassisIdentifyLEDState(state)
Expand Down Expand Up @@ -207,6 +210,10 @@ func (ob *outBand) PowerCycle() error {
return ob.Redfish.PowerReset() // PowerCycle is not supported
}

func (o *outBand) GetIdentifyLED() (hal.IdentifyLEDState, error) {
return o.Redfish.GetIdentifyLED()
}

func (ob *outBand) IdentifyLEDState(state hal.IdentifyLEDState) error {
return errorNotImplemented //TODO https://github.com/metal-stack/go-hal/issues/11
}
Expand Down
8 changes: 8 additions & 0 deletions internal/vendors/supermicro/supermicro.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (ib *inBand) PowerReset() error {
return ib.IpmiTool.SetChassisControl(ipmi.ChassisControlHardReset)
}

func (o *inBand) GetIdentifyLED() (hal.IdentifyLEDState, error) {
return hal.IdentifyLEDStateUnknown, nil
}

func (ib *inBand) IdentifyLEDState(state hal.IdentifyLEDState) error {
return ib.IpmiTool.SetChassisIdentifyLEDState(state)
}
Expand Down Expand Up @@ -250,6 +254,10 @@ func (ob *outBand) PowerCycle() error {
})
}

func (o *outBand) GetIdentifyLED() (hal.IdentifyLEDState, error) {
return o.Redfish.GetIdentifyLED()
}

func (ob *outBand) IdentifyLEDState(state hal.IdentifyLEDState) error {
return ob.Goipmi(func(client *ipmi.Client) error {
return client.SetChassisIdentifyLEDState(state)
Expand Down
8 changes: 7 additions & 1 deletion internal/vendors/vagrant/vagrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func (ib *inBand) PowerCycle() error {
func (ib *inBand) PowerReset() error {
return ib.IpmiTool.SetChassisControl(ipmi.ChassisControlHardReset)
}

func (o *inBand) GetIdentifyLED() (hal.IdentifyLEDState, error) {
return hal.IdentifyLEDStateUnknown, nil
}
func (ib *inBand) IdentifyLEDState(state hal.IdentifyLEDState) error {
return nil
}
Expand Down Expand Up @@ -187,6 +189,10 @@ func (ob *outBand) PowerCycle() error {
})
}

func (o *outBand) GetIdentifyLED() (hal.IdentifyLEDState, error) {
return hal.IdentifyLEDStateUnknown, nil
}

func (ob *outBand) IdentifyLEDState(state hal.IdentifyLEDState) error {
return nil
}
Expand Down

0 comments on commit 3632375

Please sign in to comment.