Function: vCenter VAPI Plugin Content Library Item Deploy

by Simon Sparks · 18 January 2026

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

public ContentLibraryItemDeployOVF(strTemplateName: string, strVcVirtualMachineName: string, objVcVmFolder: VcVmFolder, objVcDatastore: VcDatastore, objVcHostSystem: VcHostSystem, objVcResourcePool: VcResourcePool, strAnnotation: string): VcVirtualMachine {

    let strVAPIContentLibraryModelId: string = this.ContentLibraryItemGetIDByName(strTemplateName);

    let objVMwareVCenterOVFLibraryItemDeploymentTarget: com_vmware_vcenter_ovf_library__item_deployment__target = new com_vmware_vcenter_ovf_library__item_deployment__target();
    objVMwareVCenterOVFLibraryItemDeploymentTarget.folder_id = objVcVmFolder.id;
    objVMwareVCenterOVFLibraryItemDeploymentTarget.host_id = objVcHostSystem.id;
    objVMwareVCenterOVFLibraryItemDeploymentTarget.resource_pool_id = objVcResourcePool.id;

    let objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec: com_vmware_vcenter_ovf_library__item_resource__pool__deployment__spec = new com_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;

    let objVMwareVCenterOvfLibraryItem: com_vmware_vcenter_ovf_library__item = new com_vmware_vcenter_ovf_library__item(this.objVAPIClient);

    let objVMwareVCenterOvfLibraryItemDeploymentResult: com_vmware_vcenter_ovf_library__item_deployment__result = objVMwareVCenterOvfLibraryItem.deploy(null, strVAPIContentLibraryModelId, objVMwareVCenterOVFLibraryItemDeploymentTarget, objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec);

    if (objVMwareVCenterOvfLibraryItemDeploymentResult.succeeded === true) {

        let objVMwareVCenterOvfLibraryItemDeployableIdentity: com_vmware_vcenter_ovf_library__item_deployable__identity = objVMwareVCenterOvfLibraryItemDeploymentResult.resource_id;

        let strXPathQuery: string = `matches(id, '${objVMwareVCenterOvfLibraryItemDeployableIdentity.id}')`;

        let arrVcVirtualMachine: VcVirtualMachine[] = this.serverFindAllForType("VC:VirtualMachine", strXPathQuery);

        let objVcVirtualMachine: VcVirtualMachine = arrVcVirtualMachine.find((objVcVirtualMachine: VcVirtualMachine): boolean => {
            return objVcVirtualMachine.id === objVMwareVCenterOvfLibraryItemDeployableIdentity.id;
        });

        return objVcVirtualMachine;
    } else if (objVMwareVCenterOvfLibraryItemDeploymentResult.succeeded === false) {
        return null;
    }
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like