VMware Cloud Community
admin
Immortal
Immortal

How to get provisioned space for datastore using vsphere API

I'd like to know the API to use to get the provisioned space for a datastore. This is displayed in vsphere under ‘provisioned space’ in the summary tab of a ‘datastore’ in Inventory > Datastores view.

I looked around in datastore related APIs and could not find any property that can give me this value. If not a single property/API, is there a way to write some code to compute this based on available vsphere APIs?

Reply
0 Kudos
2 Replies
vmroyale
Immortal
Immortal

Hello.

Note: This discussion was moved from the VMware vCenter Server community to the Automation Tools community.

Good Luck!

Brian Atkinson | vExpert | VMTN Moderator | Author of "VCP5-DCV VMware Certified Professional-Data Center Virtualization on vSphere 5.5 Study Guide: VCP-550" | @vmroyale | http://vmroyale.com
Reply
0 Kudos
mattboren
Expert
Expert

Hello, Ragsboss-

You should be able to use a few of the properties of a VMware.Vim.DatastoreSummary object (reference at http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.Datastore.Summary.html).  There is not a "ProvisionedSpace" property, but you can calculate it from:

propertydescription (brief)
capacity

Maximum capacity of the datastore, in bytes

freeSpaceAvailable space of the datastore, in bytes
uncommitted

Total additional storage space, in bytes,

potentially used by all VMs on the datastore

Since provisioned space is sum of used space (which is capacity - freeSpace) and the uncommitted bytes, the simple math would be something like:

$longProvisionedBytes = $dstoreSummary.Capacity - $dstoreSummary.freeSpace + $dstoreSummary.uncommitted

How does that look?

Reply
0 Kudos