[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 0/7] Expose QEMU APIs to Python binding



On Fri, Sep 09, 2011 at 07:24:40PM +0800, Osier Yang wrote:
> This patchset is to expose QEMU APIs to Python binding, as we
> don't intend to support the QEMU APIs officially, it's exposed
> seperately with general libvirt APIs with standalone
> libvirt_qemu.py and libvirtmod_qemu.so. And there is no class
> for QEMU APIs, there are written directly as function in
> libvirt_qemu.py.
> 
> How to use the APIs.
> 
> #! /usr/bin/python -u
> import libvirt
> import libvirt_qemu
> 
> conn = libvirt.open(None)
> dom = conn.lookupByName('test')
> 
> print libvirt_qemu.qemuMonitorCommand(dom, 'info blockstats', 1)
> libvirt_qemu.qemuAttach(conn, 2307, 0)

This feels like rather a strange way to expose this in Python.



We currently have 'libvirt.Connection' and 'libvirt.Domain'
objects in the Python binding.

> conn = libvirt.open(None)

This is giving us a libvirt.Connection object.

> dom = conn.lookupByName('test')

This is giving us a libvirt.Domain object.

> print libvirt_qemu.qemuMonitorCommand(dom, 'info blockstats', 1)

And this is just wierd.


What I think is that we should have a 'libvirt_qemu.QemuConnection' object
which is a subclass of 'libvirt.Connection', and 'libvirt_qemu.QemuDomain'
object which is a subclass of libvirt.Domain' which adds the new QEMU
specific method 'qemuMonitorCommand'.

So the example usage would end up being

  > #! /usr/bin/python -u
  > import libvirt
  > import libvirt_qemu
  >
  > conn = libvirt_qemu.open(None)

This would be a libvirt_qemu.QemuConnection object.

  > dom = conn.lookupByName('test')

And this would thus now be a libvirt_qemu.QemuDomain object,
so that finally you can simply do

  > dom.qemuMonitorCommand('info blockstats', 1)


  # cat libvirt_qemu.py

  def open(name)
     ....call libvirt.open and turn the result
         into a libvirt_qemu.QemuConnection object

  class QemuConnection(libvirt.Connection):
     def __init__(....)
        ...

     def lookupByName(name)
        ...call original lookupByName method and turn
           the result into a libvirt_qemu.Domain object
           instead

  class QemuDomain(libvirt.Domain):
     def __init__(....)
        ...

     def qemuMonitorCommand(cmd, flags)
        ...


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]