本文整理匯總了Golang中github.com/vmware/govmomi/object.VirtualMachine.ResourcePool方法的典型用法代碼示例。如果您正苦於以下問題:Golang VirtualMachine.ResourcePool方法的具體用法?Golang VirtualMachine.ResourcePool怎麽用?Golang VirtualMachine.ResourcePool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/vmware/govmomi/object.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.ResourcePool方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FindHosts
func (vmh *VMHost) FindHosts(targetVM *object.VirtualMachine) (hosts []*object.HostSystem, err error) {
targetResourcePool, err := targetVM.ResourcePool(vmh.Ctx)
if err != nil {
return nil, errors.New("Error with finding Resource Pool of VM")
}
var resourcePoolProp mo.ResourcePool
err = targetResourcePool.Properties(vmh.Ctx, targetResourcePool.Reference(), []string{"owner"}, &resourcePoolProp)
if err != nil {
return nil, errors.New("Error with finding Owner of Resource Pool")
}
typeOfOwningResource := resourcePoolProp.Owner.Type
//Scenario in which VM is apart of a Cluster (Not tied to 1 ESXi host) - VMware DRS
if typeOfOwningResource == "ClusterComputeResource" {
cluster := object.NewClusterComputeResource(vmh.client.Client, resourcePoolProp.Owner)
var clusterProp mo.ClusterComputeResource
err = cluster.Properties(vmh.Ctx, cluster.Reference(), []string{"host"}, &clusterProp)
if err != nil {
return nil, errors.New("Error with finding Hosts of Cluster")
}
//convert Managed Object References into actual host_sytem objects to return
var hosts []*object.HostSystem
for _, host := range clusterProp.Host {
newHost := object.NewHostSystem(vmh.client.Client, host)
hosts = append(hosts, newHost)
}
return hosts, nil
} else {
return nil, errors.New("Looks like you are on a single/Non-Clustered host and we havent gotten to this yet!!")
}
}