當前位置: 首頁>>代碼示例>>Golang>>正文


Golang VirtualMachine.ResourcePool方法代碼示例

本文整理匯總了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!!")
	}

}
開發者ID:zhaog918,項目名稱:govmax,代碼行數:34,代碼來源:vmomi.go


注:本文中的github.com/vmware/govmomi/object.VirtualMachine.ResourcePool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。