[virt-tools-list] [libosinfo v2] Add 'install-stages' parameter to OsinfoMedia

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Wed Oct 3 15:13:15 UTC 2012


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

If media is an installer, this specifies the number of install stages
(IOW number of reboots the intaller takes before installation is
complete). Default value is '1'.

This is mainly needed for applications like GNOME Boxes and virt-install
to be able to tell when OS installation from a given media is complete so
that they can take whatever post installation steps they may need to.
---
 osinfo/osinfo_loader.c |  8 ++++++
 osinfo/osinfo_media.c  | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_media.h  | 20 ++++++++-------
 3 files changed, 85 insertions(+), 9 deletions(-)

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index ab507da..d050cc2 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -652,6 +652,7 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
     gchar *arch = (gchar *)xmlGetProp(root, BAD_CAST "arch");
     xmlChar *live = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_LIVE);
     xmlChar *installer = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_INSTALLER);
+    xmlChar *install_stages = xmlGetProp(root, BAD_CAST OSINFO_MEDIA_PROP_INSTALL_STAGES);
     const gchar *const keys[] = {
         OSINFO_MEDIA_PROP_URL,
         OSINFO_MEDIA_PROP_KERNEL,
@@ -676,6 +677,13 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
         xmlFree(installer);
     }
 
+    if (install_stages) {
+        osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                OSINFO_MEDIA_PROP_INSTALL_STAGES,
+                                (gchar *)install_stages);
+        xmlFree(install_stages);
+    }
+
     gint nnodes = osinfo_loader_nodeset("./iso/*", ctxt, &nodes, err);
     if (error_is_set(err))
         return NULL;
diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 6e33634..872b678 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -151,6 +151,7 @@ enum {
     PROP_INITRD_PATH,
     PROP_INSTALLER,
     PROP_LIVE,
+    PROP_INSTALL_STAGES,
 };
 
 static void
@@ -212,6 +213,11 @@ osinfo_media_get_property (GObject    *object,
                              osinfo_media_get_live (media));
         break;
 
+    case PROP_INSTALL_STAGES:
+        g_value_set_int (value,
+                         osinfo_media_get_install_stages (media));
+        break;
+
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -288,6 +294,12 @@ osinfo_media_set_property(GObject      *object,
                                          g_value_get_boolean (value));
         break;
 
+    case PROP_INSTALL_STAGES:
+        osinfo_entity_set_param_int64 (OSINFO_ENTITY(media),
+                                       OSINFO_MEDIA_PROP_INSTALL_STAGES,
+                                       g_value_get_int (value));
+        break;
+
     default:
         /* We don't have any other property... */
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -465,6 +477,34 @@ osinfo_media_class_init (OsinfoMediaClass *klass)
                                   G_PARAM_STATIC_NICK |
                                   G_PARAM_STATIC_BLURB);
     g_object_class_install_property (g_klass, PROP_LIVE, pspec);
+
+    /**
+     * OsinfoMedia::install-stages:
+     *
+     * If media is an installer, this property indicates the number of install
+     * stages (IOW number of reboots the intaller takes before installation is
+     * complete).
+     *
+     * This property is not applicable to media that has no installer. You can
+     * use #osinfo_media_get_installer (or OsinfoMedia::installer) to check
+     * that.
+     *
+     * Warning: Some media allow you to install from live sessions, in which
+     * case number of reboots *alone* is not a reliable method for tracking
+     * installation.
+     */
+    pspec = g_param_spec_int ("install-stages",
+                              "InstallStages",
+                              "Number of installation stages",
+                              G_MININT,
+                              G_MAXINT,
+                              1 /* default value */,
+                              G_PARAM_READWRITE |
+                              G_PARAM_CONSTRUCT | /* to set default value */
+                              G_PARAM_STATIC_NAME |
+                              G_PARAM_STATIC_NICK |
+                              G_PARAM_STATIC_BLURB);
+    g_object_class_install_property (g_klass, PROP_INSTALL_STAGES, pspec);
 }
 
 static void
@@ -1005,6 +1045,32 @@ gboolean osinfo_media_get_live(OsinfoMedia *media)
             (OSINFO_ENTITY(media), OSINFO_MEDIA_PROP_LIVE, FALSE);
 }
 
+/**
+ * osinfo_media_get_install_stages:
+ * @media: a #OsinfoMedia instance
+ *
+ * If media is an installer, this method retrieves the number of install stages
+ * (IOW number of reboots the intaller takes before installation is complete).
+ *
+ * This function is not supposed to be called on media that has no installer.
+ * You can use #osinfo_media_get_installer (or OsinfoMedia::installer) to check
+ * that.
+ *
+ * Warning: Some media allow you to install from live sessions, in which case
+ * number of reboots *alone* is not a reliable method for tracking installation.
+ *
+ * Returns: (transfer none): the installer stages or -1 if media is not an
+ * installer
+ */
+gint osinfo_media_get_install_stages(OsinfoMedia *media)
+{
+    g_return_val_if_fail(OSINFO_IS_MEDIA(media), -1);
+    g_return_val_if_fail(osinfo_media_get_installer (media), -1);
+
+    return (gint) osinfo_entity_get_param_value_int64_with_default
+            (OSINFO_ENTITY(media), OSINFO_MEDIA_PROP_INSTALL_STAGES, 1);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index e897a91..cbda525 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -70,16 +70,17 @@ typedef struct _OsinfoMediaClass   OsinfoMediaClass;
 
 typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
 
-#define OSINFO_MEDIA_PROP_ARCHITECTURE "architecture"
-#define OSINFO_MEDIA_PROP_URL          "url"
-#define OSINFO_MEDIA_PROP_VOLUME_ID    "volume-id"
-#define OSINFO_MEDIA_PROP_SYSTEM_ID    "system-id"
-#define OSINFO_MEDIA_PROP_PUBLISHER_ID "publisher-id"
+#define OSINFO_MEDIA_PROP_ARCHITECTURE   "architecture"
+#define OSINFO_MEDIA_PROP_URL            "url"
+#define OSINFO_MEDIA_PROP_VOLUME_ID      "volume-id"
+#define OSINFO_MEDIA_PROP_SYSTEM_ID      "system-id"
+#define OSINFO_MEDIA_PROP_PUBLISHER_ID   "publisher-id"
 #define OSINFO_MEDIA_PROP_APPLICATION_ID "application-id"
-#define OSINFO_MEDIA_PROP_KERNEL       "kernel"
-#define OSINFO_MEDIA_PROP_INITRD       "initrd"
-#define OSINFO_MEDIA_PROP_LIVE         "live"
-#define OSINFO_MEDIA_PROP_INSTALLER    "installer"
+#define OSINFO_MEDIA_PROP_KERNEL         "kernel"
+#define OSINFO_MEDIA_PROP_INITRD         "initrd"
+#define OSINFO_MEDIA_PROP_LIVE           "live"
+#define OSINFO_MEDIA_PROP_INSTALLER      "installer"
+#define OSINFO_MEDIA_PROP_INSTALL_STAGES "install-stages"
 
 /* object */
 struct _OsinfoMedia
@@ -124,6 +125,7 @@ const gchar *osinfo_media_get_kernel_path(OsinfoMedia *media);
 const gchar *osinfo_media_get_initrd_path(OsinfoMedia *media);
 gboolean osinfo_media_get_installer(OsinfoMedia *media);
 gboolean osinfo_media_get_live(OsinfoMedia *media);
+gint osinfo_media_get_install_stages(OsinfoMedia *media);
 
 #endif /* __OSINFO_MEDIA_H__ */
 /*
-- 
1.7.12.1




More information about the virt-tools-list mailing list