Application Delivery Management

创建复合 StyleBook

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

例如,您可以使用在上一节中构建的 basic-lb-config StyleBook 来构建另一个名为 composite-example 的 StyleBook。要使用“basic-lb-config” StyleBook,您必须将其导入到新 StyleBook 的 import-stylebooks 部分。

构建您的 StyleBook

新的 StyleBook 如下所示:

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 StyleBook 的命名空间和版本,并使用前缀“stlb”引用它来导入该 StyleBook。

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

StyleBook 添加了第二个组件“monit-comp”,该组件使用 Nitro 资源“lbmonitor”(一个内置 StyleBook)的属性来创建监视器配置对象。它还有一个子组件“monit-svcgrp-bind-comp”,用于创建绑定配置对象,该对象将监视器绑定到在第一个组件中创建的服务组。由于在“basic-lb-config” StyleBook 中创建的服务组组件作为输出公开,因此此 StyleBook 可以使用表达式 $components.basic-lb-comp.outputs.servicegroup-comp 访问它。这是一个示例,说明导入 StyleBook 如何使用 outputs 部分来访问导入 StyleBook 中的组件,否则它们将无法访问这些组件。

接下来,将 StyleBook 内容复制并粘贴到文本编辑器中,然后将文件另存为 composite-example.yaml。在将文件导入 NetScaler Console 之前,请务必验证 YAML 内容。然后,将其导入 NetScaler Console 并使用此 StyleBook 创建一个或多个配置。

我们建议您使用 StyleBook 中内置的 YAML 验证器来验证和导入 YAML 内容。

创建复合 StyleBook