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

Issue #192: HostSystem doesn't seem to be returning the correct host. #195

Merged
merged 1 commit into from
Jan 5, 2015
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
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])
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