Bug 839259

Summary: libvirt-python API domain query conn.listDefinedDomains() does not list all defined domains as virsh list does.
Product: Red Hat Enterprise Linux 5 Reporter: Frantisek Reznicek <freznice>
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED NOTABUG QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 5.8CC: berrange, bsarathy, esammons
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-07-11 11:53:35 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Frantisek Reznicek 2012-07-11 11:50:24 UTC
Description of problem:

'virsh list' command list all running libvirt domains / machines.

The is an equivalent in libvirt python binding:
  conn = libvirt.openReadOnly(None)
  conn.listDefinedDomains()
Python binding does not provide the information as virsh does.
See Additional info for more details...

Version-Release number of selected component (if applicable):
  libvirt-0.8.2-25.el5
  libvirt-python-0.8.2-25.el5

How reproducible:
  100%

Steps to Reproduce:
  See Additional info...
  
Actual results:
  conn.listDefinedDomains() call does not return all defined domains (as virsh list [--all])

Expected results:
conn.listDefinedDomains() call should return all defined domains (as virsh list [--all])

Additional info:

  [root@mrg-qe-16 ~]# rpm -qa | grep libvirt | sort
  libvirt-0.8.2-25.el5
  libvirt-0.8.2-25.el5
  libvirt-python-0.8.2-25.el5
  [root@mrg-qe-16 ~]# uname -a
  Linux mrg-qe-16.lab.eng.brq.redhat.com 2.6.18-308.8.2.el5 #1 SMP Tue May 29 11:54:17 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
  
  
  [root@mrg-qe-16 ~]# virsh help | grep list | grep -v "\-"
      list            list domains
  [root@mrg-qe-16 ~]# virsh list
  Id Name                 State
  ----------------------------------
    5 cluster-rhel5i-0     running
    6 cluster-rhel5x-4     running
    7 cluster-rhel5x-3     running
    8 cluster-rhel5x-2     running
    9 cluster-rhel5x-1     running
  
  [root@mrg-qe-16 ~]# virsh list --all
  Id Name                 State
  ----------------------------------
    5 cluster-rhel5i-0     running
    6 cluster-rhel5x-4     running
    7 cluster-rhel5x-3     running
    8 cluster-rhel5x-2     running
    9 cluster-rhel5x-1     running
    - cluster-rhel5x-0     shut off
  
  [root@mrg-qe-16 ~]# python
  Python 2.4.3 (#1, May  1 2012, 13:55:48) 
  [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import libvirt
  >>> conn = libvirt.openReadOnly(None)
  >>> conn.listDomainsID()
  [9, 6, 7, 8, 5]
  >>> conn.listDefinedDomains()
  ['cluster-rhel5x-0']
  >>> conn.lookupByName("cluster-rhel5x-1")
  <libvirt.virDomain instance at 0x2aad2ec99200>
  >>> conn2=libvirt.open("qemu:///system")
  >>> conn2.listDomainsID()
  [9, 6, 7, 8, 5]
  >>> conn2.listDefinedDomains()
  ['cluster-rhel5x-0']
  >>>

Comment 1 Daniel Berrangé 2012-07-11 11:53:35 UTC
You are not comparing like-for-like here.  The 'virsh list --all' command will *combine* the results from  listDomainsID() and listDefineDomains().  The listDefinedDomains() API will only list defined domains which are not running.