Daniel P. Berrange wrote: > 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') Thanks for that! > 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 Understood. Could this code be wrapped libvirt side with something like: domain.xpath('/domain/devices/graphics[@type='vnc']/@port') So that libvirt consumers dont need an explicit dependency on XML libraries? Just another question that came to mind: how do I get notified when something happens to a domain? IE: how can I fire a script whenever a domain is created/added/stopped? Thanks Antoine > > Daniel -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list