参数条件
参数条件用于修改 StyleBook 定义中某些参数的行为。StyleBook 定义中的参数是创建配置包时提供的输入。使用 parameters-conditions 在定义中定义参数条件。
StyleBook 定义中的参数可以有许多约束。当用户更改参数行为时,参数条件用于解决冲突。例如,当用户选择 SSL 协议时,需要证书详细信息才能创建配置包。但是,证书详细信息最初可能未设置为必填字段。
参数条件具有以下属性:
-
target:指定要对其应用操作的目标参数。您可以指定多个目标参数。 -
action:指定要对目标参数执行的操作。参数条件支持以下操作: -
condition:可选,指定一个条件以对指定的目标参数应用操作。如果您未指定条件,则操作将直接应用于目标参数。 -
value:根据操作设置目标参数属性的值。
注意
目前,参数条件无法应用于列表对象中的参数。
“show”或“hide”
当操作为 show 且指定条件返回 True 时,目标参数将显示在 GUI 上。
当操作为 hide 且指定条件返回 True 时,目标参数将从 GUI 上消失。
示例:
parameters-conditions:
-
target: $parameters.security-settings.cert-details
action: show
condition: $parameters.protocol in ["SSL", "SSL-BRIDGE"]
<!--NeedCopy-->
最初,security-settings 参数的证书详细信息是隐藏的。当用户选择 SSL 或 SSL-Bridge 协议时,证书详细信息将显示。
“set-default”
当操作为 set-default 且指定条件返回 True 时,目标参数的值将设置为默认值。
示例 1:
parameters-conditions:
-
target: $parameters.port
action: set-default
condition: $parameters.protocol == "SSL"
value: 443
-
target: $parameters.port
action: set-default
condition: $parameters.protocol != "SSL"
value: 80
<!--NeedCopy-->
示例 2:
parameters-conditions:
-
target: $parameters.port
action: set-default
value: if-then-else($parameters.protocol == "SSL", 443, 80)
<!--NeedCopy-->
当用户选择 SSL 协议时,默认端口值设置为 443。对于其他协议,默认端口值设置为 80。示例 1 和示例 2 产生相同的结果。
“set-required”
当操作为 set-required 且指定条件返回 True 时,目标参数将成为创建配置包的必填字段。
parameters-conditions:
-
target: $parameters.security-settings.cert-details
action: set-required
condition: $parameters.protocol in ["SSL", "SSL-BRIDGE"]
<!--NeedCopy-->
最初,security-settings 参数的证书详细信息可能不是必需的。当用户选择 SSL 或 SSL-Bridge 协议时,证书详细信息将成为创建配置包的必填字段。
“set-allowed-values”
当操作为 set-allowed-values 且指定条件返回 True 时,目标参数将只允许您选择指定的值。
示例:
parameters-conditions:
-
target: $parameters.app-name
action: set-allowed-values
value:
- "SSL"
condition: $parameters.lb-virtual-port == 443
<!--NeedCopy-->
当用户将 443 指定为负载均衡虚拟端口时,应用程序名称将只允许 SSL 选项。
“set-label”
当操作为 set-label 且指定条件返回 True 时,目标参数的标签将更改为指定的文本。
示例:
parameters-conditions:
-
target: $parameters.app-name
action: set-label
value: if-then-else($parameters.lb-service-type == "TCP", "TCPApp","UDPApp")
<!--NeedCopy-->
当用户选择负载均衡协议为 TCP 时,应用程序的标签将更改为 TCPApp。如果用户选择其他选项,应用程序的标签将更改为 UDPApp。
“set-description”
当操作为 set-description 且指定条件返回 True 时,目标参数的描述将更改为指定的文本。此描述将显示在目标参数的工具提示中。
示例:
parameters-conditions:
-
target: $parameters.app-name
action: set-description
value: if-then-else($parameters.lb-service-type == "TCP", "Select a TCP application name","Select a UDP application name")
<!--NeedCopy-->
当用户选择负载均衡协议为 TCP 时,应用程序的工具提示将显示文本:Select a TCP application name。如果用户选择其他选项,应用程序的描述将显示 Select a UDP application name。
“collapse-pane”或“expand-pane”
当操作为 collapse-pane 且指定条件返回 True 时,目标参数的窗格将在 GUI 中折叠。
当操作为 expand-pane 且指定条件返回 True 时,目标参数的窗格将在 GUI 中展开。
示例:
parameters-conditions:
-
target: $parameters.security-settings.cert-details
action: expand-pane
condition: $parameters.protocol in ["SSL", "SSL-BRIDGE"]
<!--NeedCopy-->
最初,security-settings 参数的证书详细信息窗格可能未展开。当用户选择 SSL 或 SSL-Bridge 协议时,证书详细信息窗格将在 GUI 上展开。
“set-pattern”
当操作为 set-pattern 且指定条件返回 True 时,目标参数字段将设置为指定的模式。
示例:
parameters-conditions:
-
target: $parameters.app-name
action: set-pattern
value: "[a-z]+"
<!--NeedCopy-->
在此示例中,应用程序名称只允许小写字母字符。
嵌套参数条件
在 StyleBook 定义中,您可以在参数条件中指定参数条件。这些条件称为嵌套参数条件,并使用重复构造来定义这些条件。当您想要从另一个参数为某个参数应用操作时,嵌套参数条件非常有用。
示例:
parameters-conditions:
-
repeat: $parameters.lbvservers
repeat-item: lbvserver
parameters-conditions:
-
target: $lbvserver.port
action: set-allowed-values
condition: $lbvserver.protocol == "HTTPS"
value: $parameters.ssl-ports
<!--NeedCopy-->
在此示例中,当用户为负载均衡虚拟服务器选择 HTTPS 协议时,端口值将动态填充。并且,它适用于列表中的每个负载均衡虚拟服务器。