Function: vCenter Datastore Has Enough Free Space

by Simon Sparks · 23 January 2026

To use this function add it to the class library file named PluginVCDatastoreService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: PluginVCDatastoreService.ts

Function HasEnoughFreeSpace

Description: Orchestrator Function to Check the Datastore Free Space

public HasEnoughFreeSpace(objVcDatastore: VcDatastore, intRequiedDiskSpaceInMB: number): boolean {

    let objVcStoragePod: VcStoragePod = this.VcManagedEntityGetParentVcStoragePod(objVcDatastore);

    this.objLogger.info(`Storage Pod: ${objVcStoragePod.name} - Capacity: ${objVcStoragePod.summary.capacity} - Free Space: ${objVcStoragePod.summary.freeSpace}.`);

    let intSpaceUtilizationThreshold: number = this.VcStoragePodGetSpaceUtilizationThreshold(objVcStoragePod);

    let intFreeSpaceInMB: number = objVcDatastore.freeSpace * 1024;
    let intCapacityInMB: number = objVcDatastore.capacity * 1024;

    let intUsedSpaceInMB: number = intCapacityInMB - intFreeSpaceInMB + intRequiedDiskSpaceInMB;

    let intMultiplier: number = Math.pow(10, 2);

    let intUtilisedInPercent: number = (intUsedSpaceInMB / intCapacityInMB) * 100;

    intUtilisedInPercent = Math.round(intUtilisedInPercent * intMultiplier) / intMultiplier;

    return intUtilisedInPercent < intSpaceUtilizationThreshold;
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like