本文整理匯總了Golang中github.com/vmware/govmomi/object.ComputeResource類的典型用法代碼示例。如果您正苦於以下問題:Golang ComputeResource類的具體用法?Golang ComputeResource怎麽用?Golang ComputeResource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ComputeResource類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: LocalDatastores
func (h *Helper) LocalDatastores(ctx context.Context, cr *object.ComputeResource) ([]*object.Datastore, error) {
// List datastores for compute resource
dss, err := cr.Datastores(ctx)
if err != nil {
return nil, err
}
// Filter local datastores
var ldss []*object.Datastore
for _, ds := range dss {
var mds mo.Datastore
err = property.DefaultCollector(h.c).RetrieveOne(ctx, ds.Reference(), nil, &mds)
if err != nil {
return nil, err
}
switch i := mds.Info.(type) {
case *types.VmfsDatastoreInfo:
if i.Vmfs.Local != nil && *i.Vmfs.Local == true {
break
}
default:
continue
}
ds.InventoryPath = mds.Name
ldss = append(ldss, ds)
}
return ldss, nil
}