[virt-tools-list] [PATCH 2/2] install script: add config_param entity
Christophe Fergeau
cfergeau at redhat.com
Mon Aug 13 07:54:55 UTC 2012
On Mon, Aug 13, 2012 at 04:37:37AM -0300, Fabiano Fidêncio wrote:
> Now we need to set what are the configs that will be used in each
> script. To set it, just add, in the .xml's script file:
> <config>
> <param name="..." policy="mandatory"|"optional"/>
> </config>
>
> For manage these configs, a new entity was created, called:
> OsinfoInstallConfigParam. And the OsinfoInstallScript entity is, now,
> keeping an internal list of the OsinfoInstallConfigParam entity.
>
> With these changes, applications that uses/will use libosinfo can check
> if an install script has some config to be set using, consulting by:
> - ConfigParam entity:
> osinfo_install_script_has_config_param(OsinfoInstallScript *script,
> const OsinfoInstallConfigParameter config_param);
>
> - Parameter name:
> osinfo_install_script_has_config_param_name(OsinfoInstallScript *script,
> const gchar* name);
> ---
> data/install-scripts/fedora.xml | 6 +
> data/install-scripts/windows-sif.xml | 5 +
> data/install-scripts/windows-unattend.xml | 9 ++
> data/schemas/libosinfo.rng | 12 ++
> docs/reference/Libosinfo.types | 1 +
> osinfo/Makefile.am | 1 +
> osinfo/libosinfo.syms | 8 +
> osinfo/osinfo.h | 1 +
> osinfo/osinfo_install_config_param.c | 234 ++++++++++++++++++++++++++++++
> osinfo/osinfo_install_config_param.h | 83 +++++++++++
> osinfo/osinfo_install_script.c | 49 ++++++-
> osinfo/osinfo_install_script.h | 12 +-
> osinfo/osinfo_loader.c | 36 +++++
> 13 files changed, 455 insertions(+), 2 deletions(-)
> create mode 100644 osinfo/osinfo_install_config_param.c
> create mode 100644 osinfo/osinfo_install_config_param.h
>
> diff --git a/data/install-scripts/fedora.xml b/data/install-scripts/fedora.xml
> index 338a570..a608cdb 100644
> --- a/data/install-scripts/fedora.xml
> +++ b/data/install-scripts/fedora.xml
> @@ -1,6 +1,12 @@
> <libosinfo version="0.0.1">
> <install-script id='http://fedoraproject.org/scripts/fedora/jeos'>
> <profile>jeos</profile>
> + <config>
> + <param name="admin-password" policy="optional"/>
> + <param name="l10n-keyboard" policy="optional"/>
> + <param name="l10n-language" policy="optional"/>
> + <param name="l10n-timezone" policy="optional"/>
> + </config>
> <template filename="fedora.ks">
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> diff --git a/data/install-scripts/windows-sif.xml b/data/install-scripts/windows-sif.xml
> index 46b24ae..77fc2c5 100644
> --- a/data/install-scripts/windows-sif.xml
> +++ b/data/install-scripts/windows-sif.xml
> @@ -1,6 +1,11 @@
> <libosinfo version="0.0.1">
> <install-script id='http://microsoft.com/windows/sif'>
> <profile>jeos</profile>
> + <config>
> + <param name="admin-password" policy="optional"/>
> + <param name="reg-product-key" policy="required"/>
> + <param name="user-realname" policy="required"/>
> + </config>
> <template filename="windows.sif">
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> diff --git a/data/install-scripts/windows-unattend.xml b/data/install-scripts/windows-unattend.xml
> index 20e3e23..5698bc8 100644
> --- a/data/install-scripts/windows-unattend.xml
> +++ b/data/install-scripts/windows-unattend.xml
> @@ -1,6 +1,15 @@
> <libosinfo version="0.0.1">
> <install-script id='http://microsoft.com/windows/unattend'>
> <profile>jeos</profile>
> + <config>
> + <param name="admin-password" policy="optional"/>
> + <param name="hardware-arch" policy="optional"/>
> + <param name="l10n-language" policy="optional"/>
> + <param name="user-login" policy="optional"/>
> + <param name="user-password" policy="optional"/>
> + <param name="user-realname" policy="optional"/>
> + <param name="reg-product-key" policy="required"/>
> + </config>
> <template filename="windows.xml">
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
> index 7c8d7f7..1392f74 100644
> --- a/data/schemas/libosinfo.rng
> +++ b/data/schemas/libosinfo.rng
> @@ -410,6 +410,12 @@
> <element name='profile'>
> <text/>
> </element>
> + <element name='config'>
> + <attribute name="name"/>
> + <attribute name="policy">
> + <ref name='policies'/>
> + </attribute>
> + </element>
> <element name='product-key-format'>
> <text/>
> </element>
> @@ -479,4 +485,10 @@
> <param name="pattern">\w+://.*</param>
> </data>
> </define>
> +
> + <define name='policies'>
> + <data type="string">
> + <param name="pattern">required|optional</param>
> + </data>
> + </define>
> </grammar>
> diff --git a/docs/reference/Libosinfo.types b/docs/reference/Libosinfo.types
> index faf8643..8744ee6 100644
> --- a/docs/reference/Libosinfo.types
> +++ b/docs/reference/Libosinfo.types
> @@ -9,6 +9,7 @@ osinfo_devicelist_get_type
> osinfo_entity_get_type
> osinfo_filter_get_type
> osinfo_install_config_get_type
> +osinfo_install_config_param_get_type
> osinfo_install_script_get_type
> osinfo_install_scriptlist_get_type
> osinfo_list_get_type
> diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
> index f4aea47..68c4172 100644
> --- a/osinfo/Makefile.am
> +++ b/osinfo/Makefile.am
> @@ -89,6 +89,7 @@ libosinfo_1_0_la_SOURCES = \
> osinfo_devicelinklist.c \
> osinfo_devicelinkfilter.c \
> osinfo_install_config.c \
> + osinfo_install_config_param.c \
> osinfo_install_script.c \
> osinfo_install_scriptlist.c \
> osinfo_product.c \
> diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
> index ddf736e..1e55d0e 100644
> --- a/osinfo/libosinfo.syms
> +++ b/osinfo/libosinfo.syms
> @@ -264,6 +264,8 @@ LIBOSINFO_0.2.0 {
> osinfo_install_config_set_user_administrator;
> osinfo_install_config_set_user_autologin;
> osinfo_install_config_set_hostname;
> + osinfo_install_config_param_get_type;
> + osinfo_install_config_param_new;
> osinfo_install_script_set_output_prefix;
> osinfo_install_script_get_type;
> osinfo_install_script_new;
> @@ -276,12 +278,18 @@ LIBOSINFO_0.2.0 {
> osinfo_install_script_generate_output_async;
> osinfo_install_script_get_profile;
> osinfo_install_script_get_uri;
> + osinfo_install_script_has_config_param;
> + osinfo_install_script_has_config_param_name;
> + osinfo_install_script_get_config_param_list;
> osinfo_install_scriptlist_new;
> osinfo_install_scriptlist_new_filtered;
> osinfo_install_scriptlist_new_union;
> osinfo_install_scriptlist_new_intersection;
> osinfo_install_scriptlist_new_copy;
> osinfo_install_scriptlist_get_type;
> + osinfo_install_config_param_new;
> + osinfo_install_config_param_get_name;
> + osinfo_install_config_param_get_policy;
> osinfo_db_get_install_script;
> osinfo_db_add_install_script;
> osinfo_db_get_install_script_list;
> diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
> index aa06095..204569b 100644
> --- a/osinfo/osinfo.h
> +++ b/osinfo/osinfo.h
> @@ -34,6 +34,7 @@
> #include <osinfo/osinfo_devicelinklist.h>
> #include <osinfo/osinfo_devicelinkfilter.h>
> #include <osinfo/osinfo_install_config.h>
> +#include <osinfo/osinfo_install_config_param.h>
> #include <osinfo/osinfo_install_script.h>
> #include <osinfo/osinfo_install_scriptlist.h>
> #include <osinfo/osinfo_productlist.h>
> diff --git a/osinfo/osinfo_install_config_param.c b/osinfo/osinfo_install_config_param.c
> new file mode 100644
> index 0000000..8a0ab56
> --- /dev/null
> +++ b/osinfo/osinfo_install_config_param.c
> @@ -0,0 +1,234 @@
> +/*
> + * libosinfo:
> + *
> + * Copyright (C) 2009-2012 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
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + *
> + * Authors:
> + * Fabiano Fidêncio <fabiano at fidencio.org>
> + */
> +
> +#include <config.h>
> +
> +#include <osinfo/osinfo.h>
> +
> +G_DEFINE_TYPE (OsinfoInstallConfigParam, osinfo_install_config_param, OSINFO_TYPE_ENTITY);
> +
> +#define OSINFO_INSTALL_CONFIG_PARAM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_INSTALL_CONFIG_PARAM, OsinfoInstallConfigParamPrivate))
> +
> +/**
> + * SECTION:osinfo_install_config_param
> + * @short_description: OS install configuration parameters (and its policies)
> + * @see_also: #OsinfoInstallScript, #OsinfoInstallSciptConfig
> + *
> + * #OsinfoInstallConfigParam is an entity for representing all parameters that
> + * can be set in an automated installation. It is used to help applications to
> + * generate an automated installation script
> + */
> +
> +struct _OsinfoInstallConfigParamPrivate
> +{
> + gchar *name;
> + OsinfoInstallConfigParamPolicy policy;
> +};
> +
> +enum {
> + PROP_0,
> +
> + PROP_NAME,
> + PROP_POLICY,
> +};
> +
> +static void
> +osinfo_install_config_param_set_property(GObject *object,
> + guint property_id,
> + const GValue *value,
> + GParamSpec *pspec)
> +{
> + OsinfoInstallConfigParam *config_param =
> + OSINFO_INSTALL_CONFIG_PARAM (object);
> +
> + switch (property_id)
> + {
> + case PROP_NAME:
> + config_param->priv->name = g_value_dup_string(value);
> + break;
> + case PROP_POLICY:
> + {
> + const gchar *policy = g_value_get_string(value);
> + if (g_strcmp0(policy, "required") == 0)
> + config_param->priv->policy =
> + OSINFO_INSTALL_CONFIG_PARAM_POLICY_REQUIRED;
> + else if (g_strcmp0(policy, "optional") == 0)
> + config_param->priv->policy =
> + OSINFO_INSTALL_CONFIG_PARAM_POLICY_OPTIONAL;
> + break;
> + }
> + default:
> + /* We don't have any other property... */
> + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
> + break;
> + }
> +}
> +
> +static void
> +osinfo_install_config_param_get_property(GObject *object,
> + guint property_id,
> + GValue *value,
> + GParamSpec *pspec)
> +{
> + OsinfoInstallConfigParam *config_param =
> + OSINFO_INSTALL_CONFIG_PARAM (object);
> +
> + switch (property_id)
> + {
> + case PROP_NAME:
> + g_value_set_string(value, config_param->priv->name);
> + break;
> + case PROP_POLICY:
> + g_value_set_enum(value, config_param->priv->policy);
> + break;
> + default:
> + /* We don't have any other property... */
> + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
> + break;
> + }
> +}
> +
> +
> +static void
> +osinfo_install_config_param_finalize(GObject *object)
> +{
> + OsinfoInstallConfigParam *config_param =
> + OSINFO_INSTALL_CONFIG_PARAM(object);
> + g_free(config_param->priv->name);
> +
> + /* Chain up to the parent class */
> + G_OBJECT_CLASS (osinfo_install_config_param_parent_class)->finalize (object);
> +}
> +
> +/* Init functions */
> +static void
> +osinfo_install_config_param_class_init (OsinfoInstallConfigParamClass *klass)
> +{
> + GObjectClass *g_klass = G_OBJECT_CLASS (klass);
> + GParamSpec *pspec;
> +
> + g_klass->set_property = osinfo_install_config_param_set_property;
> + g_klass->get_property = osinfo_install_config_param_get_property;
> +
> + /**
> + * OsinfoInstallConfigParam:name:
> + *
> + * The name of the configuration parameter.
> + **/
> + pspec = g_param_spec_string("name",
> + "Name",
> + "Parameter name",
> + NULL,
> + G_PARAM_WRITABLE |
> + G_PARAM_READABLE |
> + G_PARAM_CONSTRUCT_ONLY |
> + G_PARAM_STATIC_NAME |
> + G_PARAM_STATIC_NICK |
> + G_PARAM_STATIC_BLURB);
> + g_object_class_install_property(g_klass,
> + PROP_NAME,
> + pspec);
> + /**
> + * OsinfoInstallConfigParam:policy:
> + *
> + * The policy of the configuration parameter.
> + **/
> + pspec = g_param_spec_string("policy",
> + "Policy",
> + "Parameter policy",
> + NULL,
> + G_PARAM_WRITABLE |
> + G_PARAM_READABLE |
> + G_PARAM_CONSTRUCT_ONLY |
> + G_PARAM_STATIC_NAME |
> + G_PARAM_STATIC_NICK |
> + G_PARAM_STATIC_BLURB);
> + g_object_class_install_property(g_klass,
> + PROP_POLICY,
> + pspec);
> +
> +
> + g_klass->finalize = osinfo_install_config_param_finalize;
> +
> + g_type_class_add_private (klass, sizeof (OsinfoInstallConfigParamPrivate));
> +}
> +
> +static void
> +osinfo_install_config_param_init (OsinfoInstallConfigParam *config_param)
> +{
> + OsinfoInstallConfigParamPrivate *priv;
> + config_param->priv = priv =
> + OSINFO_INSTALL_CONFIG_PARAM_GET_PRIVATE(config_param);
> +
> + config_param->priv->name = NULL;
> + config_param->priv->policy = OSINFO_INSTALL_CONFIG_PARAM_POLICY_NONE;
> +}
> +
> +
> +/**
> + * osinfo_install_config_param_new:
> + * @name: the configuration parameter name
> + * @policy: the configuration parameter policy
> + *
> + * Construct a new configuration parameter to a #OsinfoInstallScript.
> + *
> + * Returns: (transfer full): the new configuration parameter
> + */
> +OsinfoInstallConfigParam *osinfo_install_config_param_new(const gchar *name,
> + const gchar *policy)
> +{
> + return g_object_new(OSINFO_TYPE_INSTALL_CONFIG_PARAM,
> + "name", name,
> + "policy", policy,
> + NULL);
> +}
> +
> +/**
> + * osinfo_install_config_param_get_name:
> + * @config_param: the configuration parameter
> + *
> + * Returns: (transfer none): the name of the configuration parameter
> + */
> +const gchar *osinfo_install_config_param_get_name(const OsinfoInstallConfigParam *config_param)
> +{
> + return config_param->priv->name;
> +}
> +
> +/**
> + * osinfo_install_config_param_get_policy:
> + * @config_param: the configuration parameter
> + *
> + * Returns: (transfer none): the policy of the configuration parameter
> + */
> +OsinfoInstallConfigParamPolicy osinfo_install_config_param_get_policy(const OsinfoInstallConfigParam *config_param)
> +{
> + return config_param->priv->policy;
> +}
> +
> +/*
> + * Local variables:
> + * indent-tabs-mode: nil
> + * c-indent-level: 4
> + * c-basic-offset: 4
> + * End:
> + */
> diff --git a/osinfo/osinfo_install_config_param.h b/osinfo/osinfo_install_config_param.h
> new file mode 100644
> index 0000000..dce47bc
> --- /dev/null
> +++ b/osinfo/osinfo_install_config_param.h
> @@ -0,0 +1,83 @@
> +/*
> + * libosinfo: OS installation configuration
> + *
> + * Copyright (C) 2009-2012 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
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + *
> + * Authors:
> + * Fabiano Fidêncio <fabiano at fidencio.org>
> + */
> +
> +#include <glib-object.h>
> +
> +#ifndef __OSINFO_INSTALL_CONFIG_PARAM_H__
> +#define __OSINFO_INSTALL_CONFIG_PARAM_H__
> +
> +/*
> + * Type macros.
> + */
> +#define OSINFO_TYPE_INSTALL_CONFIG_PARAM (osinfo_install_config_param_get_type ())
> +#define OSINFO_INSTALL_CONFIG_PARAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_INSTALL_CONFIG_PARAM, OsinfoInstallConfigParam))
> +#define OSINFO_IS_INSTALL_CONFIG_PARAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_INSTALL_CONFIG_PARAM))
> +#define OSINFO_INSTALL_CONFIG_PARAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_INSTALL_CONFIG_PARAM, OsinfoInstallConfigParamClass))
> +#define OSINFO_IS_INSTALL_CONFIG_PARAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_INSTALL_CONFIG_PARAM))
> +#define OSINFO_INSTALL_CONFIG_PARAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_INSTALL_CONFIG_PARAM, OsinfoInstallConfigParamClass))
> +
> +typedef struct _OsinfoInstallConfigParam OsinfoInstallConfigParam;
> +typedef struct _OsinfoInstallConfigParamClass OsinfoInstallConfigParamClass;
> +typedef struct _OsinfoInstallConfigParamPrivate OsinfoInstallConfigParamPrivate;
> +
> +typedef enum {
> + OSINFO_INSTALL_CONFIG_PARAM_POLICY_NONE,
> + OSINFO_INSTALL_CONFIG_PARAM_POLICY_REQUIRED,
> + OSINFO_INSTALL_CONFIG_PARAM_POLICY_OPTIONAL,
> +} OsinfoInstallConfigParamPolicy;
> +
> +/* object */
> +struct _OsinfoInstallConfigParam
> +{
> + OsinfoEntity parent_instance;
> + /* public */
> +
> + /* private */
> + OsinfoInstallConfigParamPrivate *priv;
> +};
> +
> +/* class */
> +struct _OsinfoInstallConfigParamClass
> +{
> + OsinfoEntityClass parent_class;
> +
> + /* class members */
> +};
> +
> +GType osinfo_install_config_param_get_type(void);
> +
> +OsinfoInstallConfigParam *osinfo_install_config_param_new(const gchar *name, const gchar *policy);
> +
> +const gchar *osinfo_install_config_param_get_name(const OsinfoInstallConfigParam *config_param);
> +
> +OsinfoInstallConfigParamPolicy osinfo_install_config_param_get_policy(const OsinfoInstallConfigParam *config_param);
> +
> +
> +#endif /* __OSINFO_INSTALL_CONFIG_PARAM_H__ */
> +/*
> + * Local variables:
> + * indent-tabs-mode: nil
> + * c-indent-level: 4
> + * c-basic-offset: 4
> + * End:
> + */
> diff --git a/osinfo/osinfo_install_script.c b/osinfo/osinfo_install_script.c
> index 2d0b440..2a1dfbb 100644
> --- a/osinfo/osinfo_install_script.c
> +++ b/osinfo/osinfo_install_script.c
> @@ -47,6 +47,7 @@ G_DEFINE_TYPE (OsinfoInstallScript, osinfo_install_script, OSINFO_TYPE_ENTITY);
> struct _OsinfoInstallScriptPrivate
> {
> gchar *output_prefix;
> + GList *config_param_list;
> };
>
> enum {
> @@ -137,12 +138,12 @@ osinfo_os_get_property(GObject *object,
> }
>
>
> -
> static void
> osinfo_install_script_finalize (GObject *object)
> {
> OsinfoInstallScript *script = OSINFO_INSTALL_SCRIPT (object);
> g_free(script->priv->output_prefix);
> + g_list_free_full(script->priv->config_param_list, g_object_unref);
>
> /* Chain up to the parent class */
> G_OBJECT_CLASS (osinfo_install_script_parent_class)->finalize (object);
> @@ -216,6 +217,51 @@ osinfo_install_script_class_init (OsinfoInstallScriptClass *klass)
> g_type_class_add_private (klass, sizeof (OsinfoInstallScriptPrivate));
> }
>
> +void osinfo_install_script_add_config_param(OsinfoInstallScript *script, OsinfoInstallConfigParam *param)
> +{
> + g_return_if_fail(OSINFO_IS_INSTALL_SCRIPT(script));
> + g_return_if_fail(OSINFO_IS_INSTALL_CONFIG_PARAM(param));
> +
> + script->priv->config_param_list =
> + g_list_prepend(script->priv->config_param_list, param);
> +}
> +
> +gboolean osinfo_install_script_has_config_param(const OsinfoInstallScript *script, const OsinfoInstallConfigParam *config_param)
> +{
> + guint i, list_size = g_list_length(script->priv->config_param_list);
> +
> + for (i = 0; i < list_size; i++)
> + {
> + OsinfoInstallConfigParam *tmp;
> + tmp = g_list_nth_data(script->priv->config_param_list, i);
> +
> + if (g_strcmp0(osinfo_install_config_param_get_name(tmp),
> + osinfo_install_config_param_get_name(config_param)) == 0)
> + return TRUE;
> + }
> + return FALSE;
as discussed on IRC, this loop and the one below should look like:
for (l = the_list; l != NULL; l = l->next) {
SomeType *p = l->data;
do_something (p);
}
otherwise you'll get a quadratic behaviour.
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20120813/04722586/attachment.sig>
More information about the virt-tools-list
mailing list