[libvirt] API calls to get interfaces and block devices

Ruben Kerkhof ruben at rubenkerkhof.com
Fri Apr 11 15:54:32 UTC 2014


On Fri, Apr 11, 2014 at 2:11 PM, Daniel P. Berrange <berrange at redhat.com> wrote:
> On Fri, Apr 11, 2014 at 01:56:31PM +0200, Ruben Kerkhof wrote:
>> On Fri, Apr 11, 2014 at 1:23 PM, Daniel P. Berrange <berrange at redhat.com> wrote:
>> > On Fri, Apr 11, 2014 at 01:14:50PM +0200, Ruben Kerkhof wrote:
>> >> Hi all,
>> >>
>> >> I have a few python scripts which use the libvirt api to get interface and block device statistics.
>> >> What has been bugging me for a while now that is that there’s no high level api to get a list of all interfaces or block devices for a vm.
>> >> The list can be retrieved from the xml with a bit of Xpath magic, but this seems to me to break the nice abstraction layer libvirt provides.
>> >> Ideally, I don’t have to do anything with xml, and add dependencies on xml parsers to my code.
>> >>
>> >> I’ve seen examples of code doing this, for example the collectd libvirt plugin, but there must be many others.
>> >>
>> >> Can I kindly ask for such an API? Unfortunately I don’t have the skills to code this up myself.
>> >
>> > The libvirt-glib project provides a set of libraries including
>> > libvirt-gconfig which intend to fill the gap you describe. They
>> > are accessible from Python using GObject Introspection support.
>> > The goal of libvirt-gconfig is to remove the need for apps to
>> > know anything about XML at all.
>>
>> So now instead of having to learn XML parsing I'll have to learn
>> GObject and glib?
>> And instead of a dependency on an xml parser I'll have to add one on glib.
>> Not exactly the easy solution I was hoping for ;-)
>
> Since you're using this from python, you don't have to learn / use
> any of glib / gobject, beyond the way you right the "import"
> statements. As the example I gave showed, the libvirt gconfig API
> just appears mapped into the regular Python object model. A dep
> on glib is really totally inconsequential compared to the deps that
> the main libvirt.so already has.

You're right, I just played a bit with it and it looks easy enough.
>
> This effort wouldn't be practical without using GObject, because
> this frees us from having to write bindings for every programming
> language which has proved a major timesink with main libvirt library.

I understand.
>
>> Thanks for the example, I'll dig into it.
>> I just read https://www.berrange.com/posts/2011/11/22/introducing-the-libvirt-glib-a-mapping-of-the-libvirt-api-and-xml-to-glibgobject/
>> Is there any documentation available for  libvirt-gobject online?
>
> The -devel RPMs include the gtk-doc API docs, but I will freely admit they
> are pretty horribly incomplete.  The easiest way to see APIs available is
> to use python's built-in introspection eg
>
>>>> from gi.repository import LibvirtGConfig;
>>>> print dir(LibvirtGConfig.Domain)
> ['__class__', '__copy__', '__deepcopy__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__gdoc__', '__ge__', '__getattribute__', '__gpointer__', '__grefcount__', '__gsignals__', '__gt__', '__gtype__', '__hash__', '__info__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_force_floating', '_ref', '_ref_sink', '_unref', '_unsupported_data_method', '_unsupported_method', 'add_device', 'bind_property', 'bind_property_full', 'chain', 'compat_control', 'connect', 'connect_after', 'connect_object', 'connect_object_after', 'disconnect', 'disconnect_by_func', 'emit', 'emit_stop_by_name', 'error_quark', 'force_floating', 'freeze_notify', 'g_type_instance', 'get_cpu', 'get_current_memory', 'get_custom_xml', 'get_data', 'get_description', 'get_devices', 'get_features', 'get_memory', 'get_name', 'get_os', 'get_properties', 'get_property', 'get_qdata', 'get_schema', 'get_title', 'get_vcpus', 'get_virt_type', 'handler_block', 'handler_block_by_func', 'handler_disconnect', 'handler_is_connected', 'handler_unblock', 'handler_unblock_by_func', 'interface_find_property', 'interface_install_property', 'interface_list_properties', 'is_floating', 'new', 'new_from_xml', 'notify', 'notify_by_pspec', 'parent', 'priv', 'props', 'qdata', 'ref', 'ref_count', 'ref_sink', 'replace_data', 'replace_qdata', 'run_dispose', 'set_clock', 'set_cpu', 'set_current_memory', 'set_custom_xml', 'set_data', 'set_description', 'set_devices', 'set_features', 'set_lifecycle', 'set_memory', 'set_name', 'set_os', 'set_power_management', 'set_properties', 'set_property', 'set_seclabel', 'set_title', 'set_vcpus', 'set_virt_type', 'steal_data', 'steal_qdata', 'stop_emission', 'stop_emission_by_name', 'thaw_notify', 'to_xml', 'unref', 'validate', 'watch_closure', 'weak_ref']
>
>> Unfortunately I'm still stuck on Scientific Linux 6.5
>> There are no packages for libvirt-glib in the Scientific Linux repo,
>> are they available for libvirt 0.10 on RHEL 6.5?
>
> Ah, I'm afraid you're out of luck on RHEL-6. This is only something we cna
> support on Fedora or forthcoming RHEL-7.
>
> 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 :|

Kind regards,

Ruben




More information about the libvir-list mailing list