全部產品
Search
文件中心

CloudOps Orchestration Service:ACS-ECS-CloneInstancesAcrossRegion

更新時間:Sep 06, 2024

模板名稱

ACS-ECS-CloneInstancesAcrossRegion 跨地區複製ECS執行個體

立即執行

模板描述

跨地區複製ECS執行個體

模板類型

自動化

所有者

Alibaba Cloud

輸入參數

參數名稱

描述

類型

是否必填

預設值

約束

instanceIds

ECS執行個體ID列表

List

regionId

源地區ID

String

最大長度 : 30

最小長度 : 1

targetRegionId

目標地區ID

String

最大長度 : 30

最小長度 : 1

targetZoneId

目標可用性區域ID

String

最大長度 : 30

最小長度 : 1

targetInstanceType

執行個體類型

String

字串校正Regex : ecs.[A-Za-z0-9.-]*

最大長度 : 30

最小長度 : 1

targetSecurityGroupId

安全性群組ID

String

字串校正Regex : sg-[A-Za-z0-9]*

最大長度 : 30

最小長度 : 1

targetVSwitchId

交換器ID

String

字串校正Regex : vsw-[A-Za-z0-9]*

最大長度 : 30

最小長度 : 1

OOSAssumeRole

OOS扮演的RAM角色

String

“”

輸出參數

參數名稱

描述

類型

instanceIds

List

執行此模板需要的權限原則

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:CopyImage",
                "ecs:CreateImage",
                "ecs:DescribeDisks",
                "ecs:DescribeImages",
                "ecs:DescribeInstances",
                "ecs:RunInstances"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

詳情

ACS-ECS-CloneInstancesAcrossRegion詳情

模板內容

FormatVersion: OOS-2019-06-01
Description:
  en: Cross Region copy and run ECS instance by InstanceIds
  zh-cn: 跨地區複製ECS執行個體
  title: ACS-ECS-CloneInstancesAcrossRegion
  name-en: ACS-ECS-CloneInstancesAcrossRegion
  name-zh-cn: 跨地區複製ECS執行個體
  categories:
    - cross_region
Parameters:
  instanceIds:
    Label:
      en: InstanceIds
      zh-cn: ECS執行個體ID列表
    Type: List
  regionId:
    Label:
      en: RegionId
      zh-cn: 源地區ID
    Type: String
    MinLength: 1
    MaxLength: 30
  targetRegionId:
    Label:
      en: TargetRegionId
      zh-cn: 目標地區ID
    Type: String
    MinLength: 1
    MaxLength: 30
  targetZoneId:
    Label:
      en: TargetZoneId
      zh-cn: 目標可用性區域ID
    Type: String
    MinLength: 1
    MaxLength: 30
  targetInstanceType:
    Label:
      en: TargetInstanceType
      zh-cn: 執行個體類型
    Type: String
    AllowedPattern: 'ecs\.[A-Za-z0-9\.\-]*'
    MinLength: 1
    MaxLength: 30
  targetSecurityGroupId:
    Label:
      en: TargetSecurityGroupId
      zh-cn: 安全性群組ID
    Type: String
    AllowedPattern: 'sg-[A-Za-z0-9]*'
    MinLength: 1
    MaxLength: 30
  targetVSwitchId:
    Label:
      en: TargetVSwitchId
      zh-cn: 交換器ID
    Type: String
    AllowedPattern: 'vsw-[A-Za-z0-9]*'
    MinLength: 1
    MaxLength: 30
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOS扮演的RAM角色
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: queryDisks
    Action: ACS::ExecuteAPI
    Description:
      en: Views disk info of the ECS instance
      zh-cn: 查看執行個體的磁碟資訊
    Properties:
      Service: ECS
      API: DescribeDisks
      Parameters:
        RegionId: '{{ regionId }}'
        InstanceId: '{{ ACS::TaskLoopItem }}'
    Outputs:
      instanceDataDisks:
        Type: Json
        ValueSelector: '.Disks.Disk|map( select(.Type == "data" )|{"Category":(.Category),"Device": (.Device),"Size":(.Size),"DiskName":(.DiskName),"PerformanceLevel":(.PerformanceLevel)})'
      instanceSystemDisk:
        Type: Json
        ValueSelector: '.Disks.Disk|map( select(.Type == "system" )|{"Category":(.Category),"Device": (.Device),"Size":(.Size),"DiskName":(.DiskName),"PerformanceLevel":(.PerformanceLevel)})[]'
    Loop:
      Items: '{{ instanceIds }}'
      Outputs:
        dataDisks:
          AggregateType: 'Fn::ListJoin'
          AggregateField: instanceDataDisks
        systemDisks:
          AggregateType: 'Fn::ListJoin'
          AggregateField: instanceSystemDisk
  - Name: createImage
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Create Image
      zh-cn: 建立鏡像
    Properties:
      Service: ECS
      API: CreateImage
      Parameters:
        RegionId: '{{ regionId }}'
        ImageName: 'img-{{ ACS::TaskLoopItem }}-{{ACS::ExecutionId}}'
        InstanceId: '{{ ACS::TaskLoopItem }}'
        DetectionStrategy: Standard
    Loop:
      Items: '{{ instanceIds }}'
      Outputs:
        ImageIds:
          AggregateType: 'Fn::ListJoin'
          AggregateField: ImageId
    Outputs:
      ImageId:
        ValueSelector: ImageId
        Type: String
  - Name: untilCreateImageReady
    Action: 'ACS::WaitFor'
    Description:
      en: Wait For created images available
      zh-cn: 等待鏡像建立成功
    Properties:
      Service: ECS
      API: DescribeImages
      Parameters:
        RegionId: '{{ regionId }}'
        ImageId: '{{ ACS::TaskLoopItem }}'
      DesiredValues:
        - Available
      PropertySelector: 'Images.Image[].Status'
    Loop:
      Items: '{{ createImage.ImageIds }}'
    Retries: 57
  - Name: copyImage
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Copy image
      zh-cn: 複製鏡像
    Properties:
      Service: ECS
      API: CopyImage
      Parameters:
        RegionId: '{{ regionId }}'
        ImageId: '{{ ACS::TaskLoopItem }}'
        DestinationRegionId: '{{ targetRegionId }}'
    Loop:
      Items: '{{ createImage.ImageIds }}'
      Outputs:
        ImageIds:
          AggregateType: 'Fn::ListJoin'
          AggregateField: ImageId
    Outputs:
      ImageId:
        ValueSelector: ImageId
        Type: String
  - Name: untilCopyImageReady
    Action: 'ACS::WaitFor'
    Description:
      en: Wait for copied images available
      zh-cn: 等待鏡像複製成功
    Properties:
      Service: ECS
      API: DescribeImages
      Parameters:
        RegionId: '{{ targetRegionId }}'
        ImageId: '{{ ACS::TaskLoopItem }}'
      DesiredValues:
        - Available
      PropertySelector: 'Images.Image[].Status'
    Loop:
      Items: '{{ copyImage.ImageIds }}'
  - Name: runInstances
    Action: 'ACS::ExecuteAPI'
    Description:
      en: run instances
      zh-cn: 建立執行個體
    Properties:
      Service: ECS
      API: RunInstances
      Parameters:
        RegionId: '{{ targetRegionId }}'
        ZoneId: '{{ targetZoneId }}'
        ImageId:
          'Fn::Select':
              - '{{ ACS::TaskLoopItem }}'
              - '{{ copyImage.ImageIds }}'
        DataDisks:
          'Fn::Select':
            - '{{ ACS::TaskLoopItem }}'
            - '{{queryDisks.dataDisks}}'
        SystemDiskCategory:
          'Fn::Select':
            - Category
            - 'Fn::Select':
                - '{{ ACS::TaskLoopItem }}'
                - '{{ queryDisks.systemDisks }}'
        SystemDiskSize:
          'Fn::Select':
            - Size
            - 'Fn::Select':
                - '{{ ACS::TaskLoopItem }}'
                - '{{ queryDisks.systemDisks }}'
        SystemDiskDiskName:
          'Fn::Select':
            - DiskName
            - 'Fn::Select':
                - '{{ ACS::TaskLoopItem }}'
                - '{{ queryDisks.systemDisks }}'
        SystemDiskPerformanceLevel:
          'Fn::Select':
            - PerformanceLevel
            - 'Fn::Select':
                - '{{ ACS::TaskLoopItem }}'
                - '{{ queryDisks.systemDisks }}'
        InstanceType: '{{ targetInstanceType }}'
        SecurityGroupId: '{{ targetSecurityGroupId }}'
        VSwitchId: '{{ targetVSwitchId }}'
    Loop:
      Items:
        'Fn::Jq':
          - All
          - '.|length|range(.)'
          - '{{ instanceIds }}'
      Outputs:
        instanceIds:
          AggregateType: 'Fn::ListJoin'
          AggregateField: instanceId
    Outputs:
      instanceId:
        Type: String
        ValueSelector: 'InstanceIdSets.InstanceIdSet[]'
  - Name: untilInstanceReady
    Action: 'ACS::WaitFor'
    Description:
      en: Wait for instances running
      zh-cn: 等待執行個體建立成功
    Properties:
      Service: ECS
      API: DescribeInstances
      Parameters:
        RegionId: '{{ targetRegionId }}'
        InstanceIds: '{{ runInstances.instanceIds }}'
      DesiredValues:
        - Running
      PropertySelector: '.Instances.Instance[].Status'
Outputs:
  instanceIds:
    Value: '{{ runInstances.instanceIds }}'
    Type: List
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - targetRegionId
          - targetZoneId
          - targetInstanceType
          - targetSecurityGroupId
          - targetVSwitchId
        Label:
          default:
            zh-cn: 設定參數
            en: Configure Parameters
      - Parameters:
          - regionId
          - instanceIds
        Label:
          default:
            zh-cn: 選擇執行個體
            en: Select Ecs Instances
      - Parameters:
          - OOSAssumeRole
        Label:
          default:
            zh-cn: 進階選項
            en: Control Options