[libvirt-gconfig PATCHv2 14/32] Add some GVirConfigOs setters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



--
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-os.c |  138 ++++++++++++++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-os.h |   27 +++++++
 libvirt-gconfig/libvirt-gconfig.sym  |   11 +++
 3 files changed, 176 insertions(+), 0 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-os.c b/libvirt-gconfig/libvirt-gconfig-os.c
index c09e32a..b430eb6 100644
--- a/libvirt-gconfig/libvirt-gconfig-os.c
+++ b/libvirt-gconfig/libvirt-gconfig-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,139 @@ GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error)
                                              NULL, xml, error);
     return GVIR_CONFIG_OS(object);
 }
+
+void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type)
+{
+    xmlNodePtr node;
+    const char *type_str;
+
+    g_return_if_fail(GVIR_IS_CONFIG_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_OS_TYPE, type);
+    g_return_if_fail(type_str != NULL);
+    xmlNodeSetContent(node, (xmlChar*)type_str);
+}
+
+void gvir_config_os_set_loader(GVirConfigOs *os, const char * loader)
+{
+    gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(os),
+                                        "loader", loader);
+}
+
+void gvir_config_os_enable_boot_menu(GVirConfigOs *os, gboolean enable)
+{
+    xmlNodePtr node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_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_os_bios_enable_serial(GVirConfigOs *os, gboolean enable)
+{
+    xmlNodePtr node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_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_os_set_smbios_mode(GVirConfigOs *os,
+                                    GVirConfigOsSmBiosMode mode)
+{
+    xmlNodePtr node;
+    const char *mode_str;
+
+    g_return_if_fail(GVIR_IS_CONFIG_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_OS_SM_BIOS_MODE,
+                                          mode);
+    if (mode_str != NULL)
+        xmlNewProp(node, (xmlChar*)"mode", (xmlChar*)mode_str);
+}
+
+/**
+ * gvir_config_os_set_boot_devices:
+ * @boot_devices: (in) (element-type LibvirtGConfig.OsBootDevice):
+ */
+void gvir_config_os_set_boot_devices(GVirConfigOs *os, GList *boot_devices)
+{
+    GList *it;
+    xmlNodePtr os_node;
+    xmlNodePtr node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_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_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_os_set_arch(GVirConfigOs *os, const char *arch)
+{
+    xmlNodePtr os_node;
+    xmlNodePtr os_type_node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_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_os_set_machine(GVirConfigOs *os, const char *machine)
+{
+    xmlNodePtr os_node;
+    xmlNodePtr os_type_node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_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-os.h b/libvirt-gconfig/libvirt-gconfig-os.h
index 716f588..b789eb3 100644
--- a/libvirt-gconfig/libvirt-gconfig-os.h
+++ b/libvirt-gconfig/libvirt-gconfig-os.h
@@ -56,12 +56,39 @@ struct _GVirConfigOsClass
     gpointer padding[20];
 };
 
+typedef enum {
+    GVIR_CONFIG_OS_TYPE_HVM,
+    GVIR_CONFIG_OS_TYPE_LINUX
+} GVirConfigOsType;
+
+typedef enum {
+    GVIR_CONFIG_OS_SMBIOS_MODE_EMULATE,
+    GVIR_CONFIG_OS_SMBIOS_MODE_HOST,
+    GVIR_CONFIG_OS_SMBIOS_MODE_SYSINFO
+} GVirConfigOsSmBiosMode;
+
+typedef enum {
+    GVIR_CONFIG_OS_BOOT_DEVICE_FD,
+    GVIR_CONFIG_OS_BOOT_DEVICE_HD,
+    GVIR_CONFIG_OS_BOOT_DEVICE_CDROM,
+    GVIR_CONFIG_OS_BOOT_DEVICE_NETWORK
+} GVirConfigOsBootDevice;
 
 GType gvir_config_os_get_type(void);
 
 GVirConfigOs *gvir_config_os_new(void);
 GVirConfigOs *gvir_config_os_new_from_xml(const gchar *xml, GError **error);
 
+void gvir_config_os_set_os_type(GVirConfigOs *os, GVirConfigOsType type);
+void gvir_config_os_set_arch(GVirConfigOs *os, const char *arch);
+void gvir_config_os_set_boot_devices(GVirConfigOs *os, GList *boot_devices);
+void gvir_config_os_set_loader(GVirConfigOs *os, const char * loader);
+void gvir_config_os_set_machine(GVirConfigOs *os, const char *machine);
+void gvir_config_os_set_smbios_mode(GVirConfigOs *os,
+                                    GVirConfigOsSmBiosMode mode);
+void gvir_config_os_enable_boot_menu(GVirConfigOs *os, gboolean enable);
+void gvir_config_os_bios_enable_serial(GVirConfigOs *os, gboolean enable);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GCONFIG_OS_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 138b80f..1a924c1 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -51,8 +51,19 @@ LIBVIRT_GOBJECT_0.0.1 {
 	gvir_config_object_validate;
 
 	gvir_config_os_get_type;
+	gvir_config_os_boot_device_get_type;
+	gvir_config_os_sm_bios_mode_get_type;
+	gvir_config_os_type_get_type;
 	gvir_config_os_new;
 	gvir_config_os_new_from_xml;
+	gvir_config_os_set_os_type;
+	gvir_config_os_set_boot_devices;
+	gvir_config_os_set_loader;
+	gvir_config_os_set_smbios_mode;
+	gvir_config_os_enable_boot_menu;
+	gvir_config_os_bios_enable_serial;
+	gvir_config_os_set_machine;
+	gvir_config_os_set_arch;
 
 	gvir_config_secret_get_type;
 	gvir_config_secret_new;
-- 
1.7.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]