Junos Space Developer
Junos Space Developer

configlets using variables in names

‎06-20-2019 05:42 AM



I've been trying to create a few configlets in JunOS SPACE to add for example new BGP peers.

In my configuration, I'm using a few standard naming conventions, which I'd like to keep following for readability.

I'm struggling a bit as to what I can use as variable, and what not.

For example, the AS-number of the peer, is also used in the (import) policy-statement and associated prefix-filter.


For example, an import policy would look like this:



In my variable, I would like to use something like this:

import [ NO-BOGONS_ps AS$asnumber_ps COMMUNITIES-$country-PEER_ps ];


For the AS-number, this variable will also be used for the peer-as, which is why I only want to have the number.

I just can't figure out how to change AS$asnumber_ps to AS12345_ps when the configlet is applied and the variable is entered as 12345

how can I concatenate the strings and variable?




Junos Space Developer

Re: configlets using variables in names

‎06-21-2019 02:03 AM

If I understand the issue correctly, you just need to use the formal notation for the the variables.


import [ NO-BOGONS_ps AS${asnumber}_ps COMMUNITIES-${country}-PEER_ps ];

Let me know if you require any additional assistance.

Junos Space Developer

Re: configlets using variables in names

‎06-21-2019 06:48 AM

Thanks! That has indeed solved the first problem I was having.


Now I'd like to use a selection field to select the country for example. The problem is that when using a selection field, it's automatically adding the []. Is there a way to get rid of the [] because in a statement name, these are not accepted?


Is it also possible to add a configuration line, only when a variable is filled in?

Like for example with a BGP password. Some BGP sessions use it, others don't. It would be nice to have a single configlet for both options.


Sorry, I'm new to JunOS space and the configlets.

Junos Space Developer

Re: configlets using variables in names

[ Edited ]
‎06-21-2019 08:05 AM

Sure, let me see if I can cover these additional points.


Just another point to consider.  Junos Space CLI Configlets can leverage advanced Xpath processing, this I don't believe is enabled by default, so it can be enabled via Administration|Application Settings|Network Management Platform|Modify Application Settings|CLIConfiglets|enable Advanced Xpath Processing

This feature permits more advanced CLIConfiglets, and also permits more advanced SLAX script functionality within Junos Space.  So I would suggest that you enable this feature if it isn't already as it will allow for more advanced CLI Configlets.


Selection lists:  So, if you have a custom defined selection list variable for example ${country}, and that contains a list of countries.  If the user selects one of those items, you can then reference that within your configlet test by using: 



We have to use .get(0) because the selection list returns not a string, but an array that contains the selected item.  Since arrays start at position 0, we use .get(0) 

IIRC, JunosSpace doesn't support multiple selected items from a selection list, and therefore you can probably always get away with using .get(0) whenever handling a selection list.


Loigic based on variables.  Yes, the scripting language used by Junos Space for CLI Configlets (VTL - Velocity Template Language) supports conditionals.  So you could include logic e.g.


## In the case of a variable containing a selected value from a list
## .get(0) returns the selected value from the array
#if ( ${country}.get(0) == "Netherlands" ) ..... #elseif ( ${country}.get(0) == "Belgium" ) ..... #else #terminate ( "<p>Country not supported!</p>" ) #end
## Or in the case of a variable that contains a string...
#if ( ${bgp_pass} != "" )
bgp {

So, this example introduces some VTL directives, (#if, #elseif, #else, #end and a special JunosSpace specific directive #terminate).

If you use if/elseif/else then the logic must be terminated with the #end directive.  The #terminate directive is a Junos Space specific feature, that allows you to terminate a CLI configlet from progressing any further.  So in this example, I'm expecting the country that has been selected to be either Belgium or the Netherlands, and if a different country is selected then the CLI configlet will terminate and not even produce the configuration text.


Hope that this helps.


Junos Space Developer

Re: configlets using variables in names

‎06-23-2019 03:08 AM

Wow, thanks asharp!


I got it working now. Just needed to do ${country.get(0)} to get it working in a name of a statement.


Your reply is much appreciated!