Template Variables.

Is there a list of variables available so that I can get correct syntax? documentation only describes the use of variables, not what they are. I cannot efficiently create templates without this critical information. 

Are you refrerring to replacement variables or the configuration variables/settings that are used by the device itself.

Replacement variables are user-defined in order to insert device-specific values into a template before being sent to a device.

The configuration variables/settings that are used by the device itself are specific to the product line.  Which device type(s) are you trying to configure?

1 Like

It would be a list of replacement variables for ePMP3000 setup. Not clear how to form the correct syntax. 

Replacement variables are user-defined, so there is no set list of them.  You can use whatever string you want for the variable name.  There are two formats:

No default value:

${VARIABLE_NAME}

Default value specified:

${VARIABLE_NAME=123}

These replacement variables can be used anywhere in your templates in order to insert device-specific values.  For replacement variables without default values, an error will be thrown if a device-specific value is not specified when applying the template.  If a default value is provided with no device-specific value, then the default value is used.

Everything between the dollar sign $ and closed curly bracket } will be replaced with either a device-specific or default value before sending the configuration template to the device.

Example for setting ePMP network settings:

{
    "device_props": {
        "networkMode": "2",
        "networkBridgeIPAddressMode": "1",
        "networkBridgeIPAddr": "${IP_ADDRESS}",
        "networkBridgeNetmask": "255.255.255.0",
        "networkBridgeGatewayIP": "10.1.1.254",
        "networkBridgeDNSIPAddrPrimary": "10.1.2.30",
        "networkBridgeDNSIPAddrSecondary": "10.1.2.31"
    }
}

The template will force you to set a value for "IP_ADDRESS" for each device you apply the template on since there is no default value.

Trivial example with a default value:

{
"device_props": {
	"httpPort": "${FOO=80}"
}

}

In this template the HTTP port will be set to 80 for any device it is applied on unless a device-specific value is set against the device.  This is done in the device level configuration page or by clicking the gear icon at the far right of the higher level table-based configuration views.

What would be sent to a device if no device-specific value is specified:

{
"device_props": {
	"httpPort": "80"
}

}

I’d like to add some things I’ve found out while trying out template variables where the documentation is not 100% clear. When building a JSON template config file, like those from PMP 450, the ${…} notation needs to be completely inside double quotes (") if the value the config expects is a string, and without any quotes if the value it expects is a number or boolean. Examples below.

An IP address is a string, so you would write it like this:
“networkBridgeIPAddr”: “${IP_ADDRESS=10.1.2.3}”

Or, without a default value, like this:
“networkBridgeIPAddr”: “${IP_ADDRESS}”

If the value is a boolean or a number, there will be no double quotes.
“bridgeTableSize”: ${TABLE_SIZE}

Or, with a default value, like so:
“bridgeTableSize”: ${TABLE_SIZE=4}

Notice that this last notation, the one where the ${…} notation is not between double quotes, makes it so the config file template is not in valid JSON format. Knowing this, and following this format, has made it so every config file template with variables that I have made have been accepted by the devices. I had issues where the device would not accept the config file before I found this out, even if cnMaestro accepted the template and understood it.

Hope this helps someone.

3 Likes

Thank you for posting this information with examples @aerojean. I hope this helps others using replacement variables.

cnMaestro just does a complete replacement of the ${VARIABLE} text so you can get really creative with it beyond just parameter values if you have the need. For example, adding entire lines to the template. This may be more useful for text-based templates like cnPilot Home but it does give a lot of options.