2017-08-23 15:40:57 -04:00
|
|
|
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 15:40:57 -04:00
|
|
|
)
|
|
|
|
|
2017-08-23 20:06:50 -04:00
|
|
|
type Host struct {
|
2020-08-31 04:34:41 -04:00
|
|
|
driver *VCenterDriver
|
2018-10-31 17:42:24 -04:00
|
|
|
host *object.HostSystem
|
2017-08-23 20:06:50 -04:00
|
|
|
}
|
|
|
|
|
2020-08-31 04:34:41 -04:00
|
|
|
func (d *VCenterDriver) NewHost(ref *types.ManagedObjectReference) *Host {
|
2017-08-23 20:06:50 -04:00
|
|
|
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,
|
|
|
|
}
|
2017-08-23 15:40:57 -04:00
|
|
|
}
|
|
|
|
|
2020-08-31 04:34:41 -04:00
|
|
|
func (d *VCenterDriver) FindHost(name string) (*Host, error) {
|
2018-03-15 17:53:25 -04:00
|
|
|
h, err := d.finder.HostSystem(d.ctx, name)
|
2017-08-24 16:18:14 -04:00
|
|
|
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) {
|
2017-08-23 15:40:57 -04:00
|
|
|
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)
|
2017-08-23 15:40:57 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-08-23 20:06:50 -04:00
|
|
|
return &info, nil
|
2017-08-23 15:40:57 -04:00
|
|
|
}
|