Add example for GetBiosConfiguration

This commit is contained in:
Diogo Mendes Matsubara 2023-03-08 16:30:37 +01:00
parent 621d498c73
commit 209e24ab49
Failed to extract signature
2 changed files with 49 additions and 0 deletions

6
examples/bios/doc.go Normal file
View 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
View 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)
}