Skip to content

Commit

Permalink
Issue #192: HostSystem doesn't seem to be returning the correct host.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Gray committed Jan 4, 2015
1 parent 7fd39a7 commit 8a8e7fc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
25 changes: 24 additions & 1 deletion compute_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,35 @@ limitations under the License.

package govmomi

import "github.com/vmware/govmomi/vim25/types"
import (
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/types"
)

type ComputeResource struct {
types.ManagedObjectReference

c *Client
}

func NewComputeResource(c *Client, ref types.ManagedObjectReference) *ComputeResource {
return &ComputeResource{
ManagedObjectReference: ref,
c: c,
}
}

func (c ComputeResource) Reference() types.ManagedObjectReference {
return c.ManagedObjectReference
}

func (c ComputeResource) Hosts() ([]types.ManagedObjectReference, error) {
var cr mo.ComputeResource
ps := []string{"host"}

err := c.c.Properties(c.Reference(), ps, &cr)
if err != nil {
return nil, err
}
return cr.Host, nil
}
10 changes: 8 additions & 2 deletions find/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,16 @@ func (f *Finder) HostSystemList(path ...string) ([]*govmomi.HostSystem, error) {
var hss []*govmomi.HostSystem
for _, e := range es {
switch o := e.Object.(type) {
case mo.HostSystem:
hs := govmomi.NewHostSystem(f.Client, o.Reference())
case mo.ComputeResource:
cr := govmomi.NewComputeResource(f.Client, o.Reference())
hosts, err := cr.Hosts()
if err != nil {
return nil, err
}
hs := govmomi.NewHostSystem(f.Client, hosts[0])
hss = append(hss, hs)
}

}

return hss, nil
Expand Down
4 changes: 4 additions & 0 deletions govc/test/host.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ load test_helper
assert_success
grep -q Manufacturer: <<<$output

run govc host.info -host ${name##*/}
assert_success
grep -q Manufacturer: <<<$output

run govc host.info -host.ipath $name
assert_success

Expand Down

0 comments on commit 8a8e7fc

Please sign in to comment.