This content has been machine translated dynamically.
Dieser Inhalt ist eine maschinelle Übersetzung, die dynamisch erstellt wurde. (Haftungsausschluss)
Cet article a été traduit automatiquement de manière dynamique. (Clause de non responsabilité)
Este artículo lo ha traducido una máquina de forma dinámica. (Aviso legal)
此内容已经过机器动态翻译。 放弃
このコンテンツは動的に機械翻訳されています。免責事項
이 콘텐츠는 동적으로 기계 번역되었습니다. 책임 부인
Este texto foi traduzido automaticamente. (Aviso legal)
Questo contenuto è stato tradotto dinamicamente con traduzione automatica.(Esclusione di responsabilità))
This article has been machine translated.
Dieser Artikel wurde maschinell übersetzt. (Haftungsausschluss)
Ce article a été traduit automatiquement. (Clause de non responsabilité)
Este artículo ha sido traducido automáticamente. (Aviso legal)
この記事は機械翻訳されています.免責事項
이 기사는 기계 번역되었습니다.책임 부인
Este artigo foi traduzido automaticamente.(Aviso legal)
这篇文章已经过机器翻译.放弃
Questo articolo è stato tradotto automaticamente.(Esclusione di responsabilità))
Translation failed!
表达式
样本其中一个最强大的功能是使用表达式。可以在各种方案中使用样本表达式来计算动态值。下面的示例显示了一个将参数值与文字字符串连接的表达式。
示例:
$parameters.appname + “-mon”
此表达式检索名为 appname 的参数,并将其与字符串 “-mon” 连接。
支持以下类型的表达式:
算术表达死
- 添加 (+)
- 减法 (-)
- 乘法 (*)
- 司 (/)
- 模数 (%)
示例:
- 添加两个数字:$parameters.a + $parameters.b
- 乘以两个数字:$parameters.a * 10
- 在一个数字除以另一个数字后查找剩余数字:
15 % 10 结果为 5
字符串表达式
- 连接两个字符串 (+)
示例:
连接两个字符串:str(“app-“) + $parameters.appname
列表表达式
合并两个列表 (+)
示例:
-
连接两个列表:$parameters.external-servers + $parameters.internal-servers
-
如果 $parameters.ports-1 为 [80, 81],$parameters.port-2 为 [81, 82],则 $parameters.ports-1 + $parameters.ports-2 的结果为 [80, 81, 81, 82] 的列表
关系表达式
-
== :测试两个操作数是否相同,如果相同,则返回 true,否则返回 false。
-
!= :测试两个操作数是否不同,如果不同,则返回 true,否则返回 false。
-
:如果第一个操作数大于第二个操作数,则返回 true,否则返回 false。
-
= :如果第一个操作数大于或等于第二个操作数,则返回 true,否则返回 false。
-
< :如果第一个操作数小于第二个操作数,则返回 true,否则返回 false。
- <= :如果第一个操作数小于或等于第二个操作数,则返回 true,否则返回 false。
示例:
- 使用等号运算符:$parameters.name = = “abcd”
- 使用不等号运算符:$parameters.name != “default”
- 其他关系运算符示例
- 10 > 9
- 10 >= 10
- 0 < 9
- 10 <= 9
- 10 == 10
- 10 != 1
逻辑(布尔)表达式
-
and:逻辑“与”运算符。如果两个操作数为 true,则结果为 true,否则为 false。
-
or:逻辑“或”运算符。如果其中一个操作数为 true,则结果为 true,否则为 false。
-
not:一元运算符。如果操作数为 true,则结果为 false,反之亦然。
-
在:测试第一个参数是否是第二个参数的子字符串
-
在:测试项目是否是列表的一部分
注意
您可以键入转换表达式,通过使用这种表达式,字符串转换可以为数字,数字可以转换为字符串。同样,tcp-port 可以转换为数字,IP 地址可以转换为字符串。
必须在任何运算符前后使用分隔符。可以使用以下分隔符:
在运算符前面:空格、Tab、逗号、(、)、[、]
在运算符后面:空格、Tab、(、[
例如:
abc + def
100 % 10
10 > 9
表达式类型验证
样本引擎现在允许在编译期间进行增强的类型检查,即,在导入样本本身的过程中,而不是在创建配置包时,验证编写样本时使用的表达式,
对参数、替换、组件、组件属性、组件输出、用户定义的变量(重复项、重复索引、替代函数的参数等)的所有引用都会根据它们的存在和类型进行验证。
类型检查示例:
在以下示例中,lbvserver 样本的预期 port 属性类型为 tcp-port。在 Citrix Application Delivery Management (ADM) 早期版本中,样本编译器将该值计算为字符串,并导入并执行样本。现在,在编译时(导入时)进行类型验证。编译器发现 string 和 tcp-port 不是兼容的类型,因此样本编译器抛出错误,且样本导入或迁移失败。
components:
-
name: lbvserver-comp
type: ns::lbvserver
properties:
name: mylb
ipv46: 10.102.190.15
port: str("80")
servicetype: HTTP
You should now declare this as a number for the compiler to successfully compile this StyleBook.
port: 80
<!--NeedCopy-->
标记无效表达式的示例:
在早期版本中,当将无效表达式分配给属性名称时,编译器未检测到无效表达式,并允许将样本导入 Citrix ADM。现在,如果将此样本导入到 Citrix ADM,编译器将识别此类无效表达式并将其标记为。因此,样本不会导入到 Citrix ADM。
在此示例中,为 lb-sg-binding-comp 组件中的 name 属性分配的表达式为:$components.lbvserver-comp.properties.lbvservername。但组件 lbvserver-comp 中没有称为 lbvservername 的属性。在早期的 Citrix ADM 版本中,编译器将允许此表达式并成功导入该表达式。当用户要使用此样本创建配置包时,实际上会失败。但是现在,在导入过程中会识别此类错误,并且样本不会导入到 Citrix ADM。您必须手动更正此类错误并导入样本。
components:
-
name: lbvserver-comp
type: ns::lbvserver
properties:
name: mylb
ipv46: 10.102.190.15
port: 80
servicetype: HTTP
-
name: sg-comp
type: ns::servicegroup
properties:
servicegroupname: mysg
servicetype: HTTP
-
name: lb-sg-binding-comp
type: ns::lbvserver_servicegroup_binding
condition: $parameters.create-binding
properties:
name: $components.lbvserver-comp.properties.lbvservername
servicegroupname: $components.sg-comp.properties.servicegroupname
<!--NeedCopy-->
为列表建立索引
现在,可以直接为列表中的项目建立索引来访问它们:
| | | | ——————————————————————————- | ———————————————————————————————————————————————- | | 表达式 | 说明 | | $components.test-lbs[0] | 引用 test-lbs 组件中的第一个项目 | | $components.test-lbs[0].properties.p1 | 引用 test-lbs 组件中的第一个项目的属性 p1 | | $components.lbcomps[0].outputs.servicegroups[1].properties.servicegroupname | 引用 servicegroups 组件中的第二个项目的属性 servicegroupname,这是 lbcomps 组件的第一个项目的输出。 | |
This Preview product documentation is Citrix Confidential.
You agree to hold this documentation confidential pursuant to the terms of your Citrix Beta/Tech Preview Agreement.
The development, release and timing of any features or functionality described in the Preview documentation remains at our sole discretion and are subject to change without notice or consultation.
The documentation is for informational purposes only and is not a commitment, promise or legal obligation to deliver any material, code or functionality and should not be relied upon in making Citrix product purchase decisions.
If you do not agree, select Do Not Agree to exit.