vmware / govmomi

Go library for the VMware vSphere API
Apache License 2.0
2.27k stars 897 forks source link

How to get VmDiskFileInfo.CapacityKb from .vmdk file? #3376

Closed SoaringAnecdotalBear closed 1 month ago

SoaringAnecdotalBear commented 4 months ago

How to get VmDiskFileInfo.CapacityKb from .vmdk file? I found a TODO here(host_datastore_browser.go 89-91). Does it means Govmomi is unable to get VmDiskFileInfo.CapacityKb? Or is there a other way to get VmDiskFileInfo.CapacityKb? thanks!

github-actions[bot] commented 4 months ago

Howdy 🖐   SoaringAnecdotalBear ! Thank you for your interest in this project. We value your feedback and will respond soon.

If you want to contribute to this project, please make yourself familiar with the CONTRIBUTION guidelines.

dougm commented 3 months ago

That TODO is part of the simulator, do you need that or the client side against a real vCenter? For real vCenter, you can use VM's devices VirtualDisk.CapacityKb, for example:

% govc device.info -dump -vm MinIO disk-*
...
    BaseVirtualDevice: &types.VirtualDisk{
...
        CapacityInKB:    16777216,
...

Or you can use HostDatastoreBrowser to get a .vmdk's capacity directly, for example:

% govc datastore.ls -l MinIO/*.vmdk
16.0GB  Wed Mar 13 17:31:51 2024  MinIO.vmdk

% govc datastore.ls -json -l MinIO/*.vmdk
[
  {
    "datastore": {
      "type": "Datastore",
      "value": "datastore-12"
    },
    "folderPath": "[datastore1] MinIO/",
    "file": [
      {
        "path": "MinIO.vmdk",
        "fileSize": 17179869184,
        "modification": "2024-03-13T17:31:51Z",
        "owner": "root"
      }
    ]
  }
]
SoaringAnecdotalBear commented 2 months ago

@dougm thks for your reply The last way seems to get the physical capacity, and the first way needs that the disk was attached to one vm. But I want to get the logical capacity for vmdk which is not attached to any vm.

That TODO is part of the simulator, do you need that or the client side against a real vCenter? For real vCenter, you can use VM's devices VirtualDisk.CapacityKb, for example:

% govc device.info -dump -vm MinIO disk-*
...
    BaseVirtualDevice: &types.VirtualDisk{
...
        CapacityInKB:    16777216,
...

Or you can use HostDatastoreBrowser to get a .vmdk's capacity directly, for example:

% govc datastore.ls -l MinIO/*.vmdk
16.0GB  Wed Mar 13 17:31:51 2024  MinIO.vmdk

% govc datastore.ls -json -l MinIO/*.vmdk
[
  {
    "datastore": {
      "type": "Datastore",
      "value": "datastore-12"
    },
    "folderPath": "[datastore1] MinIO/",
    "file": [
      {
        "path": "MinIO.vmdk",
        "fileSize": 17179869184,
        "modification": "2024-03-13T17:31:51Z",
        "owner": "root"
      }
    ]
  }
]