1. Packages
  2. vSphere
  3. API Docs
  4. getDatastoreStats
vSphere v4.11.2 published on Tuesday, Sep 17, 2024 by Pulumi

vsphere.getDatastoreStats

Explore with Pulumi AI

vsphere logo
vSphere v4.11.2 published on Tuesday, Sep 17, 2024 by Pulumi

    The vsphere.getDatastoreStats data source can be used to retrieve the usage stats of all vSphere datastore objects in a datacenter. This can then be used as a standalone data source to get information required as input to other data sources.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as vsphere from "@pulumi/vsphere";
    
    const datacenter = vsphere.getDatacenter({
        name: "dc-01",
    });
    const datastoreStats = datacenter.then(datacenter => vsphere.getDatastoreStats({
        datacenterId: datacenter.id,
    }));
    
    import pulumi
    import pulumi_vsphere as vsphere
    
    datacenter = vsphere.get_datacenter(name="dc-01")
    datastore_stats = vsphere.get_datastore_stats(datacenter_id=datacenter.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-vsphere/sdk/v4/go/vsphere"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		datacenter, err := vsphere.LookupDatacenter(ctx, &vsphere.LookupDatacenterArgs{
    			Name: pulumi.StringRef("dc-01"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = vsphere.GetDatastoreStats(ctx, &vsphere.GetDatastoreStatsArgs{
    			DatacenterId: datacenter.Id,
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using VSphere = Pulumi.VSphere;
    
    return await Deployment.RunAsync(() => 
    {
        var datacenter = VSphere.GetDatacenter.Invoke(new()
        {
            Name = "dc-01",
        });
    
        var datastoreStats = VSphere.GetDatastoreStats.Invoke(new()
        {
            DatacenterId = datacenter.Apply(getDatacenterResult => getDatacenterResult.Id),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.vsphere.VsphereFunctions;
    import com.pulumi.vsphere.inputs.GetDatacenterArgs;
    import com.pulumi.vsphere.inputs.GetDatastoreStatsArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            final var datacenter = VsphereFunctions.getDatacenter(GetDatacenterArgs.builder()
                .name("dc-01")
                .build());
    
            final var datastoreStats = VsphereFunctions.getDatastoreStats(GetDatastoreStatsArgs.builder()
                .datacenterId(datacenter.applyValue(getDatacenterResult -> getDatacenterResult.id()))
                .build());
    
        }
    }
    
    variables:
      datacenter:
        fn::invoke:
          Function: vsphere:getDatacenter
          Arguments:
            name: dc-01
      datastoreStats:
        fn::invoke:
          Function: vsphere:getDatastoreStats
          Arguments:
            datacenterId: ${datacenter.id}
    

    A useful example of this data source would be to determine the datastore with the most free space. For example, in addition to the above:

    Create an outputs.tf like that:

    import * as pulumi from "@pulumi/pulumi";
    
    export const maxFreeSpaceName = theirMaxFreeSpaceName;
    export const maxFreeSpace = theirMaxFreeSpace;
    
    import pulumi
    
    pulumi.export("maxFreeSpaceName", their_max_free_space_name)
    pulumi.export("maxFreeSpace", their_max_free_space)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		ctx.Export("maxFreeSpaceName", theirMaxFreeSpaceName)
    		ctx.Export("maxFreeSpace", theirMaxFreeSpace)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    
    return await Deployment.RunAsync(() => 
    {
        return new Dictionary<string, object?>
        {
            ["maxFreeSpaceName"] = theirMaxFreeSpaceName,
            ["maxFreeSpace"] = theirMaxFreeSpace,
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            ctx.export("maxFreeSpaceName", theirMaxFreeSpaceName);
            ctx.export("maxFreeSpace", theirMaxFreeSpace);
        }
    }
    
    outputs:
      maxFreeSpaceName: ${theirMaxFreeSpaceName}
      maxFreeSpace: ${theirMaxFreeSpace}
    

    and a locals.tf like that:

    Using getDatastoreStats

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getDatastoreStats(args: GetDatastoreStatsArgs, opts?: InvokeOptions): Promise<GetDatastoreStatsResult>
    function getDatastoreStatsOutput(args: GetDatastoreStatsOutputArgs, opts?: InvokeOptions): Output<GetDatastoreStatsResult>
    def get_datastore_stats(capacity: Optional[Mapping[str, str]] = None,
                            datacenter_id: Optional[str] = None,
                            free_space: Optional[Mapping[str, str]] = None,
                            opts: Optional[InvokeOptions] = None) -> GetDatastoreStatsResult
    def get_datastore_stats_output(capacity: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                            datacenter_id: Optional[pulumi.Input[str]] = None,
                            free_space: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                            opts: Optional[InvokeOptions] = None) -> Output[GetDatastoreStatsResult]
    func GetDatastoreStats(ctx *Context, args *GetDatastoreStatsArgs, opts ...InvokeOption) (*GetDatastoreStatsResult, error)
    func GetDatastoreStatsOutput(ctx *Context, args *GetDatastoreStatsOutputArgs, opts ...InvokeOption) GetDatastoreStatsResultOutput

    > Note: This function is named GetDatastoreStats in the Go SDK.

    public static class GetDatastoreStats 
    {
        public static Task<GetDatastoreStatsResult> InvokeAsync(GetDatastoreStatsArgs args, InvokeOptions? opts = null)
        public static Output<GetDatastoreStatsResult> Invoke(GetDatastoreStatsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetDatastoreStatsResult> getDatastoreStats(GetDatastoreStatsArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: vsphere:index/getDatastoreStats:getDatastoreStats
      arguments:
        # arguments dictionary

    The following arguments are supported:

    DatacenterId string
    The managed object reference ID of the datacenter the datastores are located in. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
    Capacity Dictionary<string, string>
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    FreeSpace Dictionary<string, string>
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    DatacenterId string
    The managed object reference ID of the datacenter the datastores are located in. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
    Capacity map[string]string
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    FreeSpace map[string]string
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    datacenterId String
    The managed object reference ID of the datacenter the datastores are located in. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
    capacity Map<String,String>
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    freeSpace Map<String,String>
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    datacenterId string
    The managed object reference ID of the datacenter the datastores are located in. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
    capacity {[key: string]: string}
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    freeSpace {[key: string]: string}
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    datacenter_id str
    The managed object reference ID of the datacenter the datastores are located in. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
    capacity Mapping[str, str]
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    free_space Mapping[str, str]
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    datacenterId String
    The managed object reference ID of the datacenter the datastores are located in. For default datacenters, use the id attribute from an empty vsphere.Datacenter data source.
    capacity Map<String>
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    freeSpace Map<String>
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.

    getDatastoreStats Result

    The following output properties are available:

    DatacenterId string
    The [managed object reference ID][docs-about-morefs] of the datacenter the datastores are located in.
    Id string
    The provider-assigned unique ID for this managed resource.
    Capacity Dictionary<string, string>
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    FreeSpace Dictionary<string, string>
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    DatacenterId string
    The [managed object reference ID][docs-about-morefs] of the datacenter the datastores are located in.
    Id string
    The provider-assigned unique ID for this managed resource.
    Capacity map[string]string
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    FreeSpace map[string]string
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    datacenterId String
    The [managed object reference ID][docs-about-morefs] of the datacenter the datastores are located in.
    id String
    The provider-assigned unique ID for this managed resource.
    capacity Map<String,String>
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    freeSpace Map<String,String>
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    datacenterId string
    The [managed object reference ID][docs-about-morefs] of the datacenter the datastores are located in.
    id string
    The provider-assigned unique ID for this managed resource.
    capacity {[key: string]: string}
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    freeSpace {[key: string]: string}
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    datacenter_id str
    The [managed object reference ID][docs-about-morefs] of the datacenter the datastores are located in.
    id str
    The provider-assigned unique ID for this managed resource.
    capacity Mapping[str, str]
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    free_space Mapping[str, str]
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.
    datacenterId String
    The [managed object reference ID][docs-about-morefs] of the datacenter the datastores are located in.
    id String
    The provider-assigned unique ID for this managed resource.
    capacity Map<String>
    A mapping of the capacity for all datastore in the datacenter, where the name of the datastore is used as key and the capacity as value.
    freeSpace Map<String>
    A mapping of the free space for each datastore in the datacenter, where the name of the datastore is used as key and the free space as value.

    Package Details

    Repository
    vSphere pulumi/pulumi-vsphere
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the vsphere Terraform Provider.
    vsphere logo
    vSphere v4.11.2 published on Tuesday, Sep 17, 2024 by Pulumi