Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Condition Function

Updated on 2022-02-22 GMT+08:00

Condition functions are usually used to define whether elements need to be deployed, including cond_eq, cond_not, cond_and, cond_or, and cond_if. Except cond_if, other condition functions can only be used in the conditions section. The cond_if function can be used in the conditions, node_templates, and outputs sections.

For example, vm_deploy is used to determine whether to deploy a VM.

tosca_definitions_version: cloud_tosca_version_1_0
conditions:
  condition_vm_deploy:    #The conditions can be met only when inputs parameters are matched. 
    cond_eq:
      - get_input: vm_deploy
      - true
inputs:
  image:
    description: ID of the image used by the ECS
    type: Cloud.ECS.Image.Id
  instance:
    default: 1
    description: number of ECSs to be created
  subnet:
    description: ID of the subnet to which the ECS belongs
..vm_deploy:    #Determines whether to deploy the VM.
    default: true
    type: boolean
  vpc:
    description: ID of the VPC to which the ECS belongs
node_templates:
  vm:
    condition: condition_vm_deploy     # The VM will be deployed only when the conditions are met. 
    type: Cloud.ECS.CloudServer
    properties:
      availabilityZone: ae-ad-1a
      imageId:
        get_input: image
      flavor: s3.small.1
      instances:
        get_input: instance
      name: my-ecs
      nics:
        - subnetId:
            get_input: subnet
      rootVolume:
        size: 40
        volumeType: SATA
      vpcId:
        get_input: vpc
  myecs:
    type: Cloud.ECS.CloudServer
    properties:
      name: my-ecs
      instances:
        get_input: instance
      imageId:
        get_input: image
      flavor: s3.small.1
      vpcId:
        get_input: vpc
      availabilityZone: ae-ad-1a
      nics:
        - subnetId:
            get_input: subnet
      rootVolume:
        volumeType: SSD
        size: 40

cond_eq

The cond_eq function is used to determine whether an equal condition is met. It is generally used to determine whether an input parameter is consistent with an expected value.

Table 1 cond_eq

Syntax

Parameter Description

Return Value

cond_eq: [cond1, cond2]

  • cond1: Condition 1, which can be a number, string, Boolean value, or variable obtained using the get_input function.
  • cond2: Condition 2, which can be a number, string, Boolean value, or variable obtained using the get_input function.

When the value of cond1 is the same as that of cond2, true is returned; otherwise, false is returned.

The following describes how to use the cond_eq function to determine whether the input parameter is consistent with an expected value:

inputs:
  a:
    type: string
    default: 10
conditions:
  matchA:
    cond_eq: [{get_input: a}, 10]

cond_not

The cond_not function is used to reverse the calculation result and is usually nested with other condition functions.

Table 2 cond_not

Syntax

Parameter Description

Return Value

cond_not: cond

  • cond: Condition expression, which can be a Boolean value, Boolean variable obtained using the get_input function, or nested condition function such as cond_eq or cond_not.

If the calculation result of the condition expression is true, false is returned. If the result is false, true is returned.

The following describes how to use the cond_not function to determine whether the input parameter is consistent with an expected value:

inputs:
  a:
    type: boolean
    default: true
conditions:
  matchA:
    cond_not: {get_input: a}    

cond_and

The cond_and function is used to check whether multiple conditions are met. This function supports 2 to 10 conditions.

Table 3 cond_and

Syntax

Parameter Description

Return Value

cond_and: [cond1, cond2...condn]

  • cond1: Condition 1, which can be a Boolean value, Boolean variable obtained using the get_input function, or nested condition function such as cond_eq or cond_not.
  • cond2: Condition 2, which can be a Boolean value, Boolean variable obtained using the get_input function, or nested condition function such as cond_eq or cond_not.
  • condn: Condition n (3 ≤ n ≤ 10), which is optional and can be defined as required. The parameter type is the same as that of cond1 or cond2.

If all parameter conditions are met, true is returned; otherwise, false is returned.

The following describes how to use the cond_and function to check whether the combination conditions are met:

inputs:
  a:
    type: integer
    default: 10
  b:
    type: string
    default: debug
conditions:
  matchAnd:
    cond_and: [{cond_eq: [{get_input: a}, 10]}, {cond_eq: [{get_input: b}, debug]}]   # The condition of matchAnd can be met only when both conditions 1 and 2 are met.

cond_or

The cond_or function is used to determine whether any of multiple conditions is met. This function supports 2 to 10 conditions.

Table 4 cond_or

Syntax

Parameter Description

Return Value

cond_or: [cond1, cond2...condn]

  • cond1: Condition 1, which can be a Boolean value, Boolean variable obtained using the get_input function, or nested condition function such as cond_eq or cond_not.
  • cond2: Condition 2, which can be a Boolean value, Boolean variable obtained using the get_input function, or nested condition function such as cond_eq or cond_not.
  • condn: Condition n (3 ≤ n ≤ 10), which is optional and can be defined as required. The parameter type is the same as that of cond1 or cond2.

If any condition is met, true is returned. If no condition is met, false is returned.

The following describes how to use the cond_or function to check whether the combination conditions are met:

inputs:
  a:
    type: integer
    default: 10
  b:
    type: string
    default: debug
conditions:
  matchOr:
    cond_or: [{cond_eq: [{get_input: a}, 8]}, {cond_eq: [{get_input: b}, debug]}]  # The condition of matchOr can be met when either condition is met.

cond_if

The cond_if function is a triplet expression used to assign values to properties. It is generally used in the property structure of node_templates.

Table 5 cond_if

Syntax

Parameter Description

Return Value

cond_if: [condition, value_true, value_false]

  • condition: Condition name, which must be defined in the conditions section.
  • value_true: Value assigned when a condition is met.
  • value_false: Value assigned when a condition is not met.

If the condition is met, value_true is returned. If the condition is not met, value_false is returned.

The following describes how to use the cond_if function to define property values:

inputs:
  a:
    type: integer
    default: 10
  b:
    type: string
    default: debug
conditions:
  matchOr:
    cond_or: [{cond_eq: [{get_input: a}, 8]}, {cond_eq: [{get_input: b}, debug]}]  # The condition of matchOr can be met when either condition is met.
node_templates:
  vm:
    type: Cloud.ECS.CloudServer     
    properties:
      vpcId: vpc-id-123
      name: myvm
      nics:
        - subnetId: subnet-id-123
      imageId: {cond_if: [matchOr, image-debug, image-product]}   # cond_if is used to define a condition. If the debugging mode is used, debugging images are used; otherwise, product images are used.
      instances: 1
      availabilityZone: ae-ad-1a
      rootVolume:
        volumeType: SATA
        size: 40
      flavor: flavor-1

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback