[libvirt] [RFC] [libvirt-gconfig] Suggestion about (maybe) re-factoring GVirtConfigDomainGraphics

Fabiano Fidêncio fidencio at redhat.com
Mon Feb 29 22:51:26 UTC 2016


I've been trying to use libvirt-gobject and libvirt-gconfig, on
virt-viewer, for accessing VMs and looking at their config, instead of
using libvrit and parsing XML directly and turns out, that
libvirt-gconfig is not exactly handful for a "read-only" use case (as
virt-viewer's one).

Let me try to explain pointing to some code as example and then I'll
give my suggestions.
For example, let's take a look on

In this function, the first thing done is to get the type of the
graphic device (SPICE or VNC) and here is the first problem. There is
no straightforward way for doing this on libvirt-gconfig (or is
Seems easier to continue getting the type using libxml and then use
the specific spice/vnc functions for getting the properties. And here
is the second problem, because I'll always need to have an if/else
statement for getting the properties. Something like:
if (g_str_equal(type, "vnc"))
  port = gvir_config_domain_graphics_vnc_get_port(domain);
else if (g_str_equal(type, "spice"))
  port = gvir_config_domain_graphics_spice_get_port(domain);

This kind of usage makes me think that libvirt-gconfig is missing some
abstraction class, parent of GVirConfigDomainGraphics{Spice,Vnc,...)
which could provide virtual functions like:
  gtype = gvir_config_domain_graphics_get_gtype(domain);
  port = gvir_config_domain_graphics_get_port(domain);

Thinking a bit about it and taking a look in the
GVirConfigDomainGraphics code, is possible to see a possibility for 2
new classes:
GVirConfigDomainGraphicsLocal and GVirConfigDomainGraphicsRemote.

Then we could have something like:
 |   GVirtConfigDomainGraphicsLocal
 |   |_
 |   |  GVirtConfigDomainGraphicsLocalDesktop
 |   |_
 |      GVirtConfigDomainGraphicsLocalSdl
     |   GVirtConfigDomainGraphicsRemoteSpice
     |   GVirtConfigDomainGraphicsRemoteVnc

I do know that Local and Remote are not exactly accurate names, but is
the best that I could come up with.

So, would be acceptable to introduce these two new classes and then
have the specific graphics classes inheriting from those? Does this
make sense for you, people?

I'm more than happy in provide the code for this, but not before we
discuss and set a decision about the approach. :-)

I'm looking forward for some feedback.
Fabiano Fidêncio

More information about the libvir-list mailing list