[Libvir] python/libvir.html example needs adjustment

Hello, Trying a variant of this example from python/libvir.html: import libvirt import sys conn = libvirt.openReadOnly(None) if conn == None: print 'Failed to open connection to the hypervisor' sys.exit(1) dom0 = conn.lookupByName("Domain-0") if dom0 == None: print 'Failed to find the main domain' sys.exit(1) print "Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType()) print dom0.info() I found that conn.lookupByName throws an exception when the specified name is not found. If the example is just out of date, it should use try:/except: instead of comparing dom0 to None, shouldn't it? You can demonstrate it like this: $ python -c 'import libvirt; libvirt.openReadOnly(None).lookupByName("x")' libvir: Xen Daemon error : GET operation failed: No such domain x Traceback (most recent call last): File "<string>", line 1, in ? File "/usr/lib/python2.4/site-packages/libvirt.py", line 213, in lookupByName if ret is None:raise libvirtError('virDomainLookupByName() failed') libvirt.libvirtError: virDomainLookupByName() failed [Exit 1] Jim

On Tue, Mar 28, 2006 at 02:45:15PM +0200, Jim Meyering wrote:
I found that conn.lookupByName throws an exception when the specified name is not found. If the example is just out of date, it should use try:/except: instead of comparing dom0 to None, shouldn't it?
Right, that's something I changed (or rather fixed the exception used to not be raised as expected) recently, I fixed the various examples and the doc, this is in CVs and should be on the web site shortly, thanks for the heads up ! Daniel -- Daniel Veillard | Red Hat http://redhat.com/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
participants (2)
-
Daniel Veillard
-
Jim Meyering