[libvirt] [RFC] Unify KVM kernel-space and user-space code into a single project

Daniel P. Berrange berrange at redhat.com
Fri Apr 9 14:59:24 UTC 2010

On Fri, Apr 09, 2010 at 03:53:37PM +0100, Antoine Martin wrote:
> Daniel P. Berrange wrote:
> > On Fri, Apr 09, 2010 at 03:31:37PM +0100, Antoine Martin wrote:
> >> [snip]
> >>>> * not everything is exposed via libvirt:
> >>>> virsh can retrieve vncdisplay
> >>>> but libvirt (or at least the python bindings) does not. How come?
> >>>> This happens to be one thing I need for writing a libvirt backend for my
> >>>> virtual desktop software.
> >>> The 'virsh vncdisplay' command is simply fetching the XML doc for the
> >>> guest and then extracting the VNC port using a xpath expression
> >>>
> >>>    /domain/devices/graphics[@type='vnc']/@port
> >>>
> >>> So for python you'd want to just get an XML handling module and do similar.
> >> Yes, I saw that in the virsh code.
> >> Shouldn't this be part of the libvirt api proper??
> >> Isn't it supposed to shield us from dealing with files and XML?
> > 
> > It isn't scalable to add APIs for extracting each possible piece of info
> > from the XML. All languages have APIs for extracting data from XML using
> > XPath (or DOM). Thus it is better to leave that flexibility to the apps
> > rather than hardcoding APIs for it in libvirt. The XML schemas/docs are
> > a formal part of the libvit API, so we're not trying to sheild that from
> > apps.
> > 
> I was thinking of something like:
> domain.get_attribute("vncdisplay")
> Because it's a shame to have to use virsh as a wrapper (or XML file
> parsing) and re-do all the work that was done to get to the domain
> object when all your really want is just an attribute..

You can already do that very simply in python using lxml
   from lxml import etree
   tree = etree.parse(domain.XMLDesc())
   r = tree.xpath('/domain/devices/graphics[@type='vnc']/@port')

So adding an API for this is only saving at best 2 lines of code, and is 
much less flexible in what it can do

|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

More information about the libvir-list mailing list