本文整理汇总了Golang中github.com/vmware/govmomi/object.NewComputeResource函数的典型用法代码示例。如果您正苦于以下问题:Golang NewComputeResource函数的具体用法?Golang NewComputeResource怎么用?Golang NewComputeResource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewComputeResource函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ComputeResourceList
func (f *Finder) ComputeResourceList(ctx context.Context, path string) ([]*object.ComputeResource, error) {
es, err := f.find(ctx, f.hostFolder, false, path)
if err != nil {
return nil, err
}
var crs []*object.ComputeResource
for _, e := range es {
var cr *object.ComputeResource
switch o := e.Object.(type) {
case mo.ComputeResource, mo.ClusterComputeResource:
cr = object.NewComputeResource(f.client, o.Reference())
default:
continue
}
cr.InventoryPath = e.Path
crs = append(crs, cr)
}
if len(crs) == 0 {
return nil, &NotFoundError{"compute resource", path}
}
return crs, nil
}
示例2: Remove
func (cmd *remove) Remove(ctx context.Context, host *object.HostSystem) error {
var h mo.HostSystem
err := host.Properties(ctx, host.Reference(), []string{"parent"}, &h)
if err != nil {
return err
}
remove := host.Destroy
if h.Parent.Type == "ComputeResource" {
// Standalone host. From the docs:
// "Invoking remove on a HostSystem of standalone type throws a NotSupported fault.
// A standalone HostSystem can be removeed only by invoking remove on its parent ComputeResource."
remove = object.NewComputeResource(host.Client(), *h.Parent).Destroy
}
task, err := remove(ctx)
if err != nil {
return err
}
logger := cmd.ProgressLogger(fmt.Sprintf("%s removing... ", host.InventoryPath))
defer logger.Wait()
_, err = task.WaitForResult(ctx, logger)
return err
}
示例3: HostSystemList
func (f *Finder) HostSystemList(ctx context.Context, path string) ([]*object.HostSystem, error) {
es, err := f.find(ctx, f.hostFolder, false, path)
if err != nil {
return nil, err
}
var hss []*object.HostSystem
for _, e := range es {
var hs *object.HostSystem
switch o := e.Object.(type) {
case mo.HostSystem:
hs = object.NewHostSystem(f.client, o.Reference())
case mo.ComputeResource:
cr := object.NewComputeResource(f.client, o.Reference())
hosts, err := cr.Hosts(ctx)
if err != nil {
return nil, err
}
hs = object.NewHostSystem(f.client, hosts[0])
default:
continue
}
hs.InventoryPath = e.Path
hss = append(hss, hs)
}
if len(hss) == 0 {
return nil, &NotFoundError{"host", path}
}
return hss, nil
}
示例4: GetCluster
func (rp *ResourcePool) GetCluster(ctx context.Context) (*object.ComputeResource, error) {
var err error
var mrp mo.ResourcePool
if err = rp.Properties(ctx, rp.Reference(), []string{"owner"}, &mrp); err != nil {
log.Errorf("Unable to get cluster of resource pool %s: %s", rp.Name(), err)
return nil, err
}
return object.NewComputeResource(rp.Client.Client, mrp.Owner), nil
}