vmware / govmomi

Go library for the VMware vSphere API
Apache License 2.0
2.31k stars 911 forks source link

GOVC and library items #3042

Closed Joffrey54 closed 1 year ago

Joffrey54 commented 1 year ago

Hi,

Is it possible to get hardware information about a library item (OVF) ? I need to get disks size. Is is possible to add tag as on a library item (it's possible in the UI) ?

Thanks you

github-actions[bot] commented 1 year ago

Howdy 🖐   nORKy54 ! 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 1 year ago

Hi @nORKy54 , virtual hardware info is not provided via the API. We'd have to parse it out of the OVF. We have the code to do that and with some refactoring could add the info to govc. In the meantime you could parse it out using library.export:

% govc library.export /Kubernetes/photon*/*.ovf - | grep Disk
  <DiskSection>
    <Disk ovf:populatedSize="2894921728" ovf:capacityAllocationUnits="byte" ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" ovf:diskId="vmdisk1" ovf:capacity="17179869184" ovf:fileRef="file1"/>
  </DiskSection>

Yes, you can tag library items, for example:

% govc tags.attach tkr-k8s /Kubernetes/photon-3-k8s-v1.22.9---vmware.1-tkg.1.73d1d07

% govc tags.attached.ls tkr-k8s
com.vmware.content.library.Item:02accb0e-25a1-47ed-87ff-0325eb526810

% govc tags.attached.ls -r /Kubernetes/photon-3-k8s-v1.22.9---vmware.1-tkg.1.73d1d07
tkr-k8s
dougm commented 1 year ago

You can also use the xmlstarlet program to parse disk size like so:

% govc library.export /Kubernetes/photon*/*.ovf - | xml sel -N ovf=http://schemas.dmtf.org/ovf/envelope/1 -t -m /ovf:Envelope/ovf:DiskSection/ovf:Disk -v @ovf:capacity
17179869184
Joffrey54 commented 1 year ago

Thanks you !