[virt-tools-list] Which method to call to get list of all virtual machine in system

Matthias Schmitz matthias at sigxcpu.org
Sun Mar 24 09:29:18 UTC 2013


Hi Sandeep,

Am Sun, 24 Mar 2013 12:36:08 +0530
schrieb sandeep krishnamurthy <sandeep.krishna98 at gmail.com>:

> *Which python module, method, will be helpful to get list of all
> virtual machine in the system and also what is the type of return
> value(is it list of strings(names)). *
i'am using the Python module libvirt (version 1.0.1) and can use this:

-----
# use you connection string here
connection = libvirt.open('qemu:///system')
vmlist = connection.listAllDomains()
for vm in vmlist:
    print vm.name()
-----
The return value of listAllDomains() is a list of virDomain objects.

You can also use connection.listDomainsID() to get a DomainID
(integer) list of running domains.

To get a list of all not runnig domains you can use 
connection.listDefinedDomains(). The return value is a list of strings
with the names of the defined domains.

Best wishes,
Matthias 




More information about the virt-tools-list mailing list