packer-cn/driver/host.go

46 lines
852 B
Go
Raw Normal View History

package driver
import (
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25/types"
2017-08-23 20:06:50 -04:00
"github.com/vmware/govmomi/vim25/mo"
)
2017-08-23 20:06:50 -04:00
type Host struct {
driver *Driver
host *object.HostSystem
}
func (d *Driver) NewHost(ref *types.ManagedObjectReference) *Host {
return &Host{
host: object.NewHostSystem(d.client.Client, *ref),
driver: d,
}
}
func (d *Driver) FindHost(name string) (*Host, error) {
2018-03-15 17:53:25 -04:00
h, err := d.finder.HostSystem(d.ctx, name)
if err != nil {
return nil, err
}
return &Host{
host: h,
driver: d,
}, nil
}
2017-08-23 20:06:50 -04:00
func (h *Host) Info(params ...string) (*mo.HostSystem, error){
var p []string
if len(params) == 0 {
p = []string{"*"}
} else {
p = params
}
2017-08-23 20:06:50 -04:00
var info mo.HostSystem
err := h.host.Properties(h.driver.ctx, h.host.Reference(), p, &info)
if err != nil {
return nil, err
}
2017-08-23 20:06:50 -04:00
return &info, nil
}