1. Packages
  2. vSphere
  3. API Docs
  4. getDatastoreStats
vSphere v4.10.0 published on Tuesday, Mar 12, 2024 by Pulumi

vsphere.getDatastoreStats

Explore with Pulumi AI

vsphere logo
vSphere v4.10.0 published on Tuesday, Mar 12, 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 datasource 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 usefull example of this datasource 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 = local.max_free_space_name;
    export const maxFreeSpace = local.max_free_space;
    
    import pulumi
    
    pulumi.export("maxFreeSpaceName", local["max_free_space_name"])
    pulumi.export("maxFreeSpace", local["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", local.Max_free_space_name)
    		ctx.Export("maxFreeSpace", local.Max_free_space)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    
    return await Deployment.RunAsync(() => 
    {
        return new Dictionary<string, object?>
        {
            ["maxFreeSpaceName"] = local.Max_free_space_name,
            ["maxFreeSpace"] = local.Max_free_space,
        };
    });
    
    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", local.max_free_space_name());
            ctx.export("maxFreeSpace", local.max_free_space());
        }
    }
    
    outputs:
      maxFreeSpaceName: ${local.max_free_space_name}
      maxFreeSpace: ${local.max_free_space}
    

    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, Any]] = None,
                            datacenter_id: Optional[str] = None,
                            free_space: Optional[Mapping[str, Any]] = None,
                            opts: Optional[InvokeOptions] = None) -> GetDatastoreStatsResult
    def get_datastore_stats_output(capacity: Optional[pulumi.Input[Mapping[str, Any]]] = None,
                            datacenter_id: Optional[pulumi.Input[str]] = None,
                            free_space: Optional[pulumi.Input[Mapping[str, Any]]] = 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, object>
    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, object>
    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]interface{}
    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]interface{}
    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,Object>
    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,Object>
    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]: any}
    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]: any}
    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, Any]
    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, Any]
    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<Any>
    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<Any>
    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, object>
    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, object>
    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]interface{}
    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]interface{}
    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,Object>
    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,Object>
    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]: any}
    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]: any}
    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, Any]
    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, Any]
    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<Any>
    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<Any>
    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.10.0 published on Tuesday, Mar 12, 2024 by Pulumi