On Thu, Jun 13, 2019 at 03:17:16PM +0530, Varsha Verma wrote:
Hello everyone,
I am doing an outreachy internship at Openstack Ironic. In the sushy-tools
project, we are using libvirt VMs to simulate bare metal machines for
testing purposes.
In the XML description of a domain, there are a bunch of disk elements
giving information about the various storage devices attached to the
domain. Is there some way to get the size/capacity of those disks using the
libvirt API?
Yes, there is, virStorageVolGetXMLDesc:
https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetXML...
Look for <capacity/>
The tricky part might be to get the storage volume object. I'm not sure how
sushy-tools are using libvirt and what the deployment looks like, so here are
few tips and feel free to ask for more info.
If it is a path on the local filesystem, you might just use
`virStorageVolLookupByKey` and be done with it:
https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookup...
If it is not, you might need to look it up based on the pool it is in.
If you have the pool already, then it is a matter of `virStorageVolLookupBy*`
for example. If you don't have that you might look for the pool with
`virStoragePoolLookupBy*`, for example `virStoragePoolLookupByName`:
https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLooku...
And one more general libvirt advice (although maybe not really a good one,
definitely not a silver bullet):
You can always have a look at how `virsh` does things. It might be a bit
confusing at times, but if you have a command name (in our case we'd use the
`vol-dumpxml` command), you can CamelCase it ("VolDumpXML"), prepend
"cmd" (as
in "command") and the resulting name (`cmdVolDumpXML`) is the name of the
function that virsh runs for that command. You can see it in
tools/virsh-volume.c:
https://github.com/libvirt/libvirt/blob/master/tools/virsh-volume.c#L1211
The main part of how it looks up a volume is `virshCommandOptVol` which is just
a syntax sugar for `virshCommandOptVolBy` in the same file:
https://github.com/libvirt/libvirt/blob/master/tools/virsh-volume.c#L68
Which is trying to do the lookup by all various possible things. Same thing can
be found for `pool-*` commands.
HTH, have a nice day,
Martin
--
*Regards,*
*Varsha Verma*
*Fourth Year Undergraduate*
*Department of Electrical Engineering*
*IIT-BHU, Varanasi*
_______________________________________________
libvirt-users mailing list
libvirt-users(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-users