ACS::CheckFor
更新時(shí)間:
用法
該動(dòng)作用來(lái)檢查云產(chǎn)品資源是否符合預(yù)期狀態(tài),如是預(yù)期狀態(tài),則任務(wù)執(zhí)行成功。否則,任務(wù)執(zhí)行失敗。通常用來(lái)做前置檢查。如要停止某ECS實(shí)例,則可以先檢查該ECS實(shí)例的狀態(tài)是運(yùn)行中狀態(tài)(Running),如果不是Running,則不執(zhí)行停止操作。
語(yǔ)法
此語(yǔ)法格式除了Type
為ACS::CheckFor
以外的所有字段和ACS::WaitFor
一致,請(qǐng)參考ACS::WaitFor語(yǔ)法和說(shuō)明。
Tasks:
- Name: checkForTaskExample
Action: ACS::CheckFor
Properties:
# 以下屬性和ACS::ExecuteAPI一致,請(qǐng)參考ACS::ExecuteAPI語(yǔ)法說(shuō)明。
Service: ECS
API: DescribeInstances
Parameters:
InstanceId: i-12345678abcedfg
# 以下屬性為ACS::CheckFor的特殊屬性
PropertySelector: "jq selector" # 必填,需要等待的具體的API返回值,參考ACS::ExecuteAPI中的ValueSelector說(shuō)明
DesiredValues: # DesiredValue,NotDesiredValues 必填其一,指上面截取的值要匹配到以下值之一,匹配則表示成功,否則會(huì)超時(shí)然后失敗。
- value1
- value2
NotDesiredValues: # DesiredValue,NotDesiredValues 必填其一,指上面截取的值要不匹配到以下的所有值,全都不匹配則表示成功,否則會(huì)超時(shí)然后失敗。
- value3
- value4
Outputs: # CheckFor動(dòng)作所在的任務(wù)支持輸出,當(dāng)任務(wù)滿足NotDesiredValues/DesiredValues的條件時(shí),任務(wù)執(zhí)行成功后會(huì)返回輸出參數(shù)的值。
OutputParameter1:
ValueSelector: 'jq selector' # jq的選擇器語(yǔ)法,以O(shè)penAPI的返回作為JSON輸入,jq的語(yǔ)法請(qǐng)參考 https://stedolan.github.io/jq/
Type: String/Boolean/List(Array)/Number/Object
{
"Tasks": [
{
"Name": "checkForTaskExample",
"Action": "ACS::CheckFor",
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"InstanceId": "i-12345678abcedfg"
},
"PropertySelector": "jq selector",
"DesiredValues": [
"value1",
"value2"
],
"NotDesiredValues": [
"value3",
"value4"
]
},
"Outputs": {
"OutputParameter1": {
"ValueSelector": "jq selector",
"Type": "String/Boolean/List(Array)/Number/Object"
}
}
}
]
}
示例
如下模板:為指定磁盤(pán)創(chuàng)建快照。用CheckFor檢查特定實(shí)例是否處于Running或Stopped狀態(tài)。
FormatVersion: OOS-2019-06-01
Parameters:
DiskId:
Description: the disk id of the snap shot to copy
Type: String
InstanceId:
Description: the instances id of the snap shot to copy
Type: String
SnapshotName:
Description: snap shot name of the new snap
Type: String
Tasks:
- Name: checkInstanceReady
Action: ACS::CheckFor
Properties:
Service: ECS
API: DescribeInstances
DesiredValues:
- Running
- Stopped
Parameters:
InstanceIds:
- '{{ InstanceId }} '
PropertySelector: Instances.Instance[].Status
- Name: createSnapshot
Action: ACS::ExecuteAPI
Properties:
Service: ECS
API: CreateSnapshot
Parameters:
DiskId: '{{ DiskId }}'
SnapshotName: '{{ SnapshotName }}'
Outputs:
SnapshotId:
Type: String
ValueSelector: SnapshotId
- Name: waitSnapshotsReady
Action: ACS::WaitFor
Properties:
Service: ECS
API: DescribeSnapshots
DesiredValues:
- accomplished
Parameters:
SnapshotIds:
- '{{ createSnapshot.SnapshotId }}'
PropertySelector: Snapshots.Snapshot[].Status
Outputs:
SnapshotId:
Type: String
Value: '{{ createSnapshot.SnapshotId }}'
{
"FormatVersion": "OOS-2019-06-01",
"Parameters": {
"DiskId": {
"Description": "the disk id of the snap shot to copy ",
"Type": "String"
},
"InstanceId": {
"Description": "the instances id of the snap shot to copy ",
"Type": "String"
},
"SnapshotName": {
"Description": "snap shot name of the new snap",
"Type": "String"
}
},
"Tasks": [
{
"Name": "checkInstanceReady",
"Action": "ACS::CheckFor",
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"DesiredValues": ["Running", "Stopped"],
"Parameters": {
"InstanceIds": ["{{ InstanceId }} "]
},
"PropertySelector": "Instances.Instance[].Status"
}
},
{
"Name": "createSnapshot",
"Action": "ACS::ExecuteAPI",
"Properties": {
"Service": "ECS",
"API": "CreateSnapshot",
"Parameters": {
"DiskId": "{{ DiskId }}",
"SnapshotName": "{{ SnapshotName }}"
}
},
"Outputs": {
"SnapshotId": {
"Type": "String",
"ValueSelector": "SnapshotId"
}
}
},
{
"Name": "waitSnapshotsReady",
"Action": "ACS::WaitFor",
"Properties": {
"Service": "ECS",
"API": "DescribeSnapshots",
"DesiredValues": ["accomplished"],
"Parameters": {
"SnapshotIds": ["{{ createSnapshot.SnapshotId }}"]
},
"PropertySelector": "Snapshots.Snapshot[].Status"
}
}
],
"Outputs": {
"SnapshotId": {
"Type": "String",
"Value": "{{ createSnapshot.SnapshotId }}"
}
}
}
文檔內(nèi)容是否對(duì)您有幫助?