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@xxxxxxxxxx> --- 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 5aac58e..39906c4 100644 --- a/osinfo/libosinfo.syms +++ b/osinfo/libosinfo.syms @@ -534,6 +534,7 @@ LIBOSINFO_1.3.0 { osinfo_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 a312958..f703ab1 100644 --- a/osinfo/osinfo_image.c +++ b/osinfo/osinfo_image.c @@ -56,6 +56,7 @@ enum { PROP_ARCHITECTURE, PROP_FORMAT, PROP_URL, + PROP_CLOUD_INIT, }; static void @@ -79,6 +80,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); @@ -113,6 +118,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); @@ -242,6 +253,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 e6fa6f6..d9d0818 100644 --- a/osinfo/osinfo_image.h +++ b/osinfo/osinfo_image.h @@ -46,6 +46,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 @@ -73,6 +74,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 b17c09d..e91ce2d 100644 --- a/osinfo/osinfo_loader.c +++ b/osinfo/osinfo_loader.c @@ -1261,11 +1261,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 _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo