Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

govc: fix datacenter.info against nested folders #1594

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions govc/datacenter/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"flag"
"fmt"
"io"
"path"
"text/tabwriter"

"github.com/vmware/govmomi/find"
Expand Down Expand Up @@ -154,17 +153,12 @@ func (r *infoResult) Write(w io.Writer) error {
fmt.Fprintf(tw, "Name:\t%s\n", dc.Name)
fmt.Fprintf(tw, " Path:\t%s\n", o.InventoryPath)

folders, err := o.Folders(r.ctx)
if err != nil {
return err
}

r.finder.SetDatacenter(o)

hosts, _ := r.finder.HostSystemList(r.ctx, path.Join(folders.HostFolder.InventoryPath, "*"))
hosts, _ := r.finder.HostSystemList(r.ctx, "*")
fmt.Fprintf(tw, " Hosts:\t%d\n", len(hosts))

clusters, _ := r.finder.ClusterComputeResourceList(r.ctx, path.Join(folders.HostFolder.InventoryPath, "*"))
clusters, _ := r.finder.ClusterComputeResourceList(r.ctx, "*")
fmt.Fprintf(tw, " Clusters:\t%d\n", len(clusters))

manager := view.NewManager(r.client)
Expand Down
17 changes: 17 additions & 0 deletions govc/test/datacenter.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ load test_helper
assert_failure
}

@test "datacenter.info with folders" {
vcsim_start -cluster 3 -folder 1

info=$(govc datacenter.info DC0)

hosts=$(govc find -type h | wc -l)
clusters=$(govc find -type c | wc -l)
vms=$(govc find -type m | wc -l)
datastores=$(govc find -type s | wc -l)


assert_equal "$hosts" "$(grep Hosts: <<<"$info" | awk '{print $2}')"
assert_equal "$clusters" "$(grep Clusters: <<<"$info" | awk '{print $2}')"
assert_equal "$vms" "$(grep "Virtual Machines": <<<"$info" | awk '{print $3}')"
assert_equal "$datastores" "$(grep Datastores: <<<"$info" | awk '{print $2}')"
}

@test "datacenter.create" {
vcsim_env
unset GOVC_DATACENTER
Expand Down