-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
489 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var boardCmd = &cli.Command{ | ||
Name: "board", | ||
Usage: "gather machine board details", | ||
Flags: flags, | ||
Action: func(ctx *cli.Context) error { | ||
c, err := getHalConnection(log) | ||
if err != nil { | ||
return err | ||
} | ||
board := c.Board() | ||
log.Infow("board", "bandtype", bandtype, "host", host, "result", board.String(), "bios", board.BIOS, "powermetric", board.PowerMetric, "powersupplies", board.PowerSupplies, "ledstate", board.IndicatorLED) | ||
bmc, err := outBandBMCConnection.BMC() | ||
if err != nil { | ||
return err | ||
} | ||
log.Infow("bmc", "result", bmc) | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var ledCmd = &cli.Command{ | ||
Name: "led", | ||
Usage: "gather machine led state", | ||
Flags: flags, | ||
Action: func(ctx *cli.Context) error { | ||
// c, err := getHalConnection(log) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// ledstate := c.IdentifyLEDState() | ||
// log.Infow("board", "bandtype", bandtype, "host", host, "result", board.String(), "bios", board.BIOS, "powermetric", board.PowerMetric, "powersupplies", board.PowerSupplies) | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,154 +1,209 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/metal-stack/go-hal" | ||
|
||
"github.com/metal-stack/go-hal/connect" | ||
"github.com/metal-stack/go-hal/pkg/api" | ||
"github.com/metal-stack/go-hal/pkg/logger" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var ( | ||
band = flag.String("bandtype", "outband", "inband/outband") | ||
user = flag.String("user", "ADMIN", "bmc username") | ||
password = flag.String("password", "ADMIN", "bmc password") | ||
host = flag.String("host", "localhost", "bmc host") | ||
port = flag.Int("port", 623, "bmc port") | ||
|
||
errHelp = errors.New("usage: -bandtype inband|outband") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
log := logger.New() | ||
switch *band { | ||
case "inband": | ||
inband(log) | ||
case "outband": | ||
outband(log) | ||
default: | ||
fmt.Printf("%s\n", errHelp) | ||
os.Exit(1) | ||
log logger.Logger | ||
|
||
bandtype string | ||
user string | ||
password string | ||
host string | ||
port int | ||
|
||
bandtypeFlag = &cli.StringFlag{ | ||
Name: "bandtype", | ||
Value: "outband", | ||
Usage: "inband/outband", | ||
Destination: &bandtype, | ||
} | ||
} | ||
|
||
func inband(log logger.Logger) { | ||
ib, err := connect.InBand(log) | ||
if err != nil { | ||
panic(err) | ||
userFlag = &cli.StringFlag{ | ||
Name: "user", | ||
Value: "ADMIN", | ||
Usage: "bmc user", | ||
Destination: &user, | ||
} | ||
uuid, err := ib.UUID() | ||
if err != nil { | ||
panic(err) | ||
passwordFlag = &cli.StringFlag{ | ||
Name: "password", | ||
Value: "", | ||
Usage: "bmc password", | ||
Destination: &password, | ||
} | ||
fmt.Printf("UUID:%s\n", uuid) | ||
} | ||
|
||
func outband(log logger.Logger) { | ||
ob, err := connect.OutBand(*host, *port, *user, *password, log) | ||
if err != nil { | ||
panic(err) | ||
hostFlag = &cli.StringFlag{ | ||
Name: "host", | ||
Value: "localhost", | ||
Usage: "bmc host", | ||
Destination: &host, | ||
} | ||
|
||
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 | ||
portFlag = &cli.IntFlag{ | ||
Name: "port", | ||
Value: 623, | ||
Usage: "bmc port", | ||
Destination: &port, | ||
} | ||
fmt.Printf("BMC:\n%#v\n", bmc) | ||
|
||
_, err = ob.UUID() | ||
if err != nil { | ||
ee["UUID"] = err | ||
flags = []cli.Flag{ | ||
bandtypeFlag, | ||
hostFlag, | ||
portFlag, | ||
userFlag, | ||
passwordFlag, | ||
} | ||
outBandBMCConnection api.OutBandBMCConnection | ||
) | ||
|
||
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) | ||
func main() { | ||
log = logger.New() | ||
|
||
app := &cli.App{ | ||
Name: "hal", | ||
Usage: "try bmc commands", | ||
Commands: []*cli.Command{ | ||
uuidCmd, | ||
boardCmd, | ||
ledCmd, | ||
powerCmd, | ||
}, | ||
} | ||
|
||
board := ob.Board() | ||
fmt.Println("LED: " + board.IndicatorLED) | ||
|
||
err = ob.PowerCycle() | ||
if err != nil { | ||
ee["PowerCycle"] = err | ||
if err := app.Run(os.Args); err != nil { | ||
panic(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) | ||
if outBandBMCConnection != nil { | ||
outBandBMCConnection.Close() | ||
} | ||
|
||
err = ob.PowerOn() | ||
if err != nil { | ||
fmt.Printf("error during power on: %v\n", err) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
// ipmitool sel | ||
err = ob.IdentifyLEDState(hal.IdentifyLEDStateOff) | ||
if err != nil { | ||
ee["IdentifyLEDState"] = err | ||
} | ||
err = ob.IdentifyLEDOn() | ||
func getHalConnection(log logger.Logger) (hal.Hal, error) { | ||
switch bandtype { | ||
case "inband": | ||
ib, err := connect.InBand(log) | ||
if err != nil { | ||
ee["IdentifyLEDOn"] = err | ||
return nil, err | ||
} | ||
err = ob.IdentifyLEDOff() | ||
return ib, nil | ||
case "outband": | ||
ob, err := connect.OutBand(host, port, user, password, log) | ||
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) | ||
return nil, err | ||
} | ||
} | ||
|
||
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") | ||
outBandBMCConnection = ob.BMCConnection() | ||
return ob, nil | ||
default: | ||
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") | ||
// } | ||
// } |
Oops, something went wrong.