From 85e9625108b5154eceb8d069830de060c809b84a Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Thu, 21 Nov 2024 14:36:53 +0100 Subject: [PATCH] Allow raw redfish get commands for debugging --- cli/main.go | 121 ++++++------------------------------------------- cli/redfish.go | 42 +++++++++++++++++ 2 files changed, 55 insertions(+), 108 deletions(-) create mode 100644 cli/redfish.go diff --git a/cli/main.go b/cli/main.go index e0b51ae..4ce853b 100644 --- a/cli/main.go +++ b/cli/main.go @@ -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", @@ -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, @@ -71,6 +78,7 @@ func main() { boardCmd, ledCmd, powerCmd, + redfishCmd, }, Flags: flags, } @@ -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") -// } -// } diff --git a/cli/redfish.go b/cli/redfish.go new file mode 100644 index 0000000..8361f10 --- /dev/null +++ b/cli/redfish.go @@ -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 + }, +}