ACS::CheckFor

用途

该动作用来检查云产品资源是否符合预期状态,如是预期状态,则任务执行成功。否则,任务执行失败。通常用来做前置检查。如要停止某ECS实例,则可以先检查该ECS实例的状态是运行中状态(Running),如果不是Running,则不执行停止操作。

语法

此语法格式除了TypeACS::CheckFor以外的所有字段和ACS::WaitFor一致,请参考ACS::WaitFor语法和说明。

  • YAML格式
  1. Tasks:
  2. - Name: checkForTaskExample
  3. Action: ACS::CheckFor
  4. Properties:
  5. # 以下属性和ACS::ExecuteAPI一致,请参考ACS::ExecuteAPI语法说明。
  6. Service: ECS
  7. API: DescribeInstances
  8. Parameters:
  9. InstanceId: i-12345678abcedfg
  10. # 以下属性为ACS::CheckFor的特殊属性
  11. PropertySelector: "jq selector" # 必填,需要等待的具体的API返回值,参考ACS::ExecuteAPI中的ValueSelector说明
  12. DesiredValues: # DesiredValue,NotDesiredValues 必填其一,指上面截取的值要匹配到以下值之一,匹配则表示成功,否则会超时然后失败。
  13. - value1
  14. - value2
  15. NotDesiredValues: # DesiredValue,NotDesiredValues 必填其一,指上面截取的值要不匹配到以下的所有值,全都不匹配则表示成功,否则会超时然后失败。
  16. - value3
  17. - value4
  18. Outputs: # CheckFor动作所在的任务支持输出,当任务满足NotDesiredValues/DesiredValues的条件时,任务执行成功后会返回输出参数的值。
  19. OutputParameter1:
  20. ValueSelector: 'jq selector' # jq的选择器语法,以OpenAPI的返回作为JSON输入,jq的语法请参考 https://stedolan.github.io/jq/
  21. Type: String/Boolean/List(Array)/Number/Object
  • JSON格式(请参考YAML注释说明)
  1. {
  2. "Tasks": [
  3. {
  4. "Name": "checkForTaskExample",
  5. "Action": "ACS::CheckFor",
  6. "Properties": {
  7. "Service": "ECS",
  8. "API": "DescribeInstances",
  9. "Parameters": {
  10. "InstanceId": "i-12345678abcedfg"
  11. },
  12. "PropertySelector": "jq selector",
  13. "DesiredValues": [
  14. "value1",
  15. "value2"
  16. ],
  17. "NotDesiredValues": [
  18. "value3",
  19. "value4"
  20. ]
  21. },
  22. "Outputs": {
  23. "OutputParameter1": {
  24. "ValueSelector": "jq selector",
  25. "Type": "String/Boolean/List(Array)/Number/Object"
  26. }
  27. }
  28. }
  29. ]
  30. }

示例

如下模板:为指定磁盘创建快照。用CheckFor检查特定实例是否处于Running或Stopped状态。

  • YAML格式:
  1. FormatVersion: OOS-2019-06-01
  2. Parameters:
  3. DiskId:
  4. Description: the disk id of the snap shot to copy
  5. Type: String
  6. InstanceId:
  7. Description: the instances id of the snap shot to copy
  8. Type: String
  9. SnapshotName:
  10. Description: snap shot name of the new snap
  11. Type: String
  12. Tasks:
  13. - Name: checkInstanceReady
  14. Action: ACS::CheckFor
  15. Properties:
  16. Service: ECS
  17. API: DescribeInstances
  18. DesiredValues:
  19. - Running
  20. - Stopped
  21. Parameters:
  22. InstanceIds:
  23. - '{{ InstanceId }} '
  24. PropertySelector: Instances.Instance[].Status
  25. - Name: createSnapshot
  26. Action: ACS::ExecuteAPI
  27. Properties:
  28. Service: ECS
  29. API: CreateSnapshot
  30. Parameters:
  31. DiskId: '{{ DiskId }}'
  32. SnapshotName: '{{ SnapshotName }}'
  33. Outputs:
  34. SnapshotId:
  35. Type: String
  36. ValueSelector: SnapshotId
  37. - Name: waitSnapshotsReady
  38. Action: ACS::WaitFor
  39. Properties:
  40. Service: ECS
  41. API: DescribeSnapshots
  42. DesiredValues:
  43. - accomplished
  44. Parameters:
  45. SnapshotIds:
  46. - '{{ createSnapshot.SnapshotId }}'
  47. PropertySelector: Snapshots.Snapshot[].Status
  48. Outputs:
  49. SnapshotId:
  50. Type: String
  51. Value: '{{ createSnapshot.SnapshotId }}'
  • JSON格式:
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Parameters": {
  4. "DiskId": {
  5. "Description": "the disk id of the snap shot to copy ",
  6. "Type": "String"
  7. },
  8. "InstanceId": {
  9. "Description": "the instances id of the snap shot to copy ",
  10. "Type": "String"
  11. },
  12. "SnapshotName": {
  13. "Description": "snap shot name of the new snap",
  14. "Type": "String"
  15. }
  16. },
  17. "Tasks": [
  18. {
  19. "Name": "checkInstanceReady",
  20. "Action": "ACS::CheckFor",
  21. "Properties": {
  22. "Service": "ECS",
  23. "API": "DescribeInstances",
  24. "DesiredValues": ["Running", "Stopped"],
  25. "Parameters": {
  26. "InstanceIds": ["{{ InstanceId }} "]
  27. },
  28. "PropertySelector": "Instances.Instance[].Status"
  29. }
  30. },
  31. {
  32. "Name": "createSnapshot",
  33. "Action": "ACS::ExecuteAPI",
  34. "Properties": {
  35. "Service": "ECS",
  36. "API": "CreateSnapshot",
  37. "Parameters": {
  38. "DiskId": "{{ DiskId }}",
  39. "SnapshotName": "{{ SnapshotName }}"
  40. }
  41. },
  42. "Outputs": {
  43. "SnapshotId": {
  44. "Type": "String",
  45. "ValueSelector": "SnapshotId"
  46. }
  47. }
  48. },
  49. {
  50. "Name": "waitSnapshotsReady",
  51. "Action": "ACS::WaitFor",
  52. "Properties": {
  53. "Service": "ECS",
  54. "API": "DescribeSnapshots",
  55. "DesiredValues": ["accomplished"],
  56. "Parameters": {
  57. "SnapshotIds": ["{{ createSnapshot.SnapshotId }}"]
  58. },
  59. "PropertySelector": "Snapshots.Snapshot[].Status"
  60. }
  61. }
  62. ],
  63. "Outputs": {
  64. "SnapshotId": {
  65. "Type": "String",
  66. "Value": "{{ createSnapshot.SnapshotId }}"
  67. }
  68. }
  69. }
阿里云首页 运维编排 相关技术圈