This allows to choose between SPICE, VNC or a local display, which will go through SDL or 'desktop' depending on the hypervisor. --- configure.ac | 2 +- examples/virtxml.c | 25 +++++++ libvirt-designer/libvirt-designer-domain.c | 111 +++++++++++++++++++++++++++++ libvirt-designer/libvirt-designer-domain.h | 10 +++ libvirt-designer/libvirt-designer.sym | 2 + 5 files changed, 149 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 228a85c..bad199b 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ AC_CANONICAL_HOST AM_SILENT_RULES([yes]) LIBOSINFO_REQUIRED=0.2.7 -LIBVIRT_GCONFIG_REQUIRED=0.0.9 +LIBVIRT_GCONFIG_REQUIRED=0.1.7 LIBVIRT_GOBJECT_REQUIRED=0.1.3 GOBJECT_INTROSPECTION_REQUIRED=0.10.8 diff --git a/examples/virtxml.c b/examples/virtxml.c index d127406..0d4ebff 100644 --- a/examples/virtxml.c +++ b/examples/virtxml.c @@ -563,6 +563,8 @@ main(int argc, char *argv[]) static char *platform_str = NULL; static char *arch_str = NULL; static char *connect_uri = NULL; + static char *graphics_str = NULL; + GVirDesignerDomainGraphics graphics; static char *resources_str = NULL; GVirDesignerDomainResources resources; GOptionContext *context = NULL; @@ -589,6 +591,8 @@ main(int argc, char *argv[]) "add floppy to domain with PATH being source and FORMAT its format", "PATH[,FORMAT]"}, {"interface", 'i', 0, G_OPTION_ARG_CALLBACK, add_iface_str, "add interface with NETWORK source. Possible ARGs: mac, link={up,down}", "NETWORK[,ARG=VAL]"}, + {"graphics", 'g', 0, G_OPTION_ARG_STRING, &graphics_str, + "add graphical output to the VM. Possible values are 'spice' or 'vnc'", "GRAPHICS"}, {"resources", 'r', 0, G_OPTION_ARG_STRING, &resources_str, "Set minimal or recommended values for cpu count and RAM amount", "{minimal|recommended}"}, {NULL} @@ -669,6 +673,21 @@ main(int argc, char *argv[]) NULL); } + if (graphics_str) { + if (g_str_equal(graphics_str, "spice")) + graphics = GVIR_DESIGNER_DOMAIN_GRAPHICS_SPICE; + else if (g_str_equal(graphics_str, "vnc")) + graphics = GVIR_DESIGNER_DOMAIN_GRAPHICS_VNC; + else { + print_error("Unknown value '%s' for graphics", graphics_str); + goto cleanup; + } + g_object_unref(gvir_designer_domain_add_graphics(domain, + graphics, + &error)); + CHECK_ERROR; + } + g_list_foreach(cdrom_str_list, add_cdrom, domain); g_list_foreach(disk_str_list, add_disk, domain); @@ -779,6 +798,12 @@ Add an interface of type network with I<NETWORK> source. Moreover, some other configuration knobs can be set (possible I<ARG>s): I<mac>, I<link>={up|down} +=item -g GRAPHICS + +Add a graphics device of type I<GRAPHICS>. Valid values are spice +or vnc. + + =item -r RESOURCE, --resources=RESOURCES Set I<minimal> or I<recommended> resources on the domain XML. By default, diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c index 98b30d5..95e855d 100644 --- a/libvirt-designer/libvirt-designer-domain.c +++ b/libvirt-designer/libvirt-designer-domain.c @@ -348,6 +348,117 @@ static void gvir_designer_domain_add_clock(GVirDesignerDomain *design) g_object_unref(G_OBJECT(clock)); } + +static GVirConfigDomainGraphics * +gvir_designer_domain_create_graphics_desktop(GVirDesignerDomain *design, + GError **error) +{ + int virt_type; + + virt_type = gvir_config_domain_get_virt_type(design->priv->config); + + switch (virt_type) { + case GVIR_CONFIG_DOMAIN_VIRT_QEMU: + case GVIR_CONFIG_DOMAIN_VIRT_KQEMU: + case GVIR_CONFIG_DOMAIN_VIRT_KVM: { + GVirConfigDomainGraphicsSdl *sdl; + sdl = gvir_config_domain_graphics_sdl_new(); + return GVIR_CONFIG_DOMAIN_GRAPHICS(sdl); + } + case GVIR_CONFIG_DOMAIN_VIRT_VBOX: { + GVirConfigDomainGraphicsDesktop *desktop; + desktop = gvir_config_domain_graphics_desktop_new(); + return GVIR_CONFIG_DOMAIN_GRAPHICS(desktop); + } + default: + g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0, + "Virt type %d does not support this graphics output", + virt_type); + return NULL; + } +} + +/** + * gvir_designer_domain_add_graphics: + * @design: (transfer none): the domain designer instance + * @error: return location for a #GError, or NULL + * + * Add a new graphical framebuffer to @design. This allows + * to see what the VM displays. + * Remote display protocols will only be listening on localhost, and the + * port will be automatically allocated when the VM starts (usually + * starting at 5900). You can manipulate further the returned + * #GVirConfigDomainGraphics if you want a different behaviour. + * When setting up a SPICE display, the SPICE agent channel will be + * automatically added to the VM if it's supported and not already + * present. + * + * Returns: (transfer full): the pointer to the new graphical framebuffer + * configuration object. + */ +GVirConfigDomainGraphics * +gvir_designer_domain_add_graphics(GVirDesignerDomain *design, + GVirDesignerDomainGraphics type, + GError **error) +{ + GVirConfigDomainGraphics *graphics; + + g_return_val_if_fail(GVIR_DESIGNER_IS_DOMAIN(design), NULL); + g_return_val_if_fail(!error_is_set(error), NULL); + + switch (type) { + case GVIR_DESIGNER_DOMAIN_GRAPHICS_DESKTOP: { + graphics = gvir_designer_domain_create_graphics_desktop(design, error); + if (graphics == NULL) + return NULL; + } + + case GVIR_DESIGNER_DOMAIN_GRAPHICS_RDP: { + GVirConfigDomainGraphicsRdp *rdp; + + rdp = gvir_config_domain_graphics_rdp_new(); + gvir_config_domain_graphics_rdp_set_autoport(rdp, TRUE); + graphics = GVIR_CONFIG_DOMAIN_GRAPHICS(rdp); + + break; + } + + case GVIR_DESIGNER_DOMAIN_GRAPHICS_SPICE: { + GVirConfigDomainGraphicsSpice *spice; + + spice = gvir_config_domain_graphics_spice_new(); + gvir_config_domain_graphics_spice_set_autoport(spice, TRUE); + /* FIXME: Should only be done for local domains */ + gvir_config_domain_graphics_spice_set_image_compression(spice, + GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE_IMAGE_COMPRESSION_OFF); + graphics = GVIR_CONFIG_DOMAIN_GRAPHICS(spice); + + break; + } + + case GVIR_DESIGNER_DOMAIN_GRAPHICS_VNC: { + GVirConfigDomainGraphicsVnc *vnc; + + vnc = gvir_config_domain_graphics_vnc_new(); + gvir_config_domain_graphics_vnc_set_autoport(vnc, TRUE); + graphics = GVIR_CONFIG_DOMAIN_GRAPHICS(vnc); + + break; + } + + default: + g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0, + "Unknown graphics type: %d", type); + g_return_val_if_reached(NULL); + } + + gvir_config_domain_add_device(design->priv->config, + GVIR_CONFIG_DOMAIN_DEVICE(graphics)); + + return graphics; +} + + static void gvir_designer_domain_add_power_management(GVirDesignerDomain *design) { GVirConfigDomainPowerManagement *pm; diff --git a/libvirt-designer/libvirt-designer-domain.h b/libvirt-designer/libvirt-designer-domain.h index c0d06e8..1399bd4 100644 --- a/libvirt-designer/libvirt-designer-domain.h +++ b/libvirt-designer/libvirt-designer-domain.h @@ -44,6 +44,13 @@ typedef enum { GVIR_DESIGNER_DOMAIN_RESOURCES_RECOMMENDED, } GVirDesignerDomainResources; +typedef enum { + GVIR_DESIGNER_DOMAIN_GRAPHICS_DESKTOP, + GVIR_DESIGNER_DOMAIN_GRAPHICS_RDP, + GVIR_DESIGNER_DOMAIN_GRAPHICS_SPICE, + GVIR_DESIGNER_DOMAIN_GRAPHICS_VNC, +} GVirDesignerDomainGraphics; + typedef struct _GVirDesignerDomain GVirDesignerDomain; typedef struct _GVirDesignerDomainPrivate GVirDesignerDomainPrivate; typedef struct _GVirDesignerDomainClass GVirDesignerDomainClass; @@ -125,6 +132,9 @@ GVirConfigDomainInterface *gvir_designer_domain_add_interface_network(GVirDesign const char *network, GError **error); +GVirConfigDomainGraphics *gvir_designer_domain_add_graphics(GVirDesignerDomain *design, + GVirDesignerDomainGraphics type, + GError **error); GVirConfigDomainSound *gvir_designer_domain_add_sound(GVirDesignerDomain *design, GError **error); gboolean gvir_designer_domain_setup_resources(GVirDesignerDomain *design, diff --git a/libvirt-designer/libvirt-designer.sym b/libvirt-designer/libvirt-designer.sym index 0a8b49e..9a73993 100644 --- a/libvirt-designer/libvirt-designer.sym +++ b/libvirt-designer/libvirt-designer.sym @@ -5,6 +5,7 @@ LIBVIRT_DESIGNER_0.0.2 { gvir_designer_domain_new; gvir_designer_domain_get_type; + gvir_designer_domain_graphics_get_type; gvir_designer_domain_get_config; gvir_designer_domain_get_os; gvir_designer_domain_get_platform; @@ -19,6 +20,7 @@ LIBVIRT_DESIGNER_0.0.2 { gvir_designer_domain_add_disk_device; gvir_designer_domain_add_floppy_file; gvir_designer_domain_add_floppy_device; + gvir_designer_domain_add_graphics; gvir_designer_domain_add_interface_network; gvir_designer_domain_add_sound; gvir_designer_domain_setup_resources; -- 1.8.2.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list