Repeat construct 编辑

Repeat construct

You can use the repeat construct of a component to build multiple configuration objects of the same type.

In the following example, the members-svcg-comp component is used to bind the list of services to the service group created by the parent component. To create a configuration object that binds each server to the service group, use the repeat construct to iterate over the list of services specified for the parameter svc-servers. During the iteration, the component creates a NITRO object of the type servicegroup_servicegroupmember_binding for each service (referred to as srv in the repeat-item construct) in the service group, and it sets the ip attribute in each NITRO object to the IP address of the corresponding service.

Example:

components:
  -
      name: my-lbvserver-comp
      type: ns::lbvserver
      properties:
           name: $parameters.name + "-lb"
           servicetype: HTTP
           ipv46: $parameters.ip
           port: 80
           lbmethod: $parameters.lb-alg
           components:
-
   name: my-svcg-comp
   type: ns::servicegroup
   properties:
name: $parameters.name + "-svcgrp"
servicetype: HTTP
   components:
 -
 name: lbvserver-svg-binding-comp
 type: ns::lbvserver\servicegroup\binding
 properties:
       name: $parent.parent.properties.name
       servicegroupname: $parent.properties.name
 -
 name: members-svcg-comp
 type: ns::servicegroup\servicegroupmember\binding
 repeat:
   repeat-list: $parameters.svc-servers
   repeat-item: srv
 properties:
        ip: $srv
        port: $parameters.svc-port
        servicegroupname: $parent.properties.name
<!--NeedCopy-->

The repeat is an object by itself, and repeat-list and repeat-item are attributes for the repeat object.

  • repeat-list is a mandatory attribute that identifies the list that the component iterates on.
  • repeat-item is optional, and is used to give a friendly name to the current item in the iteration.

If not specified, the current item can be accessed using the expression $repeat-item. The last component in the above example can also be written as follows:

          -

          name: members-svcg-comp

          type: ns::servicegroup_servicegroupmember_binding

          repeat:

            repeat-list: $parameters.svc-servers

          properties:

 ip: $repeat-item

 port: $parameters.svc-port

 servicegroupname: $parent.properties.name
<!--NeedCopy-->

In addition to being able to refer to the current item white iterating over a list, it is also possible to refer to the current index of the item in the list using repeat-index. In the following example, repeat-index is used to calculate a port number based on the current index:

             name: services

             type: ns::service

             repeat:

repeat-list: $parameters.app-services

repeat-item: srv

             properties:

 ip: $parameters.app-ip

 port: $parameters.base-port + repeat-index

 servicegroupname: $parent.properties.name
<!--NeedCopy-->

Similar to the repeat-item construct, you can assign a different variable name to refer to the current index of the iteration. The previous example is equivalent to the following example:

     -

             name: services

             type: ns::service

             repeat:

repeat-list: $parameters.app-services

repeat-item: srv

repeat-index: idx

             properties:

 ip: $parameters.app-ip

 port: $parameters.base-port + $idx

 servicegroupname: $parent.properties.name
<!--NeedCopy-->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:95 次

字数:4082

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文