Skip to content

Commit

Permalink
govc: add library.info -S flag
Browse files Browse the repository at this point in the history
Outputs item storage URIs, with ResolveLibraryItemStorage() applied.
Useful for sanity testing ResolveLibraryItemStorage() against any vSphere topology.
  • Loading branch information
dougm committed Aug 1, 2024
1 parent 49b88eb commit cc02310
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions govc/library/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type info struct {
link bool
url bool
stor bool
Stor bool

pathFinder *finder.PathFinder
}
Expand All @@ -62,6 +63,9 @@ func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
f.BoolVar(&cmd.link, "L", false, "List Datastore path only")
f.BoolVar(&cmd.url, "U", false, "List pub/sub URL(s) only")
f.BoolVar(&cmd.stor, "s", false, "Include file specific storage details")
if cli.ShowUnreleased() {
f.BoolVar(&cmd.Stor, "S", false, "Include file specific storage details (resolved)")
}
}

func (cmd *info) Process(ctx context.Context) error {
Expand Down Expand Up @@ -265,14 +269,22 @@ func (r infoResultsWriter) writeFile(
}
fmt.Fprintf(w, " Datastore Path:\t%s\n", p)
}
if r.cmd.stor {
if r.cmd.stor || r.cmd.Stor {
label := "Storage URI"
s, err := r.m.GetLibraryItemStorage(r.ctx, res.GetParent().GetID(), v.Name)
if err != nil {
return err
}
if r.cmd.Stor {
label = "Resolved URI"
err = r.cmd.pathFinder.ResolveLibraryItemStorage(r.ctx, s)
if err != nil {
return err
}
}
for i := range s {
for _, uri := range s[i].StorageURIs {
fmt.Fprintf(w, " Storage URI:\t%s\n", uri)
fmt.Fprintf(w, " %s:\t%s\n", label, uri)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions govc/test/library.bats
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ load test_helper
run govc library.info -s "/my-content/ttylinux-live/$TTYLINUX_NAME.ovf"
assert_success

run env GOVC_SHOW_UNRELEASED=true govc library.info -S "/my-content/ttylinux-live/$TTYLINUX_NAME.ovf"
assert_success

run govc library.info -l -s /my-content/$TTYLINUX_NAME/$TTYLINUX_NAME.ovf
assert_success

Expand Down

0 comments on commit cc02310

Please sign in to comment.