参数-默认源代码构造
可以使用此构造来重用其他样书中的参数定义。
假设这样一个场景:一个参数或一组参数在多个样书中重复使用。为了避免重新定义这些参数,每次要创建新样书时,可以将其定义一次,然后使用 parameters-default-sources 构造将其定义导入需要这些参数的样书。
例如,如果多个样本需要配置虚拟 IP,可能必须在创建的每个新样本中定义与虚拟 IP 有关的相同参数。相反,您可以创建一个名为的单独样书,例如 vip-params
,您可以在其中定义与其相关的所有参数,如以下示例所示:
-
name: vip-params
namespace: com.acme.commontypes
version: "1.0"
description: This StyleBook defines a typical virtual IP config.
private: true
schema-version: "1.0"
parameters:
-
name: lb-appname
label: Load Balanced Application Name
description: Name of the Load Balanced application
type: string
required: true
-
name: lb-virtual-ip
label: Load Balanced App Virtual IP address
description: Virtual IP address representing the Load Balanced application
type: ipaddress
required: true
-
name: lb-virtual-port
label: Load Balanced App Virtual Port
description: TCP port representing the Load Balanced application
type: tcp-port
default: 80
-
name: lb-service-type
label: Load Balanced App Protocol
description: Protocol used for the Load Balanced application.
type: string
default: HTTP
required: true
allowed-values:
- HTTP
- SSL
- TCP
<!--NeedCopy-->
然后,您可以使用这些参数创建其他样书
-
name: acme-biz-app
namespace: com.acme.stylebooks
version: "1.0"
description: This stylebook defines the NetScaler configuration for Biz App
schema-version: "1.0"
import-stylebooks:
-
namespace: com.acme.commontypes
prefix: cmtypes
version: "1.0"
\*\*parameters-default-sources:\*\*
** - cmtypes::vip-params**
parameters:
-
name: monitorname
label: Monitor Name
description: Name of the monitor
type: string
required: true
-
name: type
label: Monitor Type
description: Type of the monitor
type: string
required: true
allowed-values:
- PING
- TCP
- HTTP
- HTTP-ECV
- TCP-ECV
- HTTP-INLINE
<!--NeedCopy-->
首先,在样书 acme-biz-app
中,使用“import-stylebooks”部分导入 vip-params
样书的命名空间和版本。然后添加 parameters-default-sources 构造,并指定样书名称,即 vip-params
。此参数与直接在此样书中定义 vip-params
样书的参数具有相同的效果。
由于 parameters-default-sources 是一个列表,且列表中的每个项目都需要是一个样本,因此可以包括多个样本中的参数。
除了包括其他样书中的参数外,还可以使用 parameters 部分定义您自己的参数。样书的完整参数列表是从其他样书中添加的参数和此样书中定义的参数的组合。因此,表达式 $parameters 是指此参数组合。
如果在导入的样书和当前样书中都定义了参数,则当前样书中的定义将覆盖从另一个样书导入的定义。如有必要,您可以通过自定义一些导入的参数来有效地使用此方法,同时使用其余导入的参数。
parameters-default-sources 构造还可以用于嵌套的参数中,如下所示:
parameters:
-
name: vip-details
label: Virtual IP details
description: Details of the Virtual IP
type: object
required: true
parameters-default-sources:
- cmtypes::vip-params
<!--NeedCopy-->
这种方法类似于将样书 vip-params
的参数直接添加为此样书中 vip-details
参数的子参数。