Product Documentation

Nested repeats

May 24, 2018

With the nested repeat construct you can have more than one repeat construct in each component depending on the definition of the component. Consider a nested repeat of two levels. For each element in the outer list (first repeat-list), you can create a repeat list for all elements of the inner list (second repeat-list). The StyleBook compiler supports up to three nested repeats. Each repeat level has repeat-item and repeat-index attributes associated with it. Both repeat-item and repeat-index attributes are optional. In addition, each repeat can also specify a repeat-condition.

Example

parameters:

  -

      name: vips

      type: ipaddress[]

  -

      name: vip-ports

      type: tcp-port[]

components:

  -

      name: lbvservers-comp  

      type: ns::lbvserver

      repeat:

         repeat-list: $parameters.vips

         repeat-item: ip

         repeat:

              repeat-list: $parameters.vip-ports

              repeat-item: port

      properties:

         name: str("lb-") + str($ip) + '-' + str($port)

         servicetype: HTTP

         ipv46: $ip

         port: $port

In the above example, for each item in $parameters.vips, we iterate over all items of $parameters.vip-ports. Thus, for each ipaddress specified in $parameters.vips, we create lbvserver configuration objects for all ports specified in $parameters.vip-ports. The properties section define the name of the object with "lb" as a prefix for the combination of the IP address and the port. Therefore, for each iteration, $ip + $port defines a unique combination of the IP address and the port number.

If repeat-item attribute is not provided, the compiler generates a default value for it. The default values for repeat-item are: $repeat-item,  $repeat-item-1, $repeat-item-2 respectively for each repeat level. Similarly, if repeat-index attribute is not provided, the compiler generates a default value for it. The default values for repeat-index are: $repeat-index, $repeat-index-1, and $repeat-index-2 respectively for each repeat level.

The following example describes the naming convention in the absence of repeat-item and repeat-index attributes in a nested repeat object.

Example

components:

-

     name: lbvservers-comp  

     type: ns::lbvserver

     repeat:

         repeat-list: $parameters.vips

        repeat:

             repeat-list: $parameters.vip-ports

     properties:

        name: str("lb-") + str($repeat-item) + '-' + str($repeat-item-1)

        servicetype: HTTP

        ipv46: $repeat-item

        port: $repeat-item-1