[Libosinfo] [libosinfo PATCH v3 10/10] image: Add "cloud-init" attribute to the image
Fabiano Fidêncio
fidencio at redhat.com
Wed Nov 14 14:49:51 UTC 2018
Some images may support cloud init customization and for those we'd like
to explicitly indicate it.
The "cloud-init" attribute is similar to the "live" attribute for
medias, has its default value as FALSE and can be optinionally set in
the XML.
This commit also extends the basic image tests to also cover the
cloud-images attribute.
https://gitlab.com/libosinfo/osinfo-db/issues/10
Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
osinfo/libosinfo.syms | 1 +
osinfo/osinfo_image.c | 26 ++++++++++++++++++++++++++
osinfo/osinfo_image.h | 2 ++
osinfo/osinfo_loader.c | 8 ++++++++
tests/test-image.c | 6 ++++++
5 files changed, 43 insertions(+)
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index bb3d476..c99d6ab 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -535,6 +535,7 @@ LIBOSINFO_1.3.0 {
osinfo_image_error_quark;
osinfo_image_get_architecture;
+ osinfo_image_get_cloud_init;
osinfo_image_get_format;
osinfo_image_get_type;
osinfo_image_get_url;
diff --git a/osinfo/osinfo_image.c b/osinfo/osinfo_image.c
index 234b328..335ec75 100644
--- a/osinfo/osinfo_image.c
+++ b/osinfo/osinfo_image.c
@@ -67,6 +67,7 @@ enum {
PROP_ARCHITECTURE,
PROP_FORMAT,
PROP_URL,
+ PROP_CLOUD_INIT,
};
static void
@@ -90,6 +91,10 @@ osinfo_image_get_property(GObject *object,
g_value_set_string(value, osinfo_image_get_url(image));
break;
+ case PROP_CLOUD_INIT:
+ g_value_set_boolean(value, osinfo_image_get_cloud_init(image));
+ break;
+
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -124,6 +129,12 @@ osinfo_image_set_property(GObject *object,
g_value_get_string(value));
break;
+ case PROP_CLOUD_INIT:
+ osinfo_entity_set_param_boolean(OSINFO_ENTITY(image),
+ OSINFO_IMAGE_PROP_CLOUD_INIT,
+ g_value_get_boolean(value));
+ break;
+
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
@@ -259,6 +270,21 @@ const gchar *osinfo_image_get_url(OsinfoImage *image)
OSINFO_IMAGE_PROP_URL);
}
+/**
+ * osinfo_image_get_cloud_init:
+ * @image: an #OsinfoImage instance
+ *
+ * Whether @image supports cloud init customizations
+ *
+ * Returns: #TRUE if @image supports cloud init customizations, #FALSE
+ * otherwise.
+ */
+gboolean osinfo_image_get_cloud_init(OsinfoImage *image)
+{
+ return osinfo_entity_get_param_value_boolean_with_default
+ (OSINFO_ENTITY(image), OSINFO_IMAGE_PROP_CLOUD_INIT, FALSE);
+}
+
/*
* Local variables:
* indent-tabs-mode: nil
diff --git a/osinfo/osinfo_image.h b/osinfo/osinfo_image.h
index 3478ea4..4ac4ad7 100644
--- a/osinfo/osinfo_image.h
+++ b/osinfo/osinfo_image.h
@@ -53,6 +53,7 @@ typedef struct _OsinfoImagePrivate OsinfoImagePrivate;
#define OSINFO_IMAGE_PROP_ARCHITECTURE "architecture"
#define OSINFO_IMAGE_PROP_FORMAT "format"
#define OSINFO_IMAGE_PROP_URL "url"
+#define OSINFO_IMAGE_PROP_CLOUD_INIT "cloud-init"
/* object */
struct _OsinfoImage
@@ -80,6 +81,7 @@ OsinfoImage *osinfo_image_new(const gchar *id, const gchar *architecture, const
const gchar *osinfo_image_get_architecture(OsinfoImage *image);
const gchar *osinfo_image_get_format(OsinfoImage *image);
const gchar *osinfo_image_get_url(OsinfoImage *image);
+gboolean osinfo_image_get_cloud_init(OsinfoImage *image);
#endif /* __OSINFO_IMAGE_H__ */
/*
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 9ac5492..b6c8fe5 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1251,11 +1251,19 @@ static OsinfoImage *osinfo_loader_image(OsinfoLoader *loader,
gchar *arch = (gchar *)xmlGetProp(root, BAD_CAST "arch");
gchar *format = (gchar *)xmlGetProp(root, BAD_CAST "format");
+ gchar *cloud_init = (gchar *)xmlGetProp(root, BAD_CAST "cloud-init");
OsinfoImage *image = osinfo_image_new(id, arch, format);
xmlFree(arch);
xmlFree(format);
osinfo_loader_entity(loader, OSINFO_ENTITY(image), keys, ctxt, root, err);
+ if (cloud_init) {
+ osinfo_entity_set_param(OSINFO_ENTITY(image),
+ OSINFO_IMAGE_PROP_CLOUD_INIT,
+ (gchar *)cloud_init);
+
+ xmlFree(cloud_init);
+ }
return image;
}
diff --git a/tests/test-image.c b/tests/test-image.c
index 053e041..d029600 100644
--- a/tests/test-image.c
+++ b/tests/test-image.c
@@ -41,6 +41,12 @@ test_basic(void)
g_assert_cmpstr(osinfo_image_get_format(image), ==, FORMAT);
g_assert_cmpstr(osinfo_image_get_url(image), ==, URL);
+ g_assert_false(osinfo_image_get_cloud_init(image));
+ osinfo_entity_set_param_boolean(OSINFO_ENTITY(image),
+ OSINFO_IMAGE_PROP_CLOUD_INIT,
+ TRUE);
+ g_assert_true(osinfo_image_get_cloud_init(image));
+
g_object_unref(image);
}
--
2.19.1
More information about the Libosinfo
mailing list