[gnome-boxes] vm-configurator: Refactor custom XML setting code



commit db72eb48f24b9126def9d5d725c2f9fd1a6fff13
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Nov 20 21:56:11 2012 +0200

    vm-configurator: Refactor custom XML setting code
    
    Refactor custom XML creation and setting into one function.
    
    This also makes the OS and media info in the domain config, permanent.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688770

 src/vm-configurator.vala |   41 ++++++++++++++++++++++++-----------------
 src/vm-creator.vala      |    2 +-
 2 files changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index 137d4a4..ee17298 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -25,16 +25,7 @@ private class Boxes.VMConfigurator {
                                         throws VMConfiguratorError {
         var domain = new Domain ();
 
-        var custom_xml = (install_media.live) ? LIVE_XML : INSTALLATION_XML;
-        if (install_media.os != null)
-            custom_xml += Markup.printf_escaped (OS_ID_XML, install_media.os.id);
-        if (install_media.os_media != null)
-            custom_xml += Markup.printf_escaped (MEDIA_ID_XML, install_media.os_media.id);
-
-        custom_xml = BOXES_XML.printf (custom_xml);
-        try {
-            domain.set_custom_xml (custom_xml, BOXES_NS, BOXES_NS_URI);
-        } catch (GLib.Error error) { assert_not_reached (); /* We are so screwed if this happens */ }
+        update_custom_xml (domain, install_media);
 
         var best_caps = get_best_guest_caps (caps, install_media);
         domain.memory = install_media.resources.ram / KIBIBYTES;
@@ -110,7 +101,7 @@ private class Boxes.VMConfigurator {
         return domain;
     }
 
-    public static void post_install_setup (Domain domain) {
+    public static void post_install_setup (Domain domain, InstallerMedia install_media) {
         set_post_install_os_config (domain);
         domain.set_lifecycle (DomainLifecycleEvent.ON_REBOOT, DomainLifecycleAction.RESTART);
 
@@ -130,7 +121,7 @@ private class Boxes.VMConfigurator {
 
         domain.set_devices (devices);
 
-        mark_as_installed (domain);
+        mark_as_installed (domain, install_media);
     }
 
     public static bool is_install_config (Domain domain) {
@@ -183,11 +174,8 @@ private class Boxes.VMConfigurator {
         return get_custom_xml_node (domain, "media-id");
     }
 
-    private static void mark_as_installed (Domain domain) {
-        try {
-            var custom_xml = BOXES_XML.printf (INSTALLED_XML);
-            domain.set_custom_xml (custom_xml, BOXES_NS, BOXES_NS_URI);
-        } catch (GLib.Error error) { assert_not_reached (); /* We are so screwed if this happens */ }
+    private static void mark_as_installed (Domain domain, InstallerMedia install_media) {
+        update_custom_xml (domain, install_media, true);
     }
 
     private static void set_cpu_config (Domain domain, Capabilities caps) {
@@ -347,6 +335,25 @@ private class Boxes.VMConfigurator {
         return null;
     }
 
+    private static void update_custom_xml (Domain domain, InstallerMedia install_media, bool installed = false) {
+        string custom_xml;
+
+        if (installed)
+            custom_xml = INSTALLED_XML;
+        else
+            custom_xml = (install_media.live) ? LIVE_XML : INSTALLATION_XML;
+
+        if (install_media.os != null)
+            custom_xml += Markup.printf_escaped (OS_ID_XML, install_media.os.id);
+        if (install_media.os_media != null)
+            custom_xml += Markup.printf_escaped (MEDIA_ID_XML, install_media.os_media.id);
+
+        custom_xml = BOXES_XML.printf (custom_xml);
+        try {
+            domain.set_custom_xml (custom_xml, BOXES_NS, BOXES_NS_URI);
+        } catch (GLib.Error error) { assert_not_reached (); /* We are so screwed if this happens */ }
+    }
+
     public static void add_usb_support (Domain domain) {
         // 4 USB redirection channels
         for (int i = 0; i < 4; i++) {
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index 69d40d8..e056767 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -159,7 +159,7 @@ private class Boxes.VMCreator {
         debug ("Setting post-installation configuration on '%s'", machine.name);
         try {
             var config = machine.domain.get_config (GVir.DomainXMLFlags.INACTIVE);
-            VMConfigurator.post_install_setup (config);
+            VMConfigurator.post_install_setup (config, install_media);
             machine.domain.set_config (config);
         } catch (GLib.Error error) {
             warning ("Failed to set post-install configuration on '%s': %s", machine.name, error.message);



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