Using expressions in Cloud Provisioning and Governance
Expressions in policy actions can set or override values. Expressions in blueprints can access attributes of resources and can map values to request form fields. Expressions are available in resource blocks, blueprints, policies, and anywhere that Cloud Provisioning and Governance allows scripts.
Using expressions
Expressions can hold the values for information that is dynamically generated in the system, such as the values for the selections users make on the Cloud User Portal. Expressions are available in resource blocks, blueprints, policies, and anywhere that Cloud Provisioning and Governance allows scripts.
- Using expressions in resource blocks
Each resource block operation uses an expression to hold a value for each parameter. The expression can use hard-coded values, data from the stack that the user provisions in the Cloud User Portal, data in the CMDB, and data that is derived from scripts. By default, Cloud Provisioning and Governance generates a set of parameters and their expressions for each resource block operation.
For example, the parameter Location, which holds the datacenter that a resource belongs to, uses the expression
${parameter.Location}Figure 1. Expressions in a resource block - Using expressions in blueprints
Blueprints can use expressions to map input parameters for each operation on a resource block. By default, the blueprint displays the same parameters and values that are specified in the resource block.
You can access blueprint attributes with expressions. The expression in the Mapping column defines blueprint attributes for each operation in a step. For example, the Location attribute, which appears on the stack request form, is accessible through the
{$parameter.Location}expression. The Location parameter with the${parameter.Location}value appears on the Inputs tab when you select a blueprint operation.Figure 2. Expressions in a blueprint - Using expressions in policy actions
Policy actions can use expressions to override parameter values that users submit in a request form on the Cloud User Portal. You can also access and override user data in stack operations. For example, use the following expression to rename a stack:
formData.Stackname = "your-naming-convention";.Figure 3. Expressions in a policy script
You can access blueprint attributes with expressions. The expression in the
Mapping column defines blueprint attributes for each operation in a
step. For example, the Location attribute, which appears on the
request form for a virtual machine, is accessed in the following expression:
{$parameter.Location}.
Expression types
- Definitional expressions
- Definitional expressions are a form of early binding (or static binding). These
bindings refer to compile-time binding and are evaluated when the user submits the stack
request form (when stack or resource provisioning starts). Definitional expressions do
not have access to the data that is generated during Orchestration. Definitional
expressions are enclosed in curly braces. For example:
${parameter.CloudAccount} - Runtime expressions
- Runtime expressions are a form of late binding (or dynamic binding). These bindings
refer to runtime binding and have access to the data that is created during Orchestration (for example, stack
items). Runtime expressions are evaluated when called during an Orchestration run. Runtime
expressions are typically used for dot-walking to data in tables. Runtime expressions
are enclosed in parentheses. For example:
$(Stack.items[VM1].attributes[node_id]) - Definitional/Runtime expressions
- Some expressions include both definitional and runtime expressions.
- Complex expressions
- You can nest expressions of any type within other expressions.
Definition expression syntax and examples
${parameter.}. Use this kind of expression to retrieve values from input attributes of processes like blueprint provisions. Data is not fetched from tables.${Stack.items[]}. Use this syntax to access attributes of specific items in a stack.${randomNumber}. Use this syntax to generate a random number. For example, you can provision a VM with a random node name or stack name.
| Example | Description |
|---|---|
| ${parameter.BillingCode} | This expression shows how a billing code parameter appears in a blueprint. |
| ${parameter.formData.CatalogAttributeType} | This expression takes a catalog attribute that is submitted by a user while the user fills out the form for a catalog item in the Cloud User Portal. |
| ${parameter.userData.userId} | This expression takes the ID of a user while the user fills out the form for a catalog item in the Cloud User Portal. |
| ${Stack.items[Virtual Server].attributes[sys_id]} | This expression gets the sys_id of a virtual server that is apart of a stack. Virtual Server is the alias of a resource block used in the stack. |
Runtime expression syntax and examples
$(ci.tablename)wheretablenameis a table in the system, usually a CI table in the CMDB. Use this syntax to access values of fields in the table.$(Stack.items[]). Use this syntax to access attributes of specific items in a stack.
| Example | Description |
|---|---|
$(ci.cmdb_ci_cloud_subnet[
sys_id=12231231231231231231].cidr) |
This expression dot walks to the Cloud Subnet table, finds the specific
record with the given sys_id, and takes the value from the cidr
column. |
$(ci.sn_cmp _ip_pool[subnet=${parameter.formData.Subnet
Id}]) |
This expression combines runtime and definition type expressions. The equal sign = is used to evaluate a value for a match. The expression dot-walks to the IP Pool table and looks for the subnet that has the subnet ID that the user submitted. |
$(ci.cmdb_ci_cloud_subnet[${parameter.formData.SubnetId}].cidr) |
This expression combines runtime and definition type expressions. The
expression takes the value of the cidr field from a subnet
that the user chose during provisioning. The square brackets []
indicate that the expression dot-walks to the Cloud Subnet table and then looks at
the subnet value that the user submitted on a blueprint provision. The expression
grabs the cidr field value and then walks to the value in
the cidr field of the sys_id of the subnet. |
| $(Stack.items[Virtual Server].attributes[sys_id]) | As in the definition expression example, this expression takes the sys_id of a virtual server that is apart of a stack. |
Example expression
$(ci.cmdb_ci_nic[$(Script:CMPVMNICs.getNICs[arg=$(Stack.items[Virtual
Server].attributes[sys_id])])].private_ip)
- $(ci: Runtime expression to retrieve data from table.
- cmdb_ci_nic: CI for NIC (Network Interface Card).
- $(Script: Script-based expression.
- CMPVMNICs: Script include.
- getNICs: Function inside a script include.
- arg: Arguments to script include function. Arguments are separated by "," when there are multiple attributes.
- $(Stack.items: Runtime stack expression to retrieve stack item from a stack. Argument is the alias specified in blueprint.
- Virtual Server: Alias of resource used in blueprint.
- $(Stack.items[Virtual Server].attributes[sys_id]): Retrieve sys_id of stack item ("Virtual Server") resource instance in a stack.
- private_ip: Attribute from cmdb_ci_nic. Replace with public IP if required.
Expressions
Simple parameter mapping expression This type of expression retrieves values from input attributes of processes, such as blueprint operations, resource blocks, and policies. Data is not fetched from tables. Maps values from one layer to another, such as from a Blueprint to a Resource to the Cloud API.
|
Stack item expression A CI instance in the CMDB represents each stack item. Use Stack Item expressions to look up first-level properties on the CI that back the stack item or on the stack item itself.
|
Property override expressions in policies In policies, you can override properties by pulling a value from the system or by using a random number. You can use data from both the forms in the Cloud User Portal and from the user who performed the operation on the form.
|
Script expression In the example,
|
CI lookup expression Accesses values of fields in a table, usually a CI table in the CMDB.
|
Random number expression Generates a random number. For example, you can provision a VM with a random node name or stack name.
|
Scratchpad expression/Resource operation output attribute expression Reads output attributes from one operation into another operation.
|
Conditions in expressions You can use conditional expressions in blueprint steps and resource operation steps to conditionally execute or skip the step. The conditional expressions are Javascript expressions and they support expression substitutions.
|
Complex expression You can nest expressions. In the example,
|
Order context This expression is useful for life cycle operations and enables you to dot-walk on the order attributes as part of the sn_cmp_order table.
|