[Libosinfo] [PATCH v4 1/7] install_scripts: Add get_supported_injection_method API

Giuseppe Scrivano gscrivan at redhat.com
Wed Mar 5 15:01:38 UTC 2014


The API allows to query how it is possible to use the script from the
installation process.

Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
---
 data/schemas/libosinfo.rng     | 11 +++++++++++
 osinfo/libosinfo.syms          |  5 +++++
 osinfo/osinfo_install_script.c | 20 +++++++++++++++++++-
 osinfo/osinfo_install_script.h | 24 +++++++++++++++++++++++-
 osinfo/osinfo_loader.c         | 23 +++++++++++++++++++++--
 5 files changed, 79 insertions(+), 4 deletions(-)

diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
index 0675217..778a972 100644
--- a/data/schemas/libosinfo.rng
+++ b/data/schemas/libosinfo.rng
@@ -616,6 +616,9 @@
             <ref name='driver-signing-reqs'/>
           </element>
         </optional>
+        <zeroOrMore>
+          <ref name='supported-injection-method'/>
+        </zeroOrMore>
         <element name='template'>
           <choice>
             <group>
@@ -770,4 +773,12 @@
       </data>
     </element>
   </define>
+
+  <define name='supported-injection-method'>
+    <element name='supported-injection-method'>
+      <data type="string">
+        <param name="pattern">cdrom|floppy|initrd|web</param>
+      </data>
+    </element>
+  </define>
 </grammar>
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index c3b967c..cdcfc28 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -495,6 +495,11 @@ LIBOSINFO_0.2.9 {
 	osinfo_release_status_get_type;
 } LIBOSINFO_0.2.8;
 
+LIBOSINFO_0.2.10 {
+	osinfo_install_script_get_supported_injection_method;
+	osinfo_install_script_supported_injection_method_get_type;
+} LIBOSINFO_0.2.9;
+
 /* Symbols in next release...
 
   LIBOSINFO_0.0.2 {
diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
index 7444c8d..de508f4 100644
--- a/osinfo/osinfo_install_script.c
+++ b/osinfo/osinfo_install_script.c
@@ -1,7 +1,7 @@
 /*
  * libosinfo:
  *
- * Copyright (C) 2009-2012 Red Hat, Inc.
+ * Copyright (C) 2009-2012, 2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1309,6 +1309,24 @@ int osinfo_install_script_get_post_install_drivers_signing_req(OsinfoInstallScri
          OSINFO_DEVICE_DRIVER_SIGNING_REQ_NONE);
 }
 
+/**
+ * osinfo_install_script_get_supported_injection_method:
+ * @script: the install script
+ *
+ * Retrieve how it is possible to inject the script in the installation process.
+ *
+ * Returns: (type OsinfoInstallScriptSupportedInjectionMethod): bitwise-or of
+ * supported methods(#OsinfoInstallScriptSupportedInjectionMethod) for install
+ * script injection.
+ */
+unsigned int osinfo_install_script_get_supported_injection_method(OsinfoInstallScript *script)
+{
+    return osinfo_entity_get_param_value_int64_with_default
+        (OSINFO_ENTITY(script),
+         OSINFO_INSTALL_SCRIPT_PROP_SUPPORTED_INJECTION_METHOD,
+         0);
+}
+
 
 /*
  * Local variables:
diff --git a/osinfo/osinfo_install_script.h b/osinfo/osinfo_install_script.h
index c39b786..ef5fb7c 100644
--- a/osinfo/osinfo_install_script.h
+++ b/osinfo/osinfo_install_script.h
@@ -1,7 +1,7 @@
 /*
  * libosinfo: OS installation script
  *
- * Copyright (C) 2009-2012 Red Hat, Inc.
+ * Copyright (C) 2009-2012, 2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -57,6 +57,7 @@ typedef struct _OsinfoInstallScriptPrivate OsinfoInstallScriptPrivate;
 #define OSINFO_INSTALL_SCRIPT_PROP_CAN_POST_INSTALL_DRIVERS "can-post-install-drivers"
 #define OSINFO_INSTALL_SCRIPT_PROP_PRE_INSTALL_DRIVERS_SIGNING_REQ "pre-install-drivers-signing-req"
 #define OSINFO_INSTALL_SCRIPT_PROP_POST_INSTALL_DRIVERS_SIGNING_REQ "post-install-drivers-signing-req"
+#define OSINFO_INSTALL_SCRIPT_PROP_SUPPORTED_INJECTION_METHOD "supported-injection-method"
 
 /* object */
 struct _OsinfoInstallScript
@@ -113,6 +114,25 @@ typedef enum {
     OSINFO_DEVICE_DRIVER_SIGNING_REQ_WARN
 } OsinfoDeviceDriverSigningReq;
 
+/**
+ * OsinfoInstallScriptSupportedInjectionMethod:
+ *
+ * @OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_CDROM: Support injection of the
+ * installation script trough a CD-ROM.
+ * @OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_FLOPPY: Support injection of the
+ * installation script trough a floppy disk.
+ * @OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_INITRD: Support injection of the
+ * installation script trough the initrd.
+ * @OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_WEB: Support injection of the
+ * installation script from the web.
+ */
+typedef enum {
+    OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_CDROM  = 1 << 0,
+    OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_FLOPPY = 1 << 1,
+    OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_INITRD = 1 << 2,
+    OSINFO_INSTALL_SCRIPT_INJECTION_METHOD_WEB    = 1 << 3,
+} OsinfoInstallScriptSupportedInjectionMethod;
+
 GType osinfo_install_script_get_type(void);
 
 OsinfoInstallScript *osinfo_install_script_new(const gchar *id);
@@ -195,6 +215,8 @@ 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);
 
+unsigned int osinfo_install_script_get_supported_injection_method(OsinfoInstallScript *script);
+
 #endif /* __OSINFO_INSTALL_SCRIPT_H__ */
 /*
  * Local variables:
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index e9ce8e1..047882d 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1,7 +1,7 @@
 /*
  * libosinfo:
  *
- * Copyright (C) 2009-2012 Red Hat, Inc.
+ * Copyright (C) 2009-2012, 2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -777,7 +777,9 @@ static void osinfo_loader_install_script(OsinfoLoader *loader,
     };
     gchar *value = NULL;
     xmlNodePtr *nodes = NULL;
-    int nnodes;
+    int i, nnodes;
+    unsigned int injection_methods = 0;
+    GFlagsClass *flags_class;
 
     if (!id) {
         OSINFO_ERROR(err, _("Missing install script id property"));
@@ -835,6 +837,23 @@ static void osinfo_loader_install_script(OsinfoLoader *loader,
     }
     g_free(nodes);
 
+    nnodes = osinfo_loader_nodeset("./supported-injection-method", ctxt, &nodes, err);
+    if (error_is_set(err))
+        goto error;
+
+    flags_class = g_type_class_ref(OSINFO_TYPE_INSTALL_SCRIPT_SUPPORTED_INJECTION_METHOD);
+    for (i = 0 ; i < nnodes ; i++) {
+        const gchar *nick = (const gchar *) nodes[i]->children->content;
+        injection_methods |= g_flags_get_value_by_nick(flags_class, nick)->value;
+    }
+    osinfo_entity_set_param_int64(OSINFO_ENTITY(installScript),
+                                  OSINFO_INSTALL_SCRIPT_PROP_SUPPORTED_INJECTION_METHOD,
+                                  injection_methods);
+
+    g_type_class_unref(flags_class);
+    g_free(nodes);
+
+
     osinfo_db_add_install_script(loader->priv->db, installScript);
 
     return;
-- 
1.8.5.3




More information about the Libosinfo mailing list