Ricardo Hillbrecht
2012-Jun-12 02:20 UTC
[libvirt-users] How to list and change domain's disk image file
Hi I'm writing a C program using libvirt API and need to list the storage volumes used by each domain. I'm wondering if there is a way to do this better of searching the XML strings of all domains, does anyone can suggest me something ? I also need to create a function to change the img file of a given domain. I intend to do the following: 1. virDomainGetXMLDesc (domain) 2. change the XML to other img file 3. virDomainUndefine (domain) 4. virDomainCreateXML (changed XML) Am i correct doing this ? There is a better method ? Thanks Ricardo
Eric Blake
2012-Jun-12 02:26 UTC
[libvirt-users] How to list and change domain's disk image file
On 06/11/2012 08:20 PM, Ricardo Hillbrecht wrote:> Hi > > I'm writing a C program using libvirt API and need to list the storage > volumes used by each domain. I'm wondering if there is a way to do > this better of searching the XML strings of all domains, does anyone > can suggest me something ?Parsing the XML is the current method of doing this. I have plans of someday adding a new API that returns a list of virStorageVolPtr corresponding to a given domain, but that's still a ways down the road.> > I also need to create a function to change the img file of a given > domain. I intend to do the following: > > 1. virDomainGetXMLDesc (domain) > 2. change the XML to other img file > 3. virDomainUndefine (domain)You can skip this step (it is okay to redefine an existing domain).> 4. virDomainCreateXML (changed XML) > > Am i correct doing this ? There is a better method ?You are doing it correctly for affecting the next boot; and this is how programs like virt-manager do it. If you want the changes to take place while the domain is live, then you will have to use the hotplug APIs such as virDomainDeviceModify. -- Eric Blake eblake at redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 620 bytes Desc: OpenPGP digital signature URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20120611/ff6493ba/attachment.sig>