[gnome-boxes] Basic support for creating a VM



commit 20e2362755f733c27d8fab233c8f9c8f704b5598
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Oct 31 20:20:01 2011 +0200

    Basic support for creating a VM
    
    In the wizard if you now give a URI to an installer ISO, a VM is
    created. A view is automatically created for it. Some issues:
    
    * ISO URI is assume to be local (file:///). When its not local, perhaps
      we should download it before using it?
    * Currently, only the OS is reported to user.
    * In case of automated install, nothing is personalized. We should be
      collecting sane default for the user and giving a chance to user to
      edit the basic stuff like admin password etc.

 src/Makefile.am                       |    7 +++
 src/fedora-installer-symlink.vala     |    1 +
 src/installer-media-symlink.vala      |    1 +
 src/os-database-symlink.vala          |    1 +
 src/unattended-installer-symlink.vala |    1 +
 src/vm-creator-symlink.vala           |    1 +
 src/win7-installer-symlink.vala       |    1 +
 src/winxp-installer-symlink.vala      |    1 +
 src/wizard.vala                       |   71 ++++++++++++++++++++++++++++++--
 9 files changed, 80 insertions(+), 5 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2696e83..687a127 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -49,6 +49,13 @@ gnome_boxes_SOURCES =				\
 	vnc-display.vala			\
 	wizard-source.vala			\
 	wizard.vala				\
+	installer-media-symlink.vala 		\
+	unattended-installer-symlink.vala 	\
+	fedora-installer-symlink.vala 		\
+	win7-installer-symlink.vala 		\
+	winxp-installer-symlink.vala 		\
+	os-database-symlink.vala 		\
+	vm-creator-symlink.vala 		\
 	$(NULL)
 
 gnome_boxes_installer_SOURCES = 		\
diff --git a/src/fedora-installer-symlink.vala b/src/fedora-installer-symlink.vala
new file mode 120000
index 0000000..30d28d1
--- /dev/null
+++ b/src/fedora-installer-symlink.vala
@@ -0,0 +1 @@
+fedora-installer.vala
\ No newline at end of file
diff --git a/src/installer-media-symlink.vala b/src/installer-media-symlink.vala
new file mode 120000
index 0000000..38a48e7
--- /dev/null
+++ b/src/installer-media-symlink.vala
@@ -0,0 +1 @@
+installer-media.vala
\ No newline at end of file
diff --git a/src/os-database-symlink.vala b/src/os-database-symlink.vala
new file mode 120000
index 0000000..a0cc1c3
--- /dev/null
+++ b/src/os-database-symlink.vala
@@ -0,0 +1 @@
+os-database.vala
\ No newline at end of file
diff --git a/src/unattended-installer-symlink.vala b/src/unattended-installer-symlink.vala
new file mode 120000
index 0000000..b3bcd7c
--- /dev/null
+++ b/src/unattended-installer-symlink.vala
@@ -0,0 +1 @@
+unattended-installer.vala
\ No newline at end of file
diff --git a/src/vm-creator-symlink.vala b/src/vm-creator-symlink.vala
new file mode 120000
index 0000000..298cbcf
--- /dev/null
+++ b/src/vm-creator-symlink.vala
@@ -0,0 +1 @@
+vm-creator.vala
\ No newline at end of file
diff --git a/src/win7-installer-symlink.vala b/src/win7-installer-symlink.vala
new file mode 120000
index 0000000..4a985bc
--- /dev/null
+++ b/src/win7-installer-symlink.vala
@@ -0,0 +1 @@
+win7-installer.vala
\ No newline at end of file
diff --git a/src/winxp-installer-symlink.vala b/src/winxp-installer-symlink.vala
new file mode 120000
index 0000000..8c9b2f4
--- /dev/null
+++ b/src/winxp-installer-symlink.vala
@@ -0,0 +1 @@
+winxp-installer.vala
\ No newline at end of file
diff --git a/src/wizard.vala b/src/wizard.vala
index 53c168e..d48b728 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -23,6 +23,13 @@ private class Boxes.Wizard: Boxes.UI {
     private WizardSummary summary;
     private CollectionSource? source;
 
+    private OSDatabase os_db;
+    private VMCreator vm_creator;
+    private GUdev.Client client;
+
+    private InstallerMedia? install_media;
+    private Osinfo.Resources? resources;
+
     private WizardPage _page;
     private WizardPage page {
         get { return _page; }
@@ -30,7 +37,7 @@ private class Boxes.Wizard: Boxes.UI {
             if (value == WizardPage.REVIEW) {
                 try {
                     prepare ();
-                } catch (Boxes.Error error) {
+                } catch (GLib.Error error) {
                     warning ("Fixme: %s".printf (error.message));
                     return;
                 }
@@ -74,21 +81,48 @@ private class Boxes.Wizard: Boxes.UI {
     }
 
     private bool create () {
-        if (source == null)
-            return false;
+        if (source == null) {
+            if (install_media == null)
+                return false;
+
+            next_button.sensitive = false;
+            vm_creator.create_domain_for_installer.begin (install_media, resources, null, on_domain_created);
+            install_media = null;
+            resources = null;
+
+            return true;
+        }
 
         source.save ();
         app.add_collection_source (source);
         return true;
     }
 
-    private void prepare_for_location (string location) throws Boxes.Error {
+    private void on_domain_created (Object? source_object, AsyncResult result) {
+        try {
+            var domain = vm_creator.create_domain_for_installer.end (result);
+            domain.start (0);
+        } catch (IOError.CANCELLED cancel_error) { // We did this, so ignore!
+        } catch (GLib.Error error) {
+            warning ("Fixme: %s".printf (error.message));
+
+            return;
+        }
+
+        // Only let the user through if either domain was successfully created or operation was cancelled
+        next_button.sensitive = true;
+    }
+
+    private void prepare_for_location (string location) throws GLib.Error {
         bool uncertain;
 
         var mimetype = ContentType.guess (location, null, out uncertain);
 
         if (uncertain)
             prepare_for_uri (location);
+        else if (ContentType.is_a (mimetype, "application/x-cd-image"))
+            // FIXME: We are assuming that its local URI
+            prepare_for_installer (location);
         else
             debug ("FIXME: %s".printf (mimetype));
     }
@@ -127,7 +161,34 @@ private class Boxes.Wizard: Boxes.UI {
         }
     }
 
-    private void prepare () throws Boxes.Error {
+    private void prepare_for_installer (string location) throws GLib.Error {
+        if (client == null) {
+            client = new GUdev.Client ({"block"});
+            os_db = new OSDatabase ();
+            vm_creator = new VMCreator ("qemu:///session"); // FIXME
+        }
+
+        next_button.sensitive = false;
+        var file = File.new_for_uri (location);
+        // FIXME: Assuming location is a local URI
+        InstallerMedia.instantiate.begin (file.get_path (), os_db, client, null, on_installer_media_instantiated);
+    }
+
+    private void on_installer_media_instantiated (Object? source_object, AsyncResult result) {
+        next_button.sensitive = true;
+
+        try {
+            install_media = InstallerMedia.instantiate.end (result);
+            resources = os_db.get_resources_for_os (install_media.os);
+
+            summary.add_property (_("System"), install_media.label);
+        } catch (IOError.CANCELLED cancel_error) { // We did this, so no warning!
+        } catch (GLib.Error error) {
+            warning ("Fixme: %s".printf (error.message));
+        }
+    }
+
+    private void prepare () throws GLib.Error {
         summary.clear ();
 
         if (this.wizard_source.page == Boxes.SourcePage.URL ||



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