[gnome-boxes] express: Set hostname in guest based on its box's name



commit b2575a89169c608d6aaf4afc0455a911f54f4dde
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue May 22 20:22:09 2012 +0300

    express: Set hostname in guest based on its box's name
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676834

 data/fedora.ks                |    2 +-
 data/win2k3.sif               |    2 +-
 data/win2k8.xml               |    1 +
 data/win7.xml                 |    1 +
 data/winxp.sif                |    2 +-
 src/fedora-installer.vala     |    5 +++--
 src/unattended-installer.vala |   17 ++++++++++-------
 src/vm-creator.vala           |    4 ++--
 src/win7-installer.vala       |    4 ++--
 src/winxp-installer.vala      |    4 ++--
 10 files changed, 24 insertions(+), 18 deletions(-)
---
diff --git a/data/fedora.ks b/data/fedora.ks
index 3be53e4..f23b7bc 100644
--- a/data/fedora.ks
+++ b/data/fedora.ks
@@ -1,7 +1,7 @@
 install
 keyboard BOXES_FEDORA_KBD
 lang BOXES_LANG
-network --onboot yes --device eth0 --bootproto dhcp --noipv6 --activate
+network --onboot yes --device eth0 --bootproto dhcp --noipv6 --hostname=BOXES_HOSTNAME --activate
 rootpw BOXES_PASSWORD
 firewall --disabled
 authconfig --enableshadow --enablemd5
diff --git a/data/win2k3.sif b/data/win2k3.sif
index 25888e4..f57ba8b 100644
--- a/data/win2k3.sif
+++ b/data/win2k3.sif
@@ -24,7 +24,7 @@
     ProductKey=BOXES_PRODUCT_KEY
     FullName="BOXES_USERNAME"
     OrgName=""
-    ComputerName=BOXES_HOSTNAME
+    ComputerName="BOXES_HOSTNAME"
 
 [LicenseFilePrintData]
     AutoMode=PerServer
diff --git a/data/win2k8.xml b/data/win2k8.xml
index 89f27b7..ecba4cb 100644
--- a/data/win2k8.xml
+++ b/data/win2k8.xml
@@ -57,6 +57,7 @@
   </settings>
   <settings pass="oobeSystem">
     <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+      <ComputerName>BOXES_HOSTNAME</ComputerName>
       <UserAccounts>
 	<AdministratorPassword>
 	  <Value>BOXES_PASSWORD</Value>
diff --git a/data/win7.xml b/data/win7.xml
index 69a2595..361f57a 100644
--- a/data/win7.xml
+++ b/data/win7.xml
@@ -57,6 +57,7 @@
   </settings>
   <settings pass="oobeSystem">
     <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="BOXES_CPU" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+      <ComputerName>BOXES_HOSTNAME</ComputerName>
       <UserAccounts>
 	<AdministratorPassword>
 	  <Value>BOXES_PASSWORD</Value>
diff --git a/data/winxp.sif b/data/winxp.sif
index 25888e4..f57ba8b 100644
--- a/data/winxp.sif
+++ b/data/winxp.sif
@@ -24,7 +24,7 @@
     ProductKey=BOXES_PRODUCT_KEY
     FullName="BOXES_USERNAME"
     OrgName=""
-    ComputerName=BOXES_HOSTNAME
+    ComputerName="BOXES_HOSTNAME"
 
 [LicenseFilePrintData]
     AutoMode=PerServer
diff --git a/src/fedora-installer.vala b/src/fedora-installer.vala
index 952f389..083ba85 100644
--- a/src/fedora-installer.vala
+++ b/src/fedora-installer.vala
@@ -93,8 +93,9 @@ private class Boxes.FedoraInstaller: UnattendedInstaller {
         }
     }
 
-    protected override string fill_unattended_data (string data) throws RegexError {
-        var str = base.fill_unattended_data (data);
+    protected override string fill_unattended_data (string data, string hostname) throws RegexError {
+        var host = hostname.replace (" ", "-");
+        var str = base.fill_unattended_data (data, host);
 
         str = kbd_regex.replace (str, str.length, 0, kbd);
 
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index 57a761b..54081e7 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -50,6 +50,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
     private static Regex password_regex;
     private static Regex timezone_regex;
     private static Regex lang_regex;
+    private static Regex host_regex;
     private static Fdo.Accounts? accounts;
 
     static construct {
@@ -58,6 +59,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
             password_regex = new Regex ("BOXES_PASSWORD");
             timezone_regex = new Regex ("BOXES_TZ");
             lang_regex = new Regex ("BOXES_LANG");
+            host_regex = new Regex ("BOXES_HOSTNAME");
         } catch (RegexError error) {
             // This just can't fail
             assert_not_reached ();
@@ -102,7 +104,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         setup_ui ();
     }
 
-    public async void setup (Cancellable? cancellable) throws GLib.Error {
+    public async void setup (string hostname, Cancellable? cancellable) throws GLib.Error {
         if (!express_toggle.active) {
             debug ("Unattended installation disabled.");
 
@@ -116,7 +118,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
                 yield create_disk_image (cancellable);
 
             foreach (var unattended_file in unattended_files)
-                yield unattended_file.copy (cancellable);
+                yield unattended_file.copy (hostname, cancellable);
             yield prepare_direct_boot (cancellable);
         } catch (GLib.Error error) {
             clean_up ();
@@ -160,11 +162,12 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
                         (_("Password required for express installation of %s"), label);
     }
 
-    public virtual string fill_unattended_data (string data) throws RegexError {
+    public virtual string fill_unattended_data (string data, string hostname) throws RegexError {
         var str = username_regex.replace (data, data.length, 0, username_entry.text);
         str = password_regex.replace (str, str.length, 0, password);
         str = timezone_regex.replace (str, str.length, 0, timezone);
         str = lang_regex.replace (str, str.length, 0, lang);
+        str = host_regex.replace (str, str.length, 0, hostname);
 
         return str;
     }
@@ -314,8 +317,8 @@ private class Boxes.UnattendedFile {
        this.dest_name = dest_name;
     }
 
-    public async void copy (Cancellable? cancellable) throws GLib.Error {
-        var unattended_tmp = yield create (cancellable);
+    public async void copy (string hostname, Cancellable? cancellable) throws GLib.Error {
+        var unattended_tmp = yield create (hostname, cancellable);
 
         debug ("Copying unattended file '%s' into disk drive/image '%s'", dest_name, installer.disk_path);
         // FIXME: Perhaps we should use libarchive for this?
@@ -330,7 +333,7 @@ private class Boxes.UnattendedFile {
         debug ("Deleted temporary file '%s'", unattended_tmp.get_path ());
     }
 
-    private async File create (Cancellable? cancellable)  throws GLib.Error {
+    private async File create (string hostname, Cancellable? cancellable)  throws GLib.Error {
         var source = File.new_for_path (src_path);
         var destination_path = get_user_unattended (dest_name);
         var destination = File.new_for_path (destination_path);
@@ -346,7 +349,7 @@ private class Boxes.UnattendedFile {
         data_stream.newline_type = DataStreamNewlineType.ANY;
         string? str;
         while ((str = yield data_stream.read_line_async (Priority.DEFAULT, cancellable)) != null) {
-            str = installer.fill_unattended_data (str);
+            str = installer.fill_unattended_data (str, hostname);
 
             str += (installer.newline_type == DataStreamNewlineType.LF) ? "\n" : "\r\n";
 
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index f3666a0..cd6e6a6 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -43,15 +43,15 @@ private class Boxes.VMCreator {
     }
 
     public async void create_and_launch_vm (InstallerMedia install_media, Cancellable? cancellable) throws GLib.Error {
+        var name = yield create_domain_name_from_media (install_media);
         var fullscreen = true;
         if (install_media is UnattendedInstaller) {
             var unattended = install_media as UnattendedInstaller;
 
-            yield unattended.setup (cancellable);
+            yield unattended.setup (name, cancellable);
             fullscreen = !unattended.express_install;
         }
 
-        var name = yield create_domain_name_from_media (install_media);
         var volume = yield create_target_volume (name, install_media.resources.storage);
         var config = configurator.create_domain_config (install_media, name, volume.get_path ());
 
diff --git a/src/win7-installer.vala b/src/win7-installer.vala
index aa79619..f4c5157 100644
--- a/src/win7-installer.vala
+++ b/src/win7-installer.vala
@@ -14,8 +14,8 @@ private class Boxes.Win7Installer: WindowsInstaller {
         }
     }
 
-    protected override string fill_unattended_data (string data) throws RegexError {
-        var str = base.fill_unattended_data (data);
+    protected override string fill_unattended_data (string data, string hostname) throws RegexError {
+        var str = base.fill_unattended_data (data, hostname);
 
         switch (os_media.architecture) {
             case "x86_64":
diff --git a/src/winxp-installer.vala b/src/winxp-installer.vala
index a71a374..2d1a29d 100644
--- a/src/winxp-installer.vala
+++ b/src/winxp-installer.vala
@@ -71,8 +71,8 @@ private class Boxes.WinXPInstaller: WindowsInstaller {
         key_inserted_id = key_entry.insert_text.connect (on_key_text_inserted);
     }
 
-    protected override string fill_unattended_data (string data) throws RegexError {
-        var str = base.fill_unattended_data (data);
+    protected override string fill_unattended_data (string data, string hostname) throws RegexError {
+        var str = base.fill_unattended_data (data, hostname);
 
         return key_regex.replace (str, str.length, 0, key_entry.text);
     }



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