To use this function add it to the class library file named vCenterVAPIService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: vCenterVAPIService.ts
Function ContentLibraryItemDeployOVF
publicContentLibraryItemDeployOVF(strTemplateName:string,strVcVirtualMachineName:string,objVcVmFolder:VcVmFolder,objVcDatastore:VcDatastore,objVcHostSystem:VcHostSystem,objVcResourcePool:VcResourcePool,strAnnotation:string):VcVirtualMachine{
letstrVAPIContentLibraryModelId:string=this.ContentLibraryItemGetIDByName(strTemplateName);
letobjVMwareVCenterOVFLibraryItemDeploymentTarget:com_vmware_vcenter_ovf_library__item_deployment__target=newcom_vmware_vcenter_ovf_library__item_deployment__target();
objVMwareVCenterOVFLibraryItemDeploymentTarget.folder_id=objVcVmFolder.id;
objVMwareVCenterOVFLibraryItemDeploymentTarget.host_id=objVcHostSystem.id;
objVMwareVCenterOVFLibraryItemDeploymentTarget.resource_pool_id=objVcResourcePool.id;
letobjVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec:com_vmware_vcenter_ovf_library__item_resource__pool__deployment__spec=newcom_vmware_vcenter_ovf_library__item_resource__pool__deployment__spec();
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.name=strVcVirtualMachineName;
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.accept_all_EULA=true;
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.annotation=strAnnotation;
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.default_datastore_id=objVcDatastore.id;
letobjVMwareVCenterOvfLibraryItem:com_vmware_vcenter_ovf_library__item=newcom_vmware_vcenter_ovf_library__item(this.objVAPIClient);
letobjVMwareVCenterOvfLibraryItemDeploymentResult:com_vmware_vcenter_ovf_library__item_deployment__result=objVMwareVCenterOvfLibraryItem.deploy(null,strVAPIContentLibraryModelId,objVMwareVCenterOVFLibraryItemDeploymentTarget,objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec);
if (objVMwareVCenterOvfLibraryItemDeploymentResult.succeeded===true){
letobjVMwareVCenterOvfLibraryItemDeployableIdentity:com_vmware_vcenter_ovf_library__item_deployable__identity=objVMwareVCenterOvfLibraryItemDeploymentResult.resource_id;
letstrXPathQuery:string=`matches(id, '${objVMwareVCenterOvfLibraryItemDeployableIdentity.id}')`;
letarrVcVirtualMachine:VcVirtualMachine[]=this.serverFindAllForType("VC:VirtualMachine",strXPathQuery);
letobjVcVirtualMachine:VcVirtualMachine=arrVcVirtualMachine.find((objVcVirtualMachine:VcVirtualMachine):boolean=>{
returnobjVcVirtualMachine.id===objVMwareVCenterOvfLibraryItemDeployableIdentity.id;
});
returnobjVcVirtualMachine;
}elseif (objVMwareVCenterOvfLibraryItemDeploymentResult.succeeded===false){
returnnull;
}
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
