Expressions

July 18, 2019

Contributed by:
C

One of the most powerful features of StyleBook is the use of expressions. You can use StyleBooks expressions in various scenarios to compute dynamic values. The example below shows an expression to concatenate a parameter value with a literal string.

Example:

$parameters.appname + “-mon”

This expression retrieves the parameter named appname, and concatenates it with the string “-mon”.

List Expressions

If $parameters.ports-1 is [80, 81] and $parameters.port-2 is [81, 82], then $parameters.ports-1 + $parameters.ports-2 results as a list [80, 81, 81, 82]

Relational Expressions

== : Tests if two operands are equal and returns true if they are equal, else returns false.

!= : Tests if two operands are different and returns true if they are different, else returns false.

> : Returns true if the first operand is greater than the second operand, else returns false.

>= : Returns true if the first operand is greater than or equal to the second operand, else returns false.

< : Returns true if the first operand is lesser than the second operand, else returns false.

<= : Returns true if the first operand is lesser than or equal to the second operand, else returns false.

Example:

Use of Equality operator: $parameters.name = = “abcd”

Use of Inequality operator: $parameters.name != “default”

Examples for other relational operators

10 > 9

10 >= 10

0 < 9

10 <= 9

10 == 10

10 != 1

Logical (Boolean) Expressions

and: The logical ‘and’ operator. If both operands are true, the result is true, else it is false.

or: The logical ‘or’ operator. If one of the operands is true, the result is true, else it is false.

not: The unary operator. If the operand is true, the result is false, and vice-versa.

in: Tests whether the first argument is a substring of the second argument

in: Tests if an item is part of a list

Note

You can type cast expressions where strings can be converted into numbers and numbers can be converted to strings. Similarly, a tcp-port can be cast to a number, and an IP address can be cast to a string.

You must use a delimiter before and after any operator. You can use the following delimiters:

Before an operator: space, tab, comma, (, ), [, ]

After an operator: space, tab, (, [

For example:

abc + def

100 % 10

10 > 9

Expression Type Validation

StyleBook engine now allows for stronger type checking during compile time, that is, the expressions used while writing the StyleBook are validated during the import of StyleBook itself rather than while creating the configuration pack.

All references to parameters, substitutions, components, properties of components, outputs of components, user-defined variables (repeat-item, repeat-index, arguments to substitution functions,) and so on are all validated for their existence and types.

Example of Type Checks:

In the following example, the expected type of port property of lbvserver StyleBook is tcp-port. In Citrix Application Delivery Management (ADM) earlier releases, the StyleBook compiler computed the value as a string and the StyleBook was imported and executed. Now, type validations happen at compile-time (import-time). The compiler finds that string and tcp-port are not compatible types and therefore, the StyleBook compiler throws an error and fails import or migration of the StyleBook.

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

Example of Flagging Invalid Expressions:

In earlier releases, when an invalid expression was assigned to a property name, the compiler did not detect invalid expressions and allowed the StyleBooks to be imported into Citrix ADM. Now if this StyleBook is imported to Citrix ADM, the compiler will identify such invalid expressions and flag it. As a result, the StyleBook will not be imported to Citrix ADM.

In this example, the expression assigned to name property in lb-sg-binding-comp component is: $components.lbvserver-comp.properties.lbvservername. However, there is no property called lbvservername in component lbvserver-comp. In earlier Citrix ADM releases, the compiler would have allowed this expression and successfully imported it. The actual failure would happen when a user wants to create a configuration pack using this StyleBook. However now, this kind of error is identified during import and the StyleBook is not imported to Citrix ADM. You must manually correct such errors and import the StyleBooks.

Refers to property servicegroupname of the second item in servicegroups component, which is an output from the first item of lbcomps component

The official version of this content is in English. Some of the Citrix documentation content is machine translated for your convenience only. Citrix has no control over machine-translated content, which may contain errors, inaccuracies or unsuitable language. No warranty of any kind, either expressed or implied, is made as to the accuracy, reliability, suitability, or correctness of any translations made from the English original into any other language, or that your Citrix product or service conforms to any machine translated content, and any warranty provided under the applicable end user license agreement or terms of service, or any other agreement with Citrix, that the product or service conforms with any documentation shall not apply to the extent that such documentation has been machine translated. Citrix will not be held responsible for any damage or issues that may arise from using machine-translated content.

THIS SERVICE MAY CONTAIN TRANSLATIONS POWERED BY GOOGLE. GOOGLE DISCLAIMS ALL WARRANTIES RELATED TO THE TRANSLATIONS, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF ACCURACY, RELIABILITY, AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

THIS SERVICE MAY CONTAIN TRANSLATIONS POWERED BY GOOGLE. GOOGLE DISCLAIMS ALL WARRANTIES RELATED TO THE TRANSLATIONS, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF ACCURACY, RELIABILITY, AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

THIS SERVICE MAY CONTAIN TRANSLATIONS POWERED BY GOOGLE. GOOGLE DISCLAIMS ALL WARRANTIES RELATED TO THE TRANSLATIONS, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF ACCURACY, RELIABILITY, AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

THIS SERVICE MAY CONTAIN TRANSLATIONS POWERED BY GOOGLE. GOOGLE DISCLAIMS ALL WARRANTIES RELATED TO THE TRANSLATIONS, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF ACCURACY, RELIABILITY, AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

THIS SERVICE MAY CONTAIN TRANSLATIONS POWERED BY GOOGLE. GOOGLE DISCLAIMS ALL WARRANTIES RELATED TO THE TRANSLATIONS, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF ACCURACY, RELIABILITY, AND ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.