VoyenceControl: How can I split a delimited list of values and perform the same action on each separate value in a template?
search cancel

VoyenceControl: How can I split a delimited list of values and perform the same action on each separate value in a template?

book

Article ID: 303474

calendar_today

Updated On:

Products

VMware

Environment

VMware Smart Assurance - NCM

Resolution

How can I use VoyenceControl to split a delimited list of values and perform the same action on each separate value in a template?



VoyenceControl supports some very basic Velocity-style syntax (see Note statements) to provide the string manipulation logic required to accomplish this task. This functionality allows you to split a delimited list of values and perform the same action on each separate value.

Example
As an example, consider a situation where you have a list of addresses that need to be added to a configuration in some way one at a time:

logging myLoggingHost1
...
logging myLoggingHostN

To accomplish this you could use a single template variable with a delimited list of addresses, then use Velocity syntax to split on the delimiter and action each separate address (see Note statements):

## specify a special variable to hold the delimiter so we can reuse it and only have to change it in one spot
## this delimiter is a regex pattern that looks for 1 or more common delimiters (semi-colon, comma and space)
#
set ($DELIM = "[;, ]+")

## get a new reference to the template variable's content
#set ($list = "<<myLoggingHostsList>>")

## now to split the list and action each separate address
#foreach ($address in $list.split($DELIM))
logging $address
#end

If you provide the following list to the variable <<myLoggingHostsList>>:

192.168.10.10, 172.17.8.10, 10.10.21.10

The output would be:

logging 192.168.10.10
logging 172.17.8.10
logging 10.10.21.10



Additional Information

The above example has been annotated using Velocity-style comments, or "##".  These lines can be removed from the example.
Spacing is very important when using Velocity-style syntax in templates.  Take special note of the spaces around parentheses, conditional values and operators.  Take note of the lack of spaces after the number signs.

Apache Velocity (formerly known as Jakarta Velocity) is an open source software project directed by the Apache Software Foundation. Velocity is a Java-based template engine that provides a simple yet powerful template language to reference objects defined in Java code.  There are many resources available on the web that go into further detail concerning syntax and code examples.