Skip to content

Commit

Permalink
Allow raw redfish get commands for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Nov 21, 2024
1 parent 6ccaaf3 commit 85e9625
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 108 deletions.
121 changes: 13 additions & 108 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (
var (
log logger.Logger

bandtype string
user string
password string
host string
port int
bandtype string
user string
password string
host string
port int
redfishPath string

bandtypeFlag = &cli.StringFlag{
Name: "bandtype",
Expand Down Expand Up @@ -51,6 +52,12 @@ var (
Usage: "bmc port",
Destination: &port,
}
redfishPathFlag = &cli.StringFlag{
Name: "redfish-path",
Value: "",
Usage: "redfish raw path",
Destination: &redfishPath,
}
flags = []cli.Flag{
bandtypeFlag,
hostFlag,
Expand All @@ -71,6 +78,7 @@ func main() {
boardCmd,
ledCmd,
powerCmd,
redfishCmd,
},
Flags: flags,
}
Expand Down Expand Up @@ -107,106 +115,3 @@ func getHalConnection(log logger.Logger) (hal.Hal, error) {
return nil, fmt.Errorf("unknown bandtype %s", bandtype)
}
}

// func outband(log logger.Logger) {
// ob, err := connect.OutBand(*host, *port, *user, *password, log)
// if err != nil {
// panic(err)
// }

// uu := make(map[string]string)
// ee := make(map[string]error)

// b := ob.Board()
// fmt.Printf("Board:\n%#v\n", b)
// fmt.Printf("Power:\n%#v\n", b.PowerMetric)
// fmt.Printf("PowerSupplies:\n%#v\n", b.PowerSupplies)

// bmc, err := ob.BMCConnection().BMC()
// if err != nil {
// ee["BMCConnection.BMC"] = err
// }
// fmt.Printf("BMC:\n%#v\n", bmc)

// _, err = ob.UUID()
// if err != nil {
// ee["UUID"] = err
// }

// ps, err := ob.PowerState()
// if err != nil {
// ee["PowerState"] = err
// }
// if ps == hal.PowerUnknownState {
// uu["PowerState"] = "unexpected power state: PowerUnknownState"
// }
// err = ob.PowerOff()
// if err != nil {
// fmt.Printf("error during power off: %v\n", err)
// }

// board := ob.Board()
// fmt.Println("LED: " + board.IndicatorLED)

// err = ob.PowerCycle()
// if err != nil {
// ee["PowerCycle"] = err
// }

// board = ob.Board()
// fmt.Println("LED: " + board.IndicatorLED)

// if false {
// err = ob.PowerOff()
// if err != nil {
// fmt.Printf("error during power off: %v\n", err)
// }

// time.Sleep(10 * time.Second)

// err = ob.PowerOn()
// if err != nil {
// fmt.Printf("error during power on: %v\n", err)
// }

// // ipmitool sel
// err = ob.IdentifyLEDState(hal.IdentifyLEDStateOff)
// if err != nil {
// ee["IdentifyLEDState"] = err
// }
// err = ob.IdentifyLEDOn()
// if err != nil {
// ee["IdentifyLEDOn"] = err
// }
// err = ob.IdentifyLEDOff()
// if err != nil {
// ee["IdentifyLEDOff"] = err
// }

// //_, err = ob.UpdateBIOS()
// //if err != nil {
// // ee["UpdateBIOS"] = err
// //}
// //
// //_, err = ob.UpdateBMC()
// //if err != nil {
// // ee["UpdateBMC"] = err
// //}
// }

// if len(uu) > 0 {
// fmt.Println("Unexpected things:")
// for m, u := range uu {
// fmt.Printf("%s: %s\n", m, u)
// }
// }

// if len(ee) > 0 {
// fmt.Println("Failed checks:")
// for m, err := range ee {
// fmt.Printf("%s: %s\n", m, err.Error())
// }
// } else {
// fmt.Println("Check succeeded")
// }
// }
42 changes: 42 additions & 0 deletions cli/redfish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"fmt"
"io"

"github.com/stmcginnis/gofish"
"github.com/urfave/cli/v2"
)

var redfishCmd = &cli.Command{
Name: "redfish",
Usage: "raw redfish usage",
Description: "for example use --redfish-path /redfish/v1/Chassis/System.Embedded.1",
Flags: append(flags, redfishPathFlag),
Action: func(ctx *cli.Context) error {

config := gofish.ClientConfig{
Endpoint: "https://" + host,
Username: user,
Password: password,
Insecure: true,
}
c, err := gofish.Connect(config)
if err != nil {
return err
}

resp, err := c.Get(redfishPath)
if err != nil {
return err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}

fmt.Println(string(body))
return nil
},
}

0 comments on commit 85e9625

Please sign in to comment.