[Libosinfo] [PATCH 3/3] Implement osinfo_install_script_get_command_line()
Fabiano Fidêncio
fidencio at redhat.com
Thu Apr 11 14:58:12 UTC 2013
---
data/install-scripts/fedora.xml | 60 +++++++++++++++++++++++++++++++++++++++++
data/install-scripts/rhel.xml | 52 +++++++++++++++++++++++++++++++++++
osinfo/libosinfo.syms | 1 +
osinfo/osinfo_install_script.c | 44 ++++++++++++++++++++++++++++--
osinfo/osinfo_install_script.h | 4 +++
5 files changed, 159 insertions(+), 2 deletions(-)
diff --git a/data/install-scripts/fedora.xml b/data/install-scripts/fedora.xml
index b5b20bb..7d9d41d 100644
--- a/data/install-scripts/fedora.xml
+++ b/data/install-scripts/fedora.xml
@@ -37,6 +37,29 @@
</xsl:choose>
</xsl:template>
+ <xsl:template name="script-disk">
+ <xsl:choose>
+ <xsl:when test="config/script-disk != ''">
+ <xsl:variable name="script-disk">
+ <xsl:value-of select="config/script-disk"/>
+ </xsl:variable>
+ <xsl:value-of select="substring-after($script-disk, '/dev/')"/>
+ </xsl:when>
+ <xsl:when test="os/version > 9">
+ <!-- target-disk uses virtio -->
+ <xsl:text>sda</xsl:text>
+ </xsl:when>
+ <xsl:when test="os/version > 6">
+ <!-- target-disk uses libata IDE -->
+ <xsl:text>sdb</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- target-disk uses IDE -->
+ <xsl:text>hdb</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
<xsl:template name="rootfs">
<xsl:choose>
<xsl:when test="os/version > 10">
@@ -74,6 +97,13 @@
</xsl:choose>
</xsl:template>
+ <xsl:template match="/command-line">
+ <xsl:text>ks=hd:</xsl:text>
+ <xsl:call-template name="script-disk"/>
+ <xsl:text>:/</xsl:text>
+ <xsl:value-of select="script/expected-filename"/>
+ </xsl:template>
+
<xsl:template match="/install-script-config">
# Install script for <xsl:value-of select="os/short-id"/> profile <xsl:value-of select="script/profile"/>
install
@@ -174,6 +204,29 @@ reboot
</xsl:choose>
</xsl:template>
+ <xsl:template name="script-disk">
+ <xsl:choose>
+ <xsl:when test="config/script-disk != ''">
+ <xsl:variable name="script-disk">
+ <xsl:value-of select="config/script-disk"/>
+ </xsl:variable>
+ <xsl:value-of select="substring-after($script-disk, '/dev/')"/>
+ </xsl:when>
+ <xsl:when test="os/version > 9">
+ <!-- target-disk uses virtio -->
+ <xsl:text>sda</xsl:text>
+ </xsl:when>
+ <xsl:when test="os/version > 6">
+ <!-- target-disk uses libata IDE -->
+ <xsl:text>sdb</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- target-disk uses IDE -->
+ <xsl:text>hdb</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
<xsl:template name="rootfs">
<xsl:choose>
<xsl:when test="os/version > 10">
@@ -211,6 +264,13 @@ reboot
</xsl:choose>
</xsl:template>
+ <xsl:template match="/command-line">
+ <xsl:text>ks=hd:</xsl:text>
+ <xsl:call-template name="script-disk"/>
+ <xsl:text>:/</xsl:text>
+ <xsl:value-of select="script/expected-filename"/>
+ </xsl:template>
+
<xsl:template match="/install-script-config">
# Install script for <xsl:value-of select="os/short-id"/> profile <xsl:value-of select="script/profile"/>
install
diff --git a/data/install-scripts/rhel.xml b/data/install-scripts/rhel.xml
index 37cf410..35be1c2 100644
--- a/data/install-scripts/rhel.xml
+++ b/data/install-scripts/rhel.xml
@@ -33,6 +33,32 @@
</xsl:choose>
</xsl:template>
+ <xsl:template name="script-disk">
+ <xsl:choose>
+ <xsl:when test="config/script-disk != ''">
+ <xsl:variable name="script-disk">
+ <xsl:value-of select="config/script-disk"/>
+ </xsl:variable>
+ <xsl:value-of select="substring-after($script-disk, '/dev/')"/>
+ </xsl:when>
+ <xsl:when test="os/version > 4">
+ <!-- target-disk uses virtio -->
+ <xsl:text>sda</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- target-disk uses IDE -->
+ <xsl:text>sdb</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="/command-line">
+ <xsl:text>ks=hd:</xsl:text>
+ <xsl:call-template name="script-disk"/>
+ <xsl:text>:/</xsl:text>
+ <xsl:value-of select="script/expected-filename"/>
+ </xsl:template>
+
<xsl:template match="/install-script-config">
# Install script for <xsl:value-of select="os/short-id"/> profile <xsl:value-of select="script/profile"/>
install
@@ -119,6 +145,32 @@ reboot
</xsl:choose>
</xsl:template>
+ <xsl:template name="script-disk">
+ <xsl:choose>
+ <xsl:when test="config/script-disk != ''">
+ <xsl:variable name="script-disk">
+ <xsl:value-of select="config/script-disk"/>
+ </xsl:variable>
+ <xsl:value-of select="substring-after($script-disk, '/dev/')"/>
+ </xsl:when>
+ <xsl:when test="os/version > 4">
+ <!-- target-disk uses virtio -->
+ <xsl:text>sda</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- target-disk uses IDE -->
+ <xsl:text>sdb</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="/command-line">
+ <xsl:text>ks=hd:</xsl:text>
+ <xsl:call-template name="script-disk"/>
+ <xsl:text>:/</xsl:text>
+ <xsl:value-of select="script/expected-filename"/>
+ </xsl:template>
+
<xsl:template match="/install-script-config">
# Install script for <xsl:value-of select="os/short-id"/> profile <xsl:value-of select="script/profile"/>
install
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 8fcf327..d68d36c 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -415,6 +415,7 @@ LIBOSINFO_0.2.6 {
LIBOSINFO_0.2.7 {
osinfo_platform_get_all_devices;
+ osinfo_install_script_get_command_line;
} LIBOSINFO_0.2.6;
/* Symbols in next release...
diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
index 3d5fe8d..78c31f6 100644
--- a/osinfo/osinfo_install_script.c
+++ b/osinfo/osinfo_install_script.c
@@ -732,6 +732,7 @@ static xmlNodePtr osinfo_install_script_generate_entity_xml(OsinfoInstallScript
static xmlDocPtr osinfo_install_script_generate_config_xml(OsinfoInstallScript *script,
OsinfoOs *os,
OsinfoInstallConfig *config,
+ const gchar *searched_node,
GError **error)
{
xmlDocPtr doc = xmlNewDoc((xmlChar *)"1.0");
@@ -740,7 +741,7 @@ static xmlDocPtr osinfo_install_script_generate_config_xml(OsinfoInstallScript *
root = xmlNewDocNode(NULL,
NULL,
- (xmlChar*)"install-script-config",
+ (xmlChar*)searched_node,
NULL);
xmlDocSetRootElement(doc, root);
@@ -820,13 +821,14 @@ static gboolean osinfo_install_script_apply_template(OsinfoInstallScript *script
OsinfoOs *os,
const gchar *templateUri,
const gchar *template,
+ const gchar *node,
gchar **result,
OsinfoInstallConfig *config,
GError **error)
{
gboolean ret = FALSE;
xsltStylesheetPtr templateXsl = osinfo_install_script_load_template(templateUri, template, error);
- xmlDocPtr configXml = osinfo_install_script_generate_config_xml(script, os, config, error);
+ xmlDocPtr configXml = osinfo_install_script_generate_config_xml(script, os, config, node, error);
if (!templateXsl || !configXml)
goto cleanup;
@@ -871,6 +873,7 @@ static void osinfo_install_script_template_loaded(GObject *src,
data->os,
uri,
input,
+ "install-script-config",
&output,
data->config,
&error)) {
@@ -915,6 +918,7 @@ void osinfo_install_script_generate_async(OsinfoInstallScript *script,
os,
"<data>",
templateData,
+ "install-script-config",
&output,
data->config,
&error)) {
@@ -1266,6 +1270,42 @@ int osinfo_install_script_get_post_install_drivers_signing_req(OsinfoInstallScri
OSINFO_DEVICE_DRIVER_SIGNING_REQ_NONE);
}
+/**
+ * osinfo_install_script_get_command_line:
+ * @script: the install script
+ * @os: the os entity
+ * @config: the install script config
+ *
+ * If install script needs pass a command line to kernel, this function
+ * retrieves the command line
+ *
+ * Returns: (transfer full): The command line string, or NULL otherwise.
+ */
+gchar *osinfo_install_script_get_command_line(OsinfoInstallScript *script,
+ OsinfoOs *os,
+ OsinfoInstallConfig *config)
+{
+ const gchar *templateData = osinfo_install_script_get_template_data(script);
+ gchar *output = NULL;
+
+ if (templateData) {
+ GError *error = NULL;
+ if (!osinfo_install_script_apply_template(script,
+ os,
+ "<data>",
+ templateData,
+ "command-line",
+ &output,
+ config,
+ &error)) {
+ g_prefix_error(&error, "%s", _("Failed to apply script template: "));
+ }
+ }
+
+ return output;
+}
+
+
/*
* Local variables:
* indent-tabs-mode: nil
diff --git a/osinfo/osinfo_install_script.h b/osinfo/osinfo_install_script.h
index e94c88c..7d90703 100644
--- a/osinfo/osinfo_install_script.h
+++ b/osinfo/osinfo_install_script.h
@@ -193,6 +193,10 @@ gboolean osinfo_install_script_get_can_post_install_drivers(OsinfoInstallScript
int osinfo_install_script_get_pre_install_drivers_signing_req(OsinfoInstallScript *script);
int osinfo_install_script_get_post_install_drivers_signing_req(OsinfoInstallScript *script);
+gchar *osinfo_install_script_get_command_line(OsinfoInstallScript *script,
+ OsinfoOs *os,
+ OsinfoInstallConfig *config);
+
#endif /* __OSINFO_INSTALL_SCRIPT_H__ */
/*
* Local variables:
--
1.8.2
More information about the Libosinfo
mailing list