To use this function add it to the class library file named vCenterVAPIService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: vCenterVAPIService.ts
Public Function: ContentLibraryItemDeployAdvancedOVF
publicContentLibraryItemDeployAdvancedOVF(strTemplateName:string,objVcVmFolder:VcVmFolder,objVcHostSystem:VcHostSystem,objVcResourcePool:VcResourcePool,objVcDatastore:VcDatastore,objVcNetwork:VcNetwork,strVcVirtualMachineName:string,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;
letobjProperties:Properties=newProperties();
objProperties.put("VM Network",objVcNetwork.id);
letobjVMwareVCenterOvfLibraryItemVirtualMachineConfigSpec:com_vmware_vcenter_ovf_library__item_vm__config__spec=newcom_vmware_vcenter_ovf_library__item_vm__config__spec();
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.network_mappings=objProperties;
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.annotation=strAnnotation;
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.default_datastore_id=objVcDatastore.id;
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.vm_config_spec=objVMwareVCenterOvfLibraryItemVirtualMachineConfigSpec;
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;
this.objLogger.info(`Object Type:${objVMwareVCenterOvfLibraryItemDeployableIdentity.type} - Object ID${objVMwareVCenterOvfLibraryItemDeployableIdentity.id}.`);
letstrXPathQuery:string=`xpath:matches(id, '${objVMwareVCenterOvfLibraryItemDeployableIdentity.id}')`;
letarrVcVirtualMachine:VcVirtualMachine[]=VcPlugin.getAllVirtualMachines(null,strXPathQuery);
letobjVcVirtualMachine:VcVirtualMachine=arrVcVirtualMachine.find((objVcVirtualMachine:VcVirtualMachine):boolean=>{
returnobjVcVirtualMachine.id===objVMwareVCenterOvfLibraryItemDeployableIdentity.id;
});
returnobjVcVirtualMachine;
}elseif (objVMwareVCenterOvfLibraryItemDeploymentResult.succeeded===false){
letobjVMwareVCenterOvfLibraryItemResultInfo:com_vmware_vcenter_ovf_library__item_result__info=objVMwareVCenterOvfLibraryItemDeploymentResult.error;
letarrVMwareVCenterOvfOvfInfo:com_vmware_vcenter_ovf_ovf__info[]=objVMwareVCenterOvfLibraryItemResultInfo.information;
arrVMwareVCenterOvfOvfInfo.forEach((objVMwareVCenterOvfOvfInfo:com_vmware_vcenter_ovf_ovf__info):void=>{
this.ContentLibraryItemDeployLogMessages(objVMwareVCenterOvfOvfInfo);
});
letarrVMwareVCenterOvfOvfWarning:com_vmware_vcenter_ovf_ovf__warning[]=objVMwareVCenterOvfLibraryItemResultInfo.warnings;
arrVMwareVCenterOvfOvfWarning.forEach((objVMwareVCenterOvfOvfWarning:com_vmware_vcenter_ovf_ovf__warning):void=>{
this.ContentLibraryItemDeployLogMessages(objVMwareVCenterOvfOvfWarning);
});
letarrVMwareVCenterOvfOvfError:com_vmware_vcenter_ovf_ovf__error[]=objVMwareVCenterOvfLibraryItemResultInfo.errors;
arrVMwareVCenterOvfOvfError.forEach((objVMwareVCenterOvfOvfError:com_vmware_vcenter_ovf_ovf__error):void=>{
this.ContentLibraryItemDeployLogMessages(objVMwareVCenterOvfOvfError);
});
returnnull;
}
}TypeScriptDiscover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
