全部产品
云市场

Action通用属性

更新时间:2019-08-10 10:58:26

动作(Action)定义了一个具体的操作,是操作的最小单位。

动作类型

动作分为以下几种类型:

  • 原子动作(Atom Action)
    • API动作(API Action)
    • 触发器动作(Trigger Action)
    • 控制类动作(Control Action)
    • 嵌套类动作(ACS::Template)
  • 云产品动作(Cloud Product Action)
    • 弹性计算(ECS)类
    • 关系型数据库(RDS)类
    • 钉钉(DingTalk)类

名称格式

动作(Action)的名称格式为ACS::<name>

通用属性

除非某个Action有特殊说明,每个Action都具有以下通用属性。

  1. ---
  2. Tasks:
  3. - Name: task_name_1
  4. Action: 'Action类型'
  5. Description: describe the purpose of the task
  6. OnError: 'END/CONTINUE/<other-task-name>' # 默认 END
  7. OnSuccess: 'NEXT/<other-task-name>/END' # 默认继续向下执行
  8. Properties:
  9. Service: ECS/RDS/RAM
  10. Risk: High/Normal
  11. API: DeleteInstance/CreateDBInstance/CreateRamRole
  12. Parameters:
  13. InstanceId: "i-XXX"
  14. Outputs:
  15. Output_parameter_name_1:
  16. Type: String/List
  17. Value: {{ task.output1 }}

Action通用定义

  • Name:合法字符为:[a-zA-Z0-9-_],长度限制200个内,不允许包含冒号(:)。
  • Action:必须为以下类型之一,原子action,业务action。以ACS::开头。
  • Description:描述当前task的用途。
  • Properties:详细信息,请参见 ACS::ExecuteApi

安全风险设置

在模板中如果您已对重要的云产品(如ECS,RDS等)做了手工标示,则模板执行时按手工设置的Risk解析。如果您未设置,则按OOS默认设置。默认设置规则:所有Delete,Remove,Terminate,Drop开头的API,都是高风险(High)。

示例

如下模板:删除一台ECS实例,把Risk设置为Normal可正常删除,否则处于Waiting状态。

  • YAML格式:
  1. ---
  2. FormatVersion: OOS-2019-06-01
  3. Description: delete instance
  4. Parameters:
  5. InstanceId:
  6. Description: the instance id that you will delete
  7. Type: String
  8. Tasks:
  9. - Name: deleteInstance
  10. Action: ACS::ExecuteAPI
  11. Description: delete instance with specified parameters
  12. Properties:
  13. Service: ECS
  14. API: DeleteInstance
  15. Risk: Normal
  16. Parameters:
  17. InstanceId: "{{ InstanceId }}"
  18. Outputs:
  19. RequestId:
  20. Type: String
  21. ValueSelector: RequestId
  22. Outputs:
  23. RequestId:
  24. Type: String
  25. Value: "{{ deleteInstance.RequestId }}"
  • JSON格式:
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": "delete instance",
  4. "Parameters": {
  5. "InstanceId": {
  6. "Description": "the instance id that you will delete",
  7. "Type": "String"
  8. }
  9. },
  10. "Tasks": [
  11. {
  12. "Name": "deleteInstance",
  13. "Action": "ACS::ExecuteAPI",
  14. "Description": "delete instance with specified parameters",
  15. "Properties": {
  16. "Service": "ECS",
  17. "API": "DeleteInstance",
  18. "Risk": "Normal",
  19. "Parameters": {
  20. "InstanceId": "{{ InstanceId }}"
  21. }
  22. },
  23. "Outputs": {
  24. "RequestId": {
  25. "Type": "String",
  26. "ValueSelector": "RequestId"
  27. }
  28. }
  29. }
  30. ],
  31. "Outputs": {
  32. "RequestId": {
  33. "Type": "String",
  34. "Value": "{{ deleteInstance.RequestId }}"
  35. }
  36. }
  37. }

流程控制类

  • OnError:ACS::END:默认
  • OnSuccess:ACS::NEXT:默认
  • OnError: CONTINUE:此任务出错时顺序执行下一个的task
  • OnError: <task_name>:此任务出错时执行指定的task
  • OnSuccess: <task_name>:此任务成功时执行指定的task

示例

如下模板:新建一台ECS实例并在此实例安装云助手,安装失败时会自动删除此实例。

  • YAML格式:
  1. ---
  2. FormatVersion: OOS-2019-06-01
  3. Parameters:
  4. SourceImageId:
  5. Description: the image id of the source image to be updated
  6. Type: String
  7. InstanceType:
  8. Description: the Instance Type for the new instances
  9. Type: String
  10. SecurityGroupId:
  11. Description: the security group id for the new instances
  12. Type: String
  13. VSwitchId:
  14. Description: the virtual switch id for the new instances
  15. Type: String
  16. OOSAssumeRole:
  17. Type: String
  18. Description: oos assume this role to execution task
  19. Default: OOSServiceRole
  20. RamRole: "{{OOSAssumeRole}}"
  21. Tasks:
  22. - Name: runInstances
  23. Action: ACS::ECS::RunInstances
  24. Properties:
  25. ImageId: "{{ SourceImageId }}"
  26. InstanceType: "{{ InstanceType }}"
  27. SecurityGroupId: "{{ SecurityGroupId }}"
  28. VSwitchId: "{{ VSwitchId }}"
  29. Outputs:
  30. InstanceId:
  31. ValueSelector: InstanceIds[0]
  32. Type: String
  33. - Name: installCloudAssistant
  34. Action: ACS::ECS::InstallCloudAssistant
  35. OnError: deleteInstance
  36. Properties:
  37. InstanceId: "{{ runInstances.InstanceId }}"
  38. - Name: deleteInstance
  39. Action: ACS::ExecuteApi
  40. Properties:
  41. Service: ECS
  42. API: DeleteInstance
  43. Risk: Normal
  44. Parameters:
  45. InstanceId: "{{ runInstances.InstanceId }}"
  46. Force: true
  47. Outputs:
  48. InstanceId:
  49. Type: String
  50. Value: "{{ runInstances.InstanceId }}"
  • JSON格式:
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Parameters": {
  4. "SourceImageId": {
  5. "Description": "the image id of the source image to be updated",
  6. "Type": "String"
  7. },
  8. "InstanceType": {
  9. "Description": "the Instance Type for the new instances",
  10. "Type": "String"
  11. },
  12. "SecurityGroupId": {
  13. "Description": "the security group id for the new instances",
  14. "Type": "String"
  15. },
  16. "VSwitchId": {
  17. "Description": "the virtual switch id for the new instances",
  18. "Type": "String"
  19. },
  20. "OOSAssumeRole": {
  21. "Type": "String",
  22. "Description": "oos assume this role to execution task",
  23. "Default": "OOSServiceRole"
  24. }
  25. },
  26. "RamRole": "{{OOSAssumeRole}}",
  27. "Tasks": [
  28. {
  29. "Name": "runInstances",
  30. "Action": "ACS::ECS::RunInstances",
  31. "Properties": {
  32. "ImageId": "{{ SourceImageId }}",
  33. "InstanceType": "{{ InstanceType }}",
  34. "SecurityGroupId": "{{ SecurityGroupId }}",
  35. "VSwitchId": "{{ VSwitchId }}"
  36. },
  37. "Outputs": {
  38. "InstanceId": {
  39. "ValueSelector": "InstanceIds[0]",
  40. "Type": "String"
  41. }
  42. }
  43. },
  44. {
  45. "Name": "installCloudAssistant",
  46. "Action": "ACS::ECS::InstallCloudAssistant",
  47. "OnError": "deleteInstance",
  48. "Properties": {
  49. "InstanceId": "{{ runInstances.InstanceId }}"
  50. }
  51. },
  52. {
  53. "Name": "deleteInstance",
  54. "Action": "ACS::ExecuteApi",
  55. "Properties": {
  56. "Service": "ECS",
  57. "API": "DeleteInstance",
  58. "Risk": "Normal",
  59. "Parameters": {
  60. "InstanceId": "{{ runInstances.InstanceId }}",
  61. "Force": true
  62. }
  63. }
  64. }
  65. ],
  66. "Outputs": {
  67. "InstanceId": {
  68. "Type": "String",
  69. "Value": "{{ runInstances.InstanceId }}"
  70. }
  71. }
  72. }

任务输出

Task级别的Outputs 由输出 Type 和输出 ValueSelector 组成。如果声明多个输出项,则用逗号分隔开。请参见下列示例的语法结构。

示例

如下模板:获取账号下所有处于Running状态的实例。

  • YAML格式:
  1. ---
  2. FormatVersion: OOS-2019-06-01
  3. Tasks:
  4. - Name: describeInstances
  5. Action: ACS::ExecuteAPI
  6. Properties:
  7. Service: ECS
  8. API: DescribeInstances
  9. Parameters:
  10. Status: "Running"
  11. Outputs:
  12. InstanceIds:
  13. Type: List
  14. ValueSelector: Instances.Instance[].InstanceId
  15. Outputs:
  16. InstanceIds:
  17. Type: String
  18. Value: "{{ describeInstances.InstanceIds }}"
  • JSON格式:
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Tasks": [
  4. {
  5. "Name": "describeInstances",
  6. "Action": "ACS::ExecuteAPI",
  7. "Properties": {
  8. "Service": "ECS",
  9. "API": "DescribeInstances",
  10. "Parameters": {
  11. "Status": "Running"
  12. }
  13. },
  14. "Outputs": {
  15. "InstanceIds": {
  16. "Type": "List",
  17. "ValueSelector": "Instances.Instance[].InstanceId"
  18. }
  19. }
  20. }
  21. ],
  22. "Outputs": {
  23. "InstanceIds": {
  24. "Type": "String",
  25. "Value": "{{ describeInstances.InstanceIds }}"
  26. }
  27. }
  28. }

输出名称(必需)

输出项的标识符,在模板中具有唯一性。如示例中的InstanceIds。

Type(必需)

输出项的类型,如StringList等。

ValueSelector(必需)

在模板执行完成时,输出的属性值。支持JQ selector,如PropertySelector、ValueSelector等。