您可以剪切、粘贴和编辑 JavaScript 示例来编写脚本,用于检索 vRealize Automation 置备的资源的实际实体。
CatalogResource 类型表示
vRealize Automation 中已置备的资源。此类型具有
ProviderBinding 类型的属性,代表具有以下属性的目录资源及其提供程序之间的关系:
- bindingId - 表示提供程序独具的实体的标识符
- providerRef - 用于识别与 vRealize Automation 组件注册表中所注册的服务直接对应的目录提供程序
有关 vRealize Orchestrator 中脚本编写的更多信息,请参见《使用 VMware vRealize Orchestrator 进行开发》。
获得置备为 vRealize Automation 目录资源的虚拟机
此示例将 vRealize Automation 主机及其 IaaS 主机用作输入参数,并且针对提供的资源 ID,返回相应的 IaaS 虚拟机。脚本代码仅采用 Virtual Machine 类型的目录资源(由 iaas-service 提供程序置备)。
变量 | 类型 |
---|---|
vcacHost | vCACCAFE:VCACHost |
iaasHost | vCAC:VCACHost |
// Id of the catalog resource (or vCACCAFECatalogResource_instance.getId()) var resourceId = "c222629c-6f90-4458-8c92-8ece0ba06173"; var resource = vCACCAFEEntitiesFinder.getCatalogResource(vcacHost, resourceId); var resourceType = resource.getResourceTypeRef().getLabel(); System.log("resource type: " + resourceType); var providerBinding = resource.getProviderBinding(); var bindingId = providerBinding.getBindingId(); System.log("provider binding id: " + bindingId); var provider = providerBinding.getProviderRef(); System.log("provider id: " + provider.getId()); System.log("provider name: " + provider.getLabel()); if ((resourceType == "Virtual Machine") && (provider.getLabel() == "iaas-service")) { System.log("It is an IaaS VM!"); // IaaS virtual machine var vm = Server.findForType("vCAC:VirtualMachine", bindingId); System.log("IaaS VM id: " + vm.virtualMachineID); System.log("IaaS VM name: " + vm.displayName); // IaaS Entity var entity = System.getModule("com.vmware.library.vcac").getVirtualMachineEntityFromId(iaasHost, bindingId); System.log("IaaS entity id: " + entity.keyString); }