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
public ContentLibraryItemDeployAdvancedOVF(strTemplateName: string, objVcVmFolder: VcVmFolder, objVcHostSystem: VcHostSystem, objVcResourcePool: VcResourcePool, objVcDatastore: VcDatastore, objVcNetwork: VcNetwork, strVcVirtualMachineName: string, 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 objProperties: Properties = new Properties();
objProperties.put("VM Network", objVcNetwork.id);
let objVMwareVCenterOvfLibraryItemVirtualMachineConfigSpec: com_vmware_vcenter_ovf_library__item_vm__config__spec = new com_vmware_vcenter_ovf_library__item_vm__config__spec();
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.network_mappings = objProperties;
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.annotation = strAnnotation;
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.default_datastore_id = objVcDatastore.id;
objVMwareVCenterOvfLibraryItemResourcePoolDeploymentSpec.vm_config_spec = objVMwareVCenterOvfLibraryItemVirtualMachineConfigSpec;
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;
this.objLogger.info(`Object Type: ${objVMwareVCenterOvfLibraryItemDeployableIdentity.type} - Object ID ${objVMwareVCenterOvfLibraryItemDeployableIdentity.id}.`);
let strXPathQuery: string = `xpath:matches(id, '${objVMwareVCenterOvfLibraryItemDeployableIdentity.id}')`;
let arrVcVirtualMachine: VcVirtualMachine[] = VcPlugin.getAllVirtualMachines(null, strXPathQuery);
let objVcVirtualMachine: VcVirtualMachine = arrVcVirtualMachine.find((objVcVirtualMachine: VcVirtualMachine): boolean => {
return objVcVirtualMachine.id === objVMwareVCenterOvfLibraryItemDeployableIdentity.id;
});
return objVcVirtualMachine;
} else if (objVMwareVCenterOvfLibraryItemDeploymentResult.succeeded === false) {
let objVMwareVCenterOvfLibraryItemResultInfo: com_vmware_vcenter_ovf_library__item_result__info = objVMwareVCenterOvfLibraryItemDeploymentResult.error;
let arrVMwareVCenterOvfOvfInfo: com_vmware_vcenter_ovf_ovf__info[] = objVMwareVCenterOvfLibraryItemResultInfo.information;
arrVMwareVCenterOvfOvfInfo.forEach((objVMwareVCenterOvfOvfInfo: com_vmware_vcenter_ovf_ovf__info): void => {
this.ContentLibraryItemDeployLogMessages(objVMwareVCenterOvfOvfInfo);
});
let arrVMwareVCenterOvfOvfWarning: com_vmware_vcenter_ovf_ovf__warning[] = objVMwareVCenterOvfLibraryItemResultInfo.warnings;
arrVMwareVCenterOvfOvfWarning.forEach((objVMwareVCenterOvfOvfWarning: com_vmware_vcenter_ovf_ovf__warning): void => {
this.ContentLibraryItemDeployLogMessages(objVMwareVCenterOvfOvfWarning);
});
let arrVMwareVCenterOvfOvfError: com_vmware_vcenter_ovf_ovf__error[] = objVMwareVCenterOvfLibraryItemResultInfo.errors;
arrVMwareVCenterOvfOvfError.forEach((objVMwareVCenterOvfOvfError: com_vmware_vcenter_ovf_ovf__error): void => {
this.ContentLibraryItemDeployLogMessages(objVMwareVCenterOvfOvfError);
});
return null;
}
}TypeScriptDiscover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
