[virt-tools-list] [libosinfo 3/4] Don't assume target disk

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Sun Nov 11 19:14:57 UTC 2012


From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>

Instead of hardcoding target disk, lets get this info from application.
---
 data/install-scripts/fedora.xml           | 31 +++++++-----------------
 data/install-scripts/windows-cmd.xml      |  3 ++-
 data/install-scripts/windows-unattend.xml | 10 ++++----
 osinfo/libosinfo.syms                     |  3 +++
 osinfo/osinfo_install_config.c            | 40 ++++++++++++++++++++++++++-----
 osinfo/osinfo_install_config.h            |  7 +++++-
 6 files changed, 59 insertions(+), 35 deletions(-)

diff --git a/data/install-scripts/fedora.xml b/data/install-scripts/fedora.xml
index 2a9680d..ca53afa 100644
--- a/data/install-scripts/fedora.xml
+++ b/data/install-scripts/fedora.xml
@@ -7,6 +7,7 @@
       <param name="l10n-keyboard" policy="optional"/>
       <param name="l10n-language" policy="optional"/>
       <param name="l10n-timezone" policy="optional"/>
+      <param name="target-disk" policy="required"/>
     </config>
     <template filename="fedora.ks">
       <xsl:stylesheet
@@ -15,23 +16,6 @@
 
         <xsl:output method="text"/>
 
-	<xsl:template name="disk">
-	  <xsl:choose>
-	    <xsl:when test="os/version > 9">
-	      <!-- virtio -->
-	      <xsl:text>vda</xsl:text>
-	    </xsl:when>
-	    <xsl:when test="os/version > 6">
-	      <!-- libata IDE -->
-	      <xsl:text>sda</xsl:text>
-	    </xsl:when>
-	    <xsl:otherwise>
-	      <!-- IDE -->
-	      <xsl:text>hda</xsl:text>
-	    </xsl:otherwise>
-	  </xsl:choose>
-	</xsl:template>
-
 	<xsl:template name="rootfs">
 	  <xsl:choose>
 	    <xsl:when test="os/version > 10">
@@ -76,13 +60,13 @@ timezone --utc <xsl:value-of select="config/l10n-timezone"/>
 bootloader --location=mbr
 zerombr <xsl:if test="os/version < 14">yes</xsl:if>
 
-clearpart --all --drives=<xsl:call-template name="disk"/>
+clearpart --all --drives=<xsl:value-of select="config/target-disk"/>
 
 <xsl:if test="os/version > 15">
 part biosboot --fstype=biosboot --size=1
 </xsl:if>
-part /boot --fstype <xsl:call-template name="bootfs"/> --size=200 --ondisk=<xsl:call-template name="disk"/>
-part pv.2 --size=1 --grow --ondisk=<xsl:call-template name="disk"/>
+part /boot --fstype <xsl:call-template name="bootfs"/> --size=200 --ondisk=<xsl:value-of select="config/target-disk"/>
+part pv.2 --size=1 --grow --ondisk=<xsl:value-of select="config/target-disk"/>
 volgroup VolGroup00 --pesize=32768 pv.2
 logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=768 --grow --maxsize=1536
 logvol / --fstype <xsl:call-template name="rootfs"/> --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
@@ -114,6 +98,7 @@ reboot
         <param name="admin-password" policy="required"/>
         <param name="avatar-location" policy="optional"/>
         <param name="avatar-disk" policy="optional"/>
+        <param name="target-disk" policy="required"/>
     </config>
     <template filename="fedora.ks">
       <xsl:stylesheet
@@ -174,13 +159,13 @@ timezone --utc <xsl:value-of select="config/l10n-timezone"/>
 bootloader --location=mbr
 zerombr
 
-clearpart --all --drives=<xsl:call-template name="disk"/>
+clearpart --all --drives=<xsl:value-of select="config/target-disk"/>
 
 firstboot --disable
 
 part biosboot --fstype=biosboot --size=1
-part /boot --fstype <xsl:call-template name="bootfs"/> --recommended --ondisk=<xsl:call-template name="disk"/>
-part pv.2 --size=1 --grow --ondisk=<xsl:call-template name="disk"/>
+part /boot --fstype <xsl:call-template name="bootfs"/> --recommended --ondisk=<xsl:value-of select="config/target-disk"/>
+part pv.2 --size=1 --grow --ondisk=<xsl:value-of select="config/target-disk"/>
 volgroup VolGroup00 --pesize=32768 pv.2
 logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=768 --grow --maxsize=1536
 logvol / --fstype <xsl:call-template name="rootfs"/> --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
diff --git a/data/install-scripts/windows-cmd.xml b/data/install-scripts/windows-cmd.xml
index 682f198..f376b6f 100644
--- a/data/install-scripts/windows-cmd.xml
+++ b/data/install-scripts/windows-cmd.xml
@@ -7,6 +7,7 @@
       <param name="user-realname" policy="required"/>
       <param name="avatar-location" policy="optional"/>
       <param name="avatar-disk" policy="optional"/>
+      <param name="target-disk" policy="required"/>
     </config>
     <template filename="windows.cmd" path-format="dos">
       <xsl:stylesheet
@@ -19,7 +20,7 @@ sc config TlntSvr start= auto
 net user <xsl:value-of select="config/user-realname"/> <xsl:text> </xsl:text> <xsl:value-of select="config/admin-password"/> /add /passwordreq:no
 net localgroup administrators <xsl:value-of select="config/user-realname"/> /add
 net accounts /maxpwage:unlimited
-if not "<xsl:value-of select="config/avatar-location"/>"=="" copy "<xsl:value-of select="config/avatar-disk"/>:\<xsl:value-of select="config/avatar-location"/>" "c:\Documents and Settings\All Users\Application Data\Microsoft\User Account Pictures\<xsl:value-of select="config/user-realname"/>.bmp"
+if not "<xsl:value-of select="config/avatar-location"/>"=="" copy "<xsl:value-of select="config/avatar-disk"/>:\<xsl:value-of select="config/avatar-location"/>" "<xsl:value-of select="config/target-disk"/>:\Documents and Settings\All Users\Application Data\Microsoft\User Account Pictures\<xsl:value-of select="config/user-realname"/>.bmp"
 REGEDIT /S a:\windows.reg
 EXIT
 	</xsl:template>
diff --git a/data/install-scripts/windows-unattend.xml b/data/install-scripts/windows-unattend.xml
index f94aa64..f7d5f1f 100644
--- a/data/install-scripts/windows-unattend.xml
+++ b/data/install-scripts/windows-unattend.xml
@@ -9,6 +9,7 @@
       <param name="user-password" policy="optional"/>
       <param name="user-realname" policy="optional"/>
       <param name="reg-product-key" policy="required"/>
+      <param name="target-disk" policy="required"/>
     </config>
     <template filename="autounattend.xml" path-format="dos">
       <xsl:stylesheet
@@ -52,8 +53,8 @@
 			<Active>true</Active>
 			<Extend>true</Extend>
 			<Format>NTFS</Format>
-			<Label>C drive</Label>
-			<Letter>C</Letter>
+                        <Label><xsl:value-of select="config/target-disk"/> drive</Label>
+                        <Letter><xsl:value-of select="config/target-disk"/></Letter>
 			<Order>1</Order>
 			<PartitionID>1</PartitionID>
 		      </ModifyPartition>
@@ -174,6 +175,7 @@
     <param name="user-password" policy="optional"/>
     <param name="user-realname" policy="optional"/>
     <param name="hostname" policy="required"/>
+    <param name="target-disk" policy="required"/>
    </config>
     <template filename="autounattend.xml" path-format="dos">
      <xsl:stylesheet
@@ -220,8 +222,8 @@
              <Active>true</Active>
              <Extend>true</Extend>
              <Format>NTFS</Format>
-             <Label>C drive</Label>
-             <Letter>C</Letter>
+             <Label><xsl:value-of select="config/target-disk"/> drive</Label>
+             <Letter><xsl:value-of select="config/target-disk"/></Letter>
              <Order>1</Order>
              <PartitionID>1</PartitionID>
             </ModifyPartition>
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index c3ea27d..0892a61 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -331,6 +331,9 @@ LIBOSINFO_0.2.2 {
 	osinfo_install_config_set_avatar_disk;
 
 	osinfo_install_script_get_expected_path_format;
+
+	osinfo_install_config_get_target_disk;
+	osinfo_install_config_set_target_disk;
 } LIBOSINFO_0.2.1;
 
 
diff --git a/osinfo/osinfo_install_config.c b/osinfo/osinfo_install_config.c
index db53be8..0dffb28 100644
--- a/osinfo/osinfo_install_config.c
+++ b/osinfo/osinfo_install_config.c
@@ -330,6 +330,38 @@ const gchar *osinfo_install_config_get_hostname(OsinfoInstallConfig *config)
 }
 
 /**
+ * osinfo_install_config_set_target_disk:
+ *
+ * Sets the #OSINFO_INSTALL_CONFIG_PROP_TARGET_DISK parameter.
+ *
+ * Note that the format of this string is dependent on the installer script
+ * @config is going to be used with. You can use
+ * #osinfo_install_script_get_expected_path_format() to find out which format
+ * does the script expects this string to be in. In case of
+ * #OSINFO_PATH_FORMAT_UNIX unix device node names are expected, e.g "/dev/fd0".
+ * In case of #OSINFO_PATH_FORMAT_DOS drive letters are expected, e.g "A".
+ */
+void osinfo_install_config_set_target_disk(OsinfoInstallConfig *config,
+                                           const gchar *disk)
+{
+    osinfo_entity_set_param(OSINFO_ENTITY(config),
+                            OSINFO_INSTALL_CONFIG_PROP_TARGET_DISK,
+                            disk);
+}
+
+/**
+ * osinfo_install_config_get_target_disk:
+ *
+ * Returns: The value of #OSINFO_INSTALL_CONFIG_PROP_TARGET_DISK parameter,
+ *          or NULL.
+ */
+const gchar *osinfo_install_config_get_target_disk(OsinfoInstallConfig *config)
+{
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(config),
+                                         OSINFO_INSTALL_CONFIG_PROP_TARGET_DISK);
+}
+
+/**
  * osinfo_install_config_set_avatar_location:
  *
  * Sets the #OSINFO_INSTALL_CONFIG_PROP_AVATAR_LOCATION parameter.
@@ -361,12 +393,8 @@ const gchar *osinfo_install_config_get_avatar_location(OsinfoInstallConfig *conf
  *
  * Sets the #OSINFO_INSTALL_CONFIG_PROP_AVATAR_DISK parameter.
  *
- * Note that the format of this string is dependent on the installer script
- * @config is going to be used with. You can use
- * #osinfo_install_script_get_expected_path_format() to find out which format
- * does the script expects this string to be in. In case of
- * #OSINFO_PATH_FORMAT_UNIX unix device node names are expected, e.g "/dev/fd0".
- * In case of #OSINFO_PATH_FORMAT_DOS drive letters are expected, e.g "A".
+ * Please read documentation on #osinfo_install_config_set_target_disk() for
+ * explanation on the format of @disk string.
  */
 void osinfo_install_config_set_avatar_disk(OsinfoInstallConfig *config,
                                            const gchar *disk)
diff --git a/osinfo/osinfo_install_config.h b/osinfo/osinfo_install_config.h
index 2fd49ab..cf5b455 100644
--- a/osinfo/osinfo_install_config.h
+++ b/osinfo/osinfo_install_config.h
@@ -54,7 +54,8 @@
 #define OSINFO_INSTALL_CONFIG_PROP_REG_PASSWORD   "reg-password"
 #define OSINFO_INSTALL_CONFIG_PROP_REG_PRODUCTKEY "reg-product-key"
 
-#define OSINFO_INSTALL_CONFIG_PROP_HOSTNAME "hostname"
+#define OSINFO_INSTALL_CONFIG_PROP_HOSTNAME    "hostname"
+#define OSINFO_INSTALL_CONFIG_PROP_TARGET_DISK "target-disk"
 
 #define OSINFO_INSTALL_CONFIG_PROP_AVATAR_LOCATION "avatar-location"
 #define OSINFO_INSTALL_CONFIG_PROP_AVATAR_DISK     "avatar-disk"
@@ -154,6 +155,10 @@ void osinfo_install_config_set_hostname(OsinfoInstallConfig *config,
                                         const gchar *hostname);
 const gchar *osinfo_install_config_get_hostname(OsinfoInstallConfig *config);
 
+void osinfo_install_config_set_target_disk(OsinfoInstallConfig *config,
+                                           const gchar *disk);
+const gchar *osinfo_install_config_get_target_disk(OsinfoInstallConfig *config);
+
 void osinfo_install_config_set_avatar_location(OsinfoInstallConfig *config,
                                                const gchar *location);
 const gchar *osinfo_install_config_get_avatar_location(OsinfoInstallConfig *config);
-- 
1.8.0




More information about the virt-tools-list mailing list