From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx> Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 11 ++- ...libvirt-gconfig-capabilities-cpu-arch-private.h | 39 +++++ .../libvirt-gconfig-capabilities-cpu-arch.c | 135 +++++++++++++++++ .../libvirt-gconfig-capabilities-cpu-arch.h | 71 +++++++++ .../libvirt-gconfig-capabilities-domain-private.h | 39 +++++ .../libvirt-gconfig-capabilities-domain.c | 93 ++++++++++++ .../libvirt-gconfig-capabilities-domain.h | 72 +++++++++ .../libvirt-gconfig-capabilities-guest-private.h | 39 +++++ .../libvirt-gconfig-capabilities-guest.c | 153 ++++++++++++++++++++ .../libvirt-gconfig-capabilities-guest.h | 74 ++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 52 +++++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 1 + libvirt-gconfig/libvirt-gconfig-private.h | 3 + libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 16 ++ 15 files changed, 800 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-domain.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-domain.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 9bd0df8..606df92 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -13,7 +13,10 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-guest.h \ + libvirt-gconfig-capabilities-domain.h \ libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-arch.h \ libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ @@ -72,14 +75,20 @@ noinst_HEADERS = \ libvirt-gconfig-object-private.h \ libvirt-gconfig-xml-doc.h \ libvirt-gconfig-capabilities-host-private.h \ + libvirt-gconfig-capabilities-guest-private.h \ libvirt-gconfig-capabilities-cpu-private.h \ - libvirt-gconfig-capabilities-cpu-feature-private.h + libvirt-gconfig-capabilities-cpu-arch-private.h \ + libvirt-gconfig-capabilities-cpu-feature-private.h \ + libvirt-gconfig-capabilities-domain-private.h GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-guest.c \ + libvirt-gconfig-capabilities-domain.c \ libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-arch.c \ libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h new file mode 100644 index 0000000..c864847 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch-private.h: libvirt CPU architecture capabilities + * + * Copyright (C) 2010-2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx> + * Daniel P. Berrange <berrange@xxxxxxxxxx> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_cpu_arch_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c new file mode 100644 index 0000000..e4d25d3 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c @@ -0,0 +1,135 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.c: libvirt CPU architecture capabilities + * + * Copyright (C) 2008 Daniel P. Berrange + * Copyright (C) 2010-2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx> + * Daniel P. Berrange <berrange@xxxxxxxxxx> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchPrivate)) + +struct _GVirConfigCapabilitiesCPUArchPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCPUArch, gvir_config_capabilities_cpu_arch, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_arch_class_init(GVirConfigCapabilitiesCPUArchClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCPUArchPrivate)); +} + +static void gvir_config_capabilities_cpu_arch_init(GVirConfigCapabilitiesCPUArch *conn) +{ + g_debug("Init GVirConfigCapabilitiesCPUArch=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_ARCH_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_cpu_arch_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_CPU_ARCH(object); +} + +const gchar * +gvir_config_capabilities_cpu_arch_get_name(GVirConfigCapabilitiesCPUArch *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_attribute_content(node, "name"); +} + +struct GetDomainData { + GVirConfigXmlDoc *doc; + GList *domains; +}; + +static gboolean add_domain(xmlNodePtr node, gpointer opaque) +{ + struct GetDomainData* data = (struct GetDomainData*)opaque; + GVirConfigCapabilitiesDomain *domain; + + if (g_strcmp0((const gchar *)node->name, "domain") != 0) + return TRUE; + + domain = gvir_config_capabilities_domain_new_from_tree(data->doc, node); + if (domain != NULL) + data->domains = g_list_append(data->domains, domain); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_arch_get_domains: + * + * Gets the possible domains for this architecture. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesDomain) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesDomain. + */ +GList * +gvir_config_capabilities_cpu_arch_get_domains(GVirConfigCapabilitiesCPUArch *caps) +{ + struct GetDomainData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.domains = NULL; + + gvir_config_xml_foreach_child(node, add_domain, &data); + + g_clear_object(&data.doc); + + return data.domains; +} + +const gchar * +gvir_config_capabilities_cpu_arch_get_emulator(GVirConfigCapabilitiesCPUArch *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_child_element_content(node, "emulator"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h new file mode 100644 index 0000000..5953ef9 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.h: libvirt CPU architecture capabilities + * + * Copyright (C) 2010-2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx> + * Daniel P. Berrange <berrange@xxxxxxxxxx> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH (gvir_config_capabilities_cpu_arch_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArch)) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH)) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchClass)) + +typedef struct _GVirConfigCapabilitiesCPUArch GVirConfigCapabilitiesCPUArch; +typedef struct _GVirConfigCapabilitiesCPUArchPrivate GVirConfigCapabilitiesCPUArchPrivate; +typedef struct _GVirConfigCapabilitiesCPUArchClass GVirConfigCapabilitiesCPUArchClass; + +struct _GVirConfigCapabilitiesCPUArch +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCPUArchPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCPUArchClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_arch_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_arch_get_name(GVirConfigCapabilitiesCPUArch *caps); +GList * +gvir_config_capabilities_cpu_arch_get_domains(GVirConfigCapabilitiesCPUArch *caps); +const gchar * +gvir_config_capabilities_cpu_arch_get_emulator(GVirConfigCapabilitiesCPUArch *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h new file mode 100644 index 0000000..a657e2e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-domain-private.h: libvirt CPU capabilities + * + * Copyright (C) 2010-2011 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx> + * Daniel P. Berrange <berrange@xxxxxxxxxx> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesDomain * +gvir_config_capabilities_domain_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c new file mode 100644 index 0000000..1023f9d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c @@ -0,0 +1,93 @@ +/* + * libvirt-gconfig-capabilities-domain.c: libvirt domain capabilities + * + * Copyright (C) 2008 Daniel P. Berrange + * Copyright (C) 2010-2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx> + * Daniel P. Berrange <berrange@xxxxxxxxxx> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_CAPABILITIES_DOMAIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainPrivate)) + +struct _GVirConfigCapabilitiesDomainPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesDomain, gvir_config_capabilities_domain, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_domain_class_init(GVirConfigCapabilitiesDomainClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesDomainPrivate)); +} + +static void gvir_config_capabilities_domain_init(GVirConfigCapabilitiesDomain *conn) +{ + g_debug("Init GVirConfigCapabilitiesDomain=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_DOMAIN_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesDomain * +gvir_config_capabilities_domain_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_DOMAIN(object); +} + +const gchar * +gvir_config_capabilities_domain_get_emulator(GVirConfigCapabilitiesDomain *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_child_element_content(node, "emulator"); +} + +GVirConfigDomainVirtType +gvir_config_capabilities_domain_get_virt_type(GVirConfigCapabilitiesDomain *caps) +{ + xmlNodePtr node; + const gchar *str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + str = gvir_config_xml_get_attribute_content(node, "type"); + if (str == NULL) + return GVIR_CONFIG_DOMAIN_VIRT_QEMU; + + return gvir_config_genum_get_value(GVIR_CONFIG_TYPE_DOMAIN_VIRT_TYPE, + str, + GVIR_CONFIG_DOMAIN_VIRT_QEMU); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h new file mode 100644 index 0000000..6c20191 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-domain.h: libvirt domain capabilities + * + * Copyright (C) 2010-2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx> + * Daniel P. Berrange <berrange@xxxxxxxxxx> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_H__ + +#include "libvirt-gconfig-domain.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN (gvir_config_capabilities_domain_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomain)) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN)) +#define GVIR_CONFIG_IS_CAPABILITIES_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN)) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainClass)) + +typedef struct _GVirConfigCapabilitiesDomain GVirConfigCapabilitiesDomain; +typedef struct _GVirConfigCapabilitiesDomainPrivate GVirConfigCapabilitiesDomainPrivate; +typedef struct _GVirConfigCapabilitiesDomainClass GVirConfigCapabilitiesDomainClass; + +struct _GVirConfigCapabilitiesDomain +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesDomainPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesDomainClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_domain_get_type(void); + +const gchar * +gvir_config_capabilities_domain_get_emulator(GVirConfigCapabilitiesDomain *caps); + +GVirConfigDomainVirtType +gvir_config_capabilities_domain_get_virt_type(GVirConfigCapabilitiesDomain *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h new file mode 100644 index 0000000..1092ad0 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-guest-private.h: libvirt guest capabilities + * + * Copyright (C) 2010-2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx> + * Daniel P. Berrange <berrange@xxxxxxxxxx> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesGuest * +gvir_config_capabilities_guest_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c new file mode 100644 index 0000000..8f42d4c --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c @@ -0,0 +1,153 @@ +/* + * libvirt-gconfig-capabilities-guest.c: libvirt guest capabilities + * + * Copyright (C) 2008 Daniel P. Berrange + * Copyright (C) 2010-2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx> + * Daniel P. Berrange <berrange@xxxxxxxxxx> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" + +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestPrivate)) + +struct _GVirConfigCapabilitiesGuestPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuest, gvir_config_capabilities_guest, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_class_init(GVirConfigCapabilitiesGuestClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestPrivate)); +} + +static void gvir_config_capabilities_guest_init(GVirConfigCapabilitiesGuest *conn) +{ + g_debug("Init GVirConfigCapabilitiesGuest=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesGuest * +gvir_config_capabilities_guest_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_GUEST(object); +} + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), -1); + + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(caps), + "os_type", + GVIR_CONFIG_TYPE_DOMAIN_OS_TYPE, + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); +} + +/** + * gvir_config_capabilities_guest_get_cpu_arch: + * + * Gets the CPU architecture capabilities of the guest. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCPUArch. + */ +GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_guest_get_cpu_arch(GVirConfigCapabilitiesGuest *caps) +{ + GVirConfigXmlDoc *doc; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &doc, NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + node = gvir_config_xml_get_element(node, "arch", NULL); + g_return_val_if_fail(node != NULL, NULL); + + return gvir_config_capabilities_cpu_arch_new_from_tree(doc, node); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigCapabilitiesCPUFeature *feature; + + feature = gvir_config_capabilities_cpu_feature_new_from_tree(data->doc, node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_get_cpu_features: + * + * Gets the CPU features for this guest. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCPUFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCPUFeature. + */ +GList * +gvir_config_capabilities_guest_get_cpu_features(GVirConfigCapabilitiesGuest *caps) +{ + struct GetFeatureData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + node = gvir_config_xml_get_element(node, "features", NULL); + if (node == NULL) + return NULL; + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.features = NULL; + + gvir_config_xml_foreach_child(node, add_feature, &data); + + g_clear_object(&data.doc); + + return data.features; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h new file mode 100644 index 0000000..c70177d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h @@ -0,0 +1,74 @@ +/* + * libvirt-gconfig-capabilities-guest.h: libvirt guest capabilities + * + * Copyright (C) 2010-2012 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx> + * Daniel P. Berrange <berrange@xxxxxxxxxx> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ + +#include "libvirt-gconfig-domain-os.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST (gvir_config_capabilities_guest_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuest)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) + +typedef struct _GVirConfigCapabilitiesGuest GVirConfigCapabilitiesGuest; +typedef struct _GVirConfigCapabilitiesGuestPrivate GVirConfigCapabilitiesGuestPrivate; +typedef struct _GVirConfigCapabilitiesGuestClass GVirConfigCapabilitiesGuestClass; + +struct _GVirConfigCapabilitiesGuest +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_get_type(void); + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps); + +GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_guest_get_cpu_arch(GVirConfigCapabilitiesGuest *caps); +GList * +gvir_config_capabilities_guest_get_cpu_features(GVirConfigCapabilitiesGuest *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 9518a30..5f38ac8 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -98,3 +98,55 @@ gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) return gvir_config_capabilities_host_new_from_tree(doc, node); } + +struct GetGuestData { + GVirConfigXmlDoc *doc; + GList *guests; +}; + +static gboolean add_guest(xmlNodePtr node, gpointer opaque) +{ + struct GetGuestData* data = (struct GetGuestData*)opaque; + GVirConfigCapabilitiesGuest *guest; + + if (g_strcmp0((const gchar *)node->name, "guest") != 0) + return TRUE; + + guest = gvir_config_capabilities_guest_new_from_tree(data->doc, node); + if (guest != NULL) + data->guests = g_list_append(data->guests, guest); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_get_guests: + * + * Gets the list of guest capabilities. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuest) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuest. + */ +GList * +gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps) +{ + struct GetGuestData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.guests = NULL; + + gvir_config_xml_foreach_child(node, add_guest, &data); + + if (data.doc != NULL) + g_object_unref(G_OBJECT(data.doc)); + + return data.guests; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 18edaf7..7e16099 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -63,6 +63,7 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); GVirConfigCapabilitiesHost * gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); +GList *gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-private.h b/libvirt-gconfig/libvirt-gconfig-private.h index 845a883..67fd4be 100644 --- a/libvirt-gconfig/libvirt-gconfig-private.h +++ b/libvirt-gconfig/libvirt-gconfig-private.h @@ -24,9 +24,12 @@ #define __LIBVIRT_GCONFIG_PRIVATE_H__ #include <libvirt-gconfig/libvirt-gconfig-domain-device-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h> #include <libvirt-gconfig/libvirt-gconfig-helpers-private.h> #include <libvirt-gconfig/libvirt-gconfig-object-private.h> #include <libvirt-gconfig/libvirt-gconfig-xml-doc.h> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index b2b7c15..32d286b 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -28,9 +28,12 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index b1df17b..51f6ce6 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -7,6 +7,7 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_new; gvir_config_capabilities_new_from_xml; gvir_config_capabilities_get_host; + gvir_config_capabilities_get_guests; gvir_config_capabilities_host_get_type; gvir_config_capabilities_host_new_from_tree; @@ -20,6 +21,21 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_cpu_feature_get_type; gvir_config_capabilities_cpu_feature_get_name; + gvir_config_capabilities_guest_get_type; + gvir_config_capabilities_guest_new_from_tree; + gvir_config_capabilities_guest_get_os_type; + gvir_config_capabilities_guest_get_cpu_arch; + gvir_config_capabilities_guest_get_cpu_features; + + gvir_config_capabilities_cpu_arch_get_type; + gvir_config_capabilities_cpu_arch_get_name; + gvir_config_capabilities_cpu_arch_get_domains; + gvir_config_capabilities_cpu_arch_get_emulator; + + gvir_config_capabilities_domain_get_type; + gvir_config_capabilities_domain_get_emulator; + gvir_config_capabilities_domain_get_virt_type; + gvir_config_domain_add_device; gvir_config_domain_get_type; gvir_config_domain_lifecycle_action_get_type; -- 1.7.7.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list