[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

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@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Thank you for your fast answer, and the new API will be welcome when it comes. Regards Ricardo 2012/6/11, Eric Blake <eblake@redhat.com>:
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@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Ricardo Hillbrecht