Skip to content

Commit

Permalink
Add example for virtual media:
Browse files Browse the repository at this point in the history
This helps users see how to use the virtual
media mounting capabilities.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Oct 8, 2024
1 parent aa8f53a commit 8c2a500
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/virtualmedia/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Virtual Media is an example command to mount and umount virtual media (ISO) on a BMC.
# mount an ISO
$ go run examples/virtualmedia/main.go \
-host 10.1.2.3 \
-user root \
-password calvin \
-iso http://example.com/image.iso
# unmount an ISO
$ go run examples/virtualmedia/main.go \
-host 10.1.2.3 \
-user root \
-password calvin \
-iso ""
*/
package main
51 changes: 51 additions & 0 deletions examples/virtualmedia/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"context"
"flag"
"fmt"
"log/slog"
"os"
"time"

"github.com/bmc-toolbox/bmclib/v2"
"github.com/go-logr/logr"
)

func main() {

ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()

user := flag.String("user", "", "BMC username, required")
pass := flag.String("password", "", "BMC password, required")
host := flag.String("host", "", "BMC hostname or IP address, required")
isoURL := flag.String("iso", "", "The HTTP URL to the ISO to be mounted, leave empty to unmount")
flag.Parse()

if *user == "" || *pass == "" || *host == "" {
fmt.Fprintln(os.Stderr, "user, password, and host are required")
flag.PrintDefaults()
os.Exit(1)
}

l := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{AddSource: true}))
log := logr.FromSlogHandler(l.Handler())

cl := bmclib.NewClient(*host, *user, *pass, bmclib.WithLogger(log))
if err := cl.Open(ctx); err != nil {
panic(err)
}
defer cl.Close(ctx)

ok, err := cl.SetVirtualMedia(ctx, "CD", *isoURL)
if err != nil {
log.Info("debugging", "metadata", cl.GetMetadata())
panic(err)
}
if !ok {
log.Info("debugging", "metadata", cl.GetMetadata())
panic("failed virtual media operation")
}
log.Info("virtual media operation successful", "metadata", cl.GetMetadata())
}

0 comments on commit 8c2a500

Please sign in to comment.