--
v2: merged several related commits
use safer g_strcmp0 for string comparison
use g_return_if_fail to test function args for sanity
---
libvirt-gconfig/libvirt-gconfig-domain-os.c | 142 +++++++++++++++++++++++++++
libvirt-gconfig/libvirt-gconfig-domain-os.h | 27 +++++
libvirt-gconfig/libvirt-gconfig.sym | 10 ++
3 files changed, 179 insertions(+), 0 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-os.c
b/libvirt-gconfig/libvirt-gconfig-domain-os.c
index 7c8bfbb..412ed41 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-os.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-os.c
@@ -27,6 +27,8 @@
#include <libxml/tree.h>
#include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h"
+#include "libvirt-gconfig/libvirt-gconfig-object-private.h"
extern gboolean debugFlag;
@@ -77,3 +79,143 @@ GVirConfigDomainOs *gvir_config_domain_os_new_from_xml(const gchar
*xml, GError
NULL, xml, error);
return GVIR_CONFIG_DOMAIN_OS(object);
}
+
+void gvir_config_domain_os_set_os_type(GVirConfigDomainOs *os,
+ GVirConfigDomainOsType type)
+{
+ xmlNodePtr node;
+ const char *type_str;
+
+ g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os));
+
+ node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(os), "type");
+ g_return_if_fail(node != NULL);
+ type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_OS_TYPE, type);
+ g_return_if_fail(type_str != NULL);
+ xmlNodeSetContent(node, (xmlChar*)type_str);
+}
+
+void gvir_config_domain_os_set_loader(GVirConfigDomainOs *os,
+ const char * loader)
+{
+ gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(os),
+ "loader", loader);
+}
+
+void gvir_config_domain_os_enable_boot_menu(GVirConfigDomainOs *os,
+ gboolean enable)
+{
+ xmlNodePtr node;
+
+ g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os));
+
+ node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(os),
"bootmenu");
+ g_return_if_fail(node != NULL);
+ if (enable)
+ xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"yes");
+ else
+ xmlNewProp(node, (xmlChar*)"enable", (xmlChar*)"no");
+}
+
+void gvir_config_domain_os_bios_enable_serial(GVirConfigDomainOs *os,
+ gboolean enable)
+{
+ xmlNodePtr node;
+
+ g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os));
+
+ node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(os), "bios");
+ g_return_if_fail(node != NULL);
+ if (enable)
+ xmlNewProp(node, (xmlChar*)"useserial", (xmlChar*)"yes");
+ else
+ xmlNewProp(node, (xmlChar*)"useserial", (xmlChar*)"no");
+}
+
+void gvir_config_domain_os_set_smbios_mode(GVirConfigDomainOs *os,
+ GVirConfigDomainOsSmBiosMode mode)
+{
+ xmlNodePtr node;
+ const char *mode_str;
+
+ g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os));
+
+ node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(os), "smbios");
+ g_return_if_fail(node != NULL);
+ mode_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_OS_SM_BIOS_MODE,
+ mode);
+ if (mode_str != NULL)
+ xmlNewProp(node, (xmlChar*)"mode", (xmlChar*)mode_str);
+}
+
+/**
+ * gvir_config_domain_os_set_boot_devices:
+ * @boot_devices: (in) (element-type LibvirtGConfig.DomainOsBootDevice):
+ */
+void gvir_config_domain_os_set_boot_devices(GVirConfigDomainOs *os, GList *boot_devices)
+{
+ GList *it;
+ xmlNodePtr os_node;
+ xmlNodePtr node;
+
+ g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os));
+
+ os_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os));
+ g_return_if_fail(os_node != NULL);
+
+ node = os_node->children;
+ while (node != NULL) {
+ xmlNodePtr next_node;
+ next_node = node->next;
+ if (g_strcmp0("boot", (char *)node->name) == 0) {
+ xmlUnlinkNode(node);
+ xmlFreeNode(node);
+ }
+ node = next_node;
+ }
+
+ for (it = boot_devices; it != NULL; it = it->next) {
+ const char *dev;
+
+ dev = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_OS_BOOT_DEVICE,
+ GPOINTER_TO_INT(it->data));
+ g_warn_if_fail(dev != NULL);
+ if (dev != NULL) {
+ node = xmlNewDocNode(NULL, NULL, (xmlChar*)"boot", NULL);
+ xmlNewProp(node, (xmlChar*)"dev", (xmlChar*)dev);
+ xmlAddChild(os_node, node);
+ }
+ }
+}
+
+void gvir_config_domain_os_set_arch(GVirConfigDomainOs *os, const char *arch)
+{
+ xmlNodePtr os_node;
+ xmlNodePtr os_type_node;
+
+ g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os));
+
+ os_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os));
+ g_return_if_fail(os_node != NULL);
+
+ os_type_node = gvir_config_xml_get_element(os_node, "type", NULL);
+ g_return_if_fail(os_type_node != NULL);
+
+ xmlNewProp(os_type_node, (xmlChar*)"arch", (xmlChar*)arch);
+}
+
+void gvir_config_domain_os_set_machine(GVirConfigDomainOs *os, const char *machine)
+{
+ xmlNodePtr os_node;
+ xmlNodePtr os_type_node;
+
+ g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_OS(os));
+
+ os_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(os));
+ g_return_if_fail(os_node != NULL);
+
+ os_type_node = gvir_config_xml_get_element(os_node, "type", NULL);
+ g_return_if_fail(os_type_node != NULL);
+
+ xmlNewProp(os_type_node, (xmlChar*)"machine", (xmlChar*)machine);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-os.h
b/libvirt-gconfig/libvirt-gconfig-domain-os.h
index 8d5d6a9..1522744 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-os.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-os.h
@@ -56,12 +56,39 @@ struct _GVirConfigDomainOsClass
gpointer padding[20];
};
+typedef enum {
+ GVIR_CONFIG_DOMAIN_OS_TYPE_HVM,
+ GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX
+} GVirConfigDomainOsType;
+
+typedef enum {
+ GVIR_CONFIG_DOMAIN_OS_SMBIOS_MODE_EMULATE,
+ GVIR_CONFIG_DOMAIN_OS_SMBIOS_MODE_HOST,
+ GVIR_CONFIG_DOMAIN_OS_SMBIOS_MODE_SYSINFO
+} GVirConfigDomainOsSmBiosMode;
+
+typedef enum {
+ GVIR_CONFIG_DOMAIN_OS_BOOT_DEVICE_FD,
+ GVIR_CONFIG_DOMAIN_OS_BOOT_DEVICE_HD,
+ GVIR_CONFIG_DOMAIN_OS_BOOT_DEVICE_CDROM,
+ GVIR_CONFIG_DOMAIN_OS_BOOT_DEVICE_NETWORK
+} GVirConfigDomainOsBootDevice;
GType gvir_config_domain_os_get_type(void);
GVirConfigDomainOs *gvir_config_domain_os_new(void);
GVirConfigDomainOs *gvir_config_domain_os_new_from_xml(const gchar *xml, GError
**error);
+void gvir_config_domain_os_set_os_type(GVirConfigDomainOs *os, GVirConfigDomainOsType
type);
+void gvir_config_domain_os_set_arch(GVirConfigDomainOs *os, const char *arch);
+void gvir_config_domain_os_set_boot_devices(GVirConfigDomainOs *os, GList
*boot_devices);
+void gvir_config_domain_os_set_loader(GVirConfigDomainOs *os, const char * loader);
+void gvir_config_domain_os_set_machine(GVirConfigDomainOs *os, const char *machine);
+void gvir_config_domain_os_set_smbios_mode(GVirConfigDomainOs *os,
+ GVirConfigDomainOsSmBiosMode mode);
+void gvir_config_domain_os_enable_boot_menu(GVirConfigDomainOs *os, gboolean enable);
+void gvir_config_domain_os_bios_enable_serial(GVirConfigDomainOs *os, gboolean enable);
+
G_END_DECLS
#endif /* __LIBVIRT_GCONFIG_DOMAIN_OS_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index ed04457..83e4e0c 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -24,8 +24,18 @@ LIBVIRT_GOBJECT_0.0.1 {
gvir_config_domain_clock_set_variable_offset;
gvir_config_domain_os_get_type;
+ gvir_config_domain_os_boot_device_get_type;
+ gvir_config_domain_os_sm_bios_mode_get_type;
gvir_config_domain_os_new;
gvir_config_domain_os_new_from_xml;
+ gvir_config_domain_os_set_os_type;
+ gvir_config_domain_os_set_boot_devices;
+ gvir_config_domain_os_set_loader;
+ gvir_config_domain_os_set_smbios_mode;
+ gvir_config_domain_os_enable_boot_menu;
+ gvir_config_domain_os_bios_enable_serial;
+ gvir_config_domain_os_set_machine;
+ gvir_config_domain_os_set_arch;
gvir_config_domain_snapshot_get_type;
gvir_config_domain_snapshot_new;
--
1.7.7.3