All Products
Search
Document Center

CloudOps Orchestration Service:Release multiple ECS instances at a time

最終更新日:Jul 15, 2024

CloudOps Orchestration Service (OOS) provides public templates for you to release multiple Elastic Compute Service (ECS) instances at a time. To automatically release ECS instances, you can create an execution based on a template and specify the IDs of the ECS instances for the execution.

Prerequisites

The ECS instances to be released must be pay-as-you-go or subscription instances.

Procedure

  1. Log on to the OOS console.

  2. In the left-side navigation pane, choose Automated Task > Public Template.

  3. On the Public Templates page, search for the ACS-ECS-BulkyDeleteInstances template that is used to release pay-as-you-go ECS instances. Then, click Create Execution.

    ACS-ECS-BulkyDeleteInstances1

  4. On the Create Task page, configure the parameters in the Basic Information step. Then, click Next Step: Parameter Settings.

    image

  5. In the Parameter Settings step, configure the parameters to execute the public template. In this example, the ACS-ECS-BulkyDeleteInstances template is used.

    image

    Parameter

    Description

    Examples

    TargetInstance

    The ECS instances that you want to release. You can directly select instances, specify instance tags, specify the resource group of instances, or upload a CSV file that contains instance information.

    test:oos / i-bp10jvphtux8ad******

    Force

    Specifies whether to forcibly release the ECS instances.

    true/false

    RateControl

    Rate control type

    Concurrency-based Control

    Concurrency

    10

    Error Threshold

    10

    OOSAssumeRole

    Optional. The permissions to be used for executing the template. Valid values:

    • Use Existing Permissions of Current Account: This is the default value. You have all the permissions granted to your account. Make sure that you have the permissions to call the ECS API operations that are used to create custom images.

    • Specify RAM Role and Use Permissions Granted to This Role: If a Resource Access Management (RAM) role is specified, OOS assumes the RAM role to perform O&M tasks.

    Use Existing Permissions of Current Account

  6. Click Next Step: OK. In the OK step, click Create.

    image

  7. Go to the Task Execution Management page to view the created execution. If the execution enters the Running state, the specified instances are being released.

  8. When the execution changes to the Success state, all of the specified instances are released.

  9. Check whether all of the specified instances are released. 2

Appendix 1: Public template and logic

  • ACS-ECS-BulkyDeleteInstances

FormatVersion: OOS-2019-06-01
Description:
  en: Bulky delete ECS postpaid instances.
   
  name-en: ACS-ECS-BulkyDeleteInstances
   
  categories:
    - instance_manage
Parameters:
  targets:
    Type: Json
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: 'ALIYUN::ECS::Instance'
  force:
    Description:
      en: Whether to force the release of a running instance.
       
    Type: Boolean
    Default: false
  rateControl:
    Description:
      en: Concurrency ratio of task execution.
       
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Description:
      en: The RAM role to be assumed by OOS.
       
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: getInstance
    Description:
      en: Views the ECS instances.
       
    Action: 'ACS::SelectTargets'
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: 'Instances.Instance[].InstanceId'
  - Name: deleteInstance
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Deletes ECS instance with the specified instance ID.
       
    Properties:
      Service: ECS
      API: DeleteInstance
      Parameters:
        InstanceId: '{{ ACS::TaskLoopItem }}'
        Force: '{{ force }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'            

The template executes the following tasks in sequence:

  1. Query ECS instances based on the specified search condition, such as IDs or tags.

  2. Release all of the specified ECS instances at a time.

  • ACS-ECS-BulkyDeletePrepaidInstances

FormatVersion: OOS-2019-06-01
Description:
  en: >-
    Bulky delete prepaid instances.The specified ECS instances must be in
    stopped status.
    
  name-en: ACS-ECS-BulkyDeletePrepaidInstances
   
  categories:
    - instance_manage
Parameters:
  targets:
    Type: Json
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: 'ALIYUN::ECS::Instance'
  rateControl:
    Description:
      en: Concurrency ratio of task execution.
       
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Description:
      en: The RAM role to be assumed by OOS.
       
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: getInstance
    Description:
      en: Views the ECS instances.
       
    Action: 'ACS::SelectTargets'
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: 'Instances.Instance[].InstanceId'
  - Name: modifyInstanceChargeType
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Modify the charge type for prepaid instances to postpaid.
       
    Properties:
      Service: ECS
      API: ModifyInstanceChargeType
      Parameters:
        InstanceIds: '{{ getInstance.instanceIds }}'
        InstanceChargeType: PostPaid
  - Name: deleteInstance
    Action: 'ACS::ECS::DeleteInstance'
    Description:
      en: Deletes the ECS instance by instance ID.
       
    Properties:
      instanceId: '{{ ACS::TaskLoopItem }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'

The template executes the following tasks in sequence:

  1. Query ECS instances based on the specified search condition, such as IDs or tags.

  2. Change the billing method of subscription instances to pay-as-you-go.

  3. Release all of the specified ECS instances at a time.