mirror of
https://github.com/bmc-toolbox/bmclib.git
synced 2025-06-03 05:14:43 +00:00
Add example for GetBiosConfiguration
This commit is contained in:
parent
621d498c73
commit
209e24ab49
6
examples/bios/doc.go
Normal file
6
examples/bios/doc.go
Normal file
@ -0,0 +1,6 @@
|
||||
/*
|
||||
bios is an example commmand that retrieves BIOS configuration information and prints it out
|
||||
|
||||
$ BMC_HOST=1.2.3.4 BMC_USERNAME=foo BMC_PASSWORD=bar go run ./examples/bios/main.go
|
||||
*/
|
||||
package main
|
43
examples/bios/main.go
Normal file
43
examples/bios/main.go
Normal file
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
bmclib "github.com/bmc-toolbox/bmclib/v2"
|
||||
logrusr "github.com/bombsimon/logrusr/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// setup logger
|
||||
l := logrus.New()
|
||||
l.Level = logrus.TraceLevel
|
||||
logger := logrusr.New(l)
|
||||
|
||||
clientOpts := []bmclib.Option{bmclib.WithLogger(logger)}
|
||||
|
||||
host := os.Getenv("BMC_HOST")
|
||||
bmcPass := os.Getenv("BMC_PASSWORD")
|
||||
bmcUser := os.Getenv("BMC_USERNAME")
|
||||
// init client
|
||||
client := bmclib.NewClient(host, "", bmcUser, bmcPass, clientOpts...)
|
||||
|
||||
ctx := context.TODO()
|
||||
// open BMC session
|
||||
err := client.Open(ctx)
|
||||
if err != nil {
|
||||
l.Fatal(err, "bmc login failed")
|
||||
}
|
||||
|
||||
defer client.Close(ctx)
|
||||
|
||||
// retrieve bios configuration
|
||||
biosConfig, err := client.GetBiosConfiguration(ctx)
|
||||
if err != nil {
|
||||
l.Error(err)
|
||||
}
|
||||
|
||||
fmt.Println(biosConfig)
|
||||
}
|
Loading…
Reference in New Issue
Block a user