Skip to end of metadata
Go to start of metadata

In CoprHD/ViPR (hereinafter referred to as CoprHD), many of the configuration files (like coordinator-var.xml) contains custom information like IP addresses and other network configurations for the current deployment.

These configurations can only be specified during deployment, which means we can't generate static configuration files at build time.

Instead, CoprHD uses a simple template expansion framework to populate the config files at runtime.

How it works

The template expansion framework consists of the following parts:

  1. The template files.
  2. /etc/gentmpl script.
  3. /etc/genconfig and /etc/genconfig.d/* scripts.

Template files

The template files are named as template_name-template[.extension_name], for example, coordinator-var-template.xml and SuSEfirewall2-template.

After expansion, a new file will be generated with the name template_name[.extension_name], for example, coordinator-var.xml and SuSEfirewall2.

Rule of Thumb

If a file contains the "-template" suffix, it's a template file.

On ViPR standalones and ViPR devkit deployments however, variable expansion doesn't take place, instead we use the default static config file ( template_name[.extension_name], without the -template suffix) in the code base.

Things to Note

If you are adding contents to the template file, make sure to add the same to the default static config file and vice versa.


The /etc/gentmpl script is a python script that does the followings in turn:

  1. foreach element expansion
  2. variable substitution

Variable substitution is fairly simple, the /etc/gentmpl script get a list of space-separated key-value pairs (e.g., prop1=val1 prop2=val2) from the cmdline argument, and replace the ${variable} syntax in the template file with the actual value (e.g., ${prop1} becomes val1).

The foreach element enables us to iterate over a collection.

For example, if we provide argument --foreach:iter:1,2,3 to the /etc/gentmpl cmdline, and add the following to file config-template.xml:

<foreach iterator="iter">

After expansion, the following will be generate in the output file



The /etc/genconfig(.d/*) scripts are wrappers of the /etc/tmpl script (besides many other functionalities of course).

There's a _gen_template function in /etc/genconfig.d/genconfig-core which wraps the call to /etc/gentmpl and can be called like the following:

_gen_template <template_filename> <newline_separated_key_value_pairs>

which is exactly what we do in /etc/genconfig.d/* files like /etc/genconfig.d/coordinator.