-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update virtual media mounting: (#398)
- Loading branch information
Showing
3 changed files
with
100 additions
and
36 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
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 |
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,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()) | ||
} |
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