[Libosinfo] [libosinfo PATCH] os: Add kernel-url-argument API

Fabiano Fidêncio fidencio at redhat.com
Thu May 2 14:39:10 UTC 2019


Tree based installations will require a kernel-url-argument to be
assed. Let's provide an API to the apps to get this info from OsinfoOS.

https://gitlab.com/libosinfo/osinfo-db/issues/28

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 osinfo/libosinfo.syms                         |  2 +
 osinfo/osinfo_loader.c                        |  1 +
 osinfo/osinfo_os.c                            | 40 +++++++++++++++++++
 osinfo/osinfo_os.h                            |  3 ++
 .../dbdata/os/libosinfo.org/test-os-test1.xml |  2 +
 tests/test-os.c                               |  2 +
 6 files changed, 50 insertions(+)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 853acf5..f8b56a7 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -577,6 +577,8 @@ LIBOSINFO_1.5.0 {
 	osinfo_install_config_get_installation_url;
 	osinfo_install_config_set_installation_url;
 
+	osinfo_os_get_kernel_url_argument;
+
 	osinfo_product_get_short_id_list;
 
 	osinfo_tree_get_os;
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 522162f..7735357 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1563,6 +1563,7 @@ static void osinfo_loader_os(OsinfoLoader *loader,
         { OSINFO_OS_PROP_FAMILY, G_TYPE_STRING },
         { OSINFO_OS_PROP_DISTRO, G_TYPE_STRING },
         { OSINFO_OS_PROP_RELEASE_STATUS, G_TYPE_STRING },
+        { OSINFO_OS_PROP_KERNEL_URL_ARGUMENT, G_TYPE_STRING },
         { NULL, G_TYPE_INVALID }
     };
 
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index e458a45..48ca06f 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -75,6 +75,7 @@ enum {
 
     PROP_FAMILY,
     PROP_DISTRO,
+    PROP_KERNEL_URL_ARGUMENT,
 };
 
 static void osinfo_os_finalize(GObject *object);
@@ -99,6 +100,11 @@ osinfo_os_get_property(GObject    *object,
                                 osinfo_entity_get_param_value(entity,
                                                                "distro"));
             break;
+        case PROP_KERNEL_URL_ARGUMENT:
+            g_value_set_string(value,
+                               osinfo_entity_get_param_value(entity,
+                                                             OSINFO_OS_PROP_KERNEL_URL_ARGUMENT));
+            break;
         default:
             /* We don't have any other property... */
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -172,6 +178,22 @@ osinfo_os_class_init(OsinfoOsClass *klass)
     g_object_class_install_property(g_klass,
                                     PROP_DISTRO,
                                     pspec);
+
+    /**
+     * OsinfoOs:kernel-url-argument:
+     *
+     * The argument to be passed to kernel command line when performing a
+     * tree based installation of this OS.
+     */
+    pspec = g_param_spec_string("kernel-url-argument",
+                                "KernelURLArgument",
+                                _("Kernel URL Argument"),
+                                NULL /* default value */,
+                                G_PARAM_READABLE |
+                                G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass,
+                                    PROP_KERNEL_URL_ARGUMENT,
+                                    pspec);
 }
 
 static void
@@ -1142,3 +1164,21 @@ void osinfo_os_add_device_driver(OsinfoOs *os, OsinfoDeviceDriver *driver)
     osinfo_list_add(OSINFO_LIST(os->priv->device_drivers),
                     OSINFO_ENTITY(driver));
 }
+
+/**
+ * osinfo_os_get_kernel_url_argument:
+ * @os: an operating system
+ *
+ * Gets the argument expected to be passed to the kernel command line when
+ * performing a tree based installation.
+ *
+ * Returns: (transfer none): the kernel url argument, if present. Otherwise,
+ * NULL.
+ */
+const gchar *osinfo_os_get_kernel_url_argument(OsinfoOs *os)
+{
+    g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
+
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(os),
+                                         OSINFO_OS_PROP_KERNEL_URL_ARGUMENT);
+}
diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h
index 7c10475..6207a53 100644
--- a/osinfo/osinfo_os.h
+++ b/osinfo/osinfo_os.h
@@ -62,6 +62,7 @@ typedef struct _OsinfoOsPrivate OsinfoOsPrivate;
 #define OSINFO_OS_PROP_FAMILY                 "family"
 #define OSINFO_OS_PROP_DISTRO                 "distro"
 #define OSINFO_OS_PROP_RELEASE_STATUS         "release-status"
+#define OSINFO_OS_PROP_KERNEL_URL_ARGUMENT    "kernel-url-argument"
 
 /* object */
 struct _OsinfoOs
@@ -142,4 +143,6 @@ void osinfo_os_add_install_script(OsinfoOs *os, OsinfoInstallScript *script);
 OsinfoDeviceDriverList *osinfo_os_get_device_drivers(OsinfoOs *os);
 void osinfo_os_add_device_driver(OsinfoOs *os, OsinfoDeviceDriver *driver);
 
+const gchar *osinfo_os_get_kernel_url_argument(OsinfoOs *os);
+
 #endif /* __OSINFO_OS_H__ */
diff --git a/tests/dbdata/os/libosinfo.org/test-os-test1.xml b/tests/dbdata/os/libosinfo.org/test-os-test1.xml
index 8253459..1417a80 100644
--- a/tests/dbdata/os/libosinfo.org/test-os-test1.xml
+++ b/tests/dbdata/os/libosinfo.org/test-os-test1.xml
@@ -7,5 +7,7 @@
     <vendor>libosinfo.org</vendor>
     <family>test</family>
     <release-status>prerelease</release-status>
+
+    <kernel-url-argument>install</kernel-url-argument>
   </os>
 </libosinfo>
diff --git a/tests/test-os.c b/tests/test-os.c
index fe7c2d6..4ffe4f4 100644
--- a/tests/test-os.c
+++ b/tests/test-os.c
@@ -92,6 +92,8 @@ test_loader(void)
     str = osinfo_os_get_family(os);
     g_assert_cmpstr(str, ==, "test");
     g_assert_cmpint(osinfo_os_get_release_status(os), ==, OSINFO_RELEASE_STATUS_PRERELEASE);
+    str = osinfo_os_get_kernel_url_argument(os);
+    g_assert_cmpstr(str, ==, "install");
 
     os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test2");
     g_assert_nonnull(os);
-- 
2.21.0




More information about the Libosinfo mailing list