Application Delivery Management

创建复合样本

样本一个重要的强大功能是它们可以用作其他样本的构建块。样本可以导入到另一个样本中,它可以被称为第二个样本的组件使用的类型,类似于 Nitro 内置样本。

例如,您可以使用上一节中构建的 基本 lb-config样书来构建另一个名为 复合示例的样书。要使用“basic-lb-config”样书,必须在新样书的 import-stylebooks 部分将其导入。

构建您的样本

新样本类似如下:

name: composite-example
namespace: com.example.stylebooks
version: "0.1"
display-name: Load Balancing Virtual Server (HTTP/RoundRobin)
description: This StyleBook defines a RoundRobin load balancing configuration with a monitor.
schema-version: "1.0"
import-stylebooks:
  -
   namespace: netscaler.nitro.config
   version: "10.5"
   prefix: ns
  -
   namespace: com.example.stylebooks
   version: "0.1"
   prefix: stlb
parameters:
  -
    name: name
    type: string
    label: Application Name
    description: Give a name to the application configuration.
    required: true
  -
    name: ip
    type: ipaddress
    label: Application Virtual IP (VIP)
    description: The Application VIP that clients access
    required: true
  -
    name: svc-servers
    type: ipaddress[]
    label: Application Server IPs
    description: The IP addresses of all the servers of this application
    required: true

  -
    name: response-code
    type: string[]
    label: List of Response Codes
    description: List of Response Codes - Provide a list of response codes in integer.

components:
  -
    name: basic-lb-comp
    type: stlb::basic-lb-config
    description: This component's type is another StyleBook that builds the NetScaler lbvserver, servicegroups and services configuration objects.
    properties:
     name: $parameters.name
     ip: $parameters.ip
     svc-servers: $parameters.svc-servers
  -
     name: monit-comp
     type: ns::lbmonitor
     description: This component is a basic Nitro type (a Builtin StyleBook) that builds the NetScaler monitor configuration object.
     properties:
       monitorname: $parameters.name + "-mon"
       type: HTTP
       respcode: $parameters.response-code
       httprequest: "'GET /'"
       lrtm: ENABLED
       secure: "YES"

     components:
        -
          name: monit-svcgrp-bind-comp
          type: ns::servicegroup_lbmonitor_binding
          properties:
            servicegroupname: $components.basic-lb-comp.outputs.servicegroup-comp.properties.servicegroupname
            monitor_name: $parent.properties.monitorname
<!--NeedCopy-->

在 import-stylebooks 部分,使用 basic-lb-config 样书的命名空间和版本将其导入,引用时加前缀“stlb”。

在 components 部分,定义了两个组件。第一个组件的类型为 stlb:: basic-lb-config,其中 “basic-lb-config” 是您在样书中为创建 基本负载平衡配置而创建的样书的名称。为此组件定义的数据对应于 basic-lb-config 样本中声明的必需参数。但是,您可以使用样本的任何参数(必填参数和可选参数)。 而不是重新构建 lbvserver、服务组以及服务和服务组绑定,而是导入样本作为组件执行所有这些操作的样本,并使用它在新样本中创建这些配置对象。

样书添加第二个组件“monit-comp”(使用 Nitro 资源“lbmonitor”(内置样书)的属性)来创建监视器配置对象。它还有子组件“monit-svcgrp-bind-comp”用来创建绑定配置对象,该对象将监视器绑定到第一个组件中创建的服务组。由于在 “基本 Lb-config” 样本中创建的服务组组件作为输出显示,因此此样本可以使用表达 式 $组件 .basents.lb-comp.outputs.Servicegroup-comp访问它。此示例说明导入样本如何能够使用 outputs 部分来访问原本无法访问的被导入样本中的组件。

接下来,将样本内容复制并粘贴到文本编辑器,然后将该文件另存为 合成,example.yaml。在 Citrix ADM 中导入文件之前,请确保验证 YAML 内容。然后,将其导入 Citrix ADM 并使用此样本创建一个或多个配置。

Citrix 建议您使用样本中的内置 YAML 验证程序来验证和导入 YAML 内容。

创建复合样本