Skip to content

Commit

Permalink
Fix govmomi #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 3, 2015
1 parent d26f470 commit c252b73
Show file tree
Hide file tree
Showing 2 changed files with 32 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

0 comments on commit c252b73

Please sign in to comment.