Skip to content

Commit

Permalink
Issue vmware#192: HostSystem doesn't seem to be returning the correct…
Browse files Browse the repository at this point in the history
… host.
  • Loading branch information
Gavin Gray committed Jan 4, 2015
1 parent 7fd39a7 commit 1cbe968
Show file tree
Hide file tree
Showing 3 changed files with 42 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
}
16 changes: 14 additions & 2 deletions find/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,23 @@ func (f *Finder) HostSystemList(path ...string) ([]*govmomi.HostSystem, error) {

var hss []*govmomi.HostSystem
for _, e := range es {
var hs *govmomi.HostSystem

switch o := e.Object.(type) {
case mo.HostSystem:
hs := govmomi.NewHostSystem(f.Client, o.Reference())
hss = append(hss, hs)
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])

This comment has been minimized.

Copy link
@dougm

Jan 5, 2015

Should we add all hosts here, instead of just the first?

This comment has been minimized.

Copy link
@bitwisekaizen

bitwisekaizen Jan 5, 2015

Owner

There won't actually ever be another host at the moment. We would want to if we were dealing with a ClusterComputeResource, then we'd want to iterate over all of the hosts in the array. On that note, there's a separate bug that doesn't allow us to find a HostSystem in a cluster by name. Will file that one, but I have no need to fix it right away. I will need it shortly though.

default:
continue
}

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 1cbe968

Please sign in to comment.