packer-cn/builder/vsphere/driver/host.go

46 lines
857 B
Go
Raw Normal View History

package driver
import (
"github.com/vmware/govmomi/object"
2017-08-23 20:06:50 -04:00
"github.com/vmware/govmomi/vim25/mo"
2018-10-31 17:42:24 -04:00
"github.com/vmware/govmomi/vim25/types"
)
2017-08-23 20:06:50 -04:00
type Host struct {
driver *Driver
2018-10-31 17:42:24 -04:00
host *object.HostSystem
2017-08-23 20:06:50 -04:00
}
func (d *Driver) NewHost(ref *types.ManagedObjectReference) *Host {
return &Host{
2018-10-31 17:42:24 -04:00
host: object.NewHostSystem(d.client.Client, *ref),
2017-08-23 20:06:50 -04:00
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
}
2018-10-31 17:42:24 -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
}