日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

使用Count功能批量創建資源

資源編排服務ROS(Resource Orchestration Service)支持Count功能,用于批量創建資源。本文將以批量創建ECS實例和EIP,并為ECS實例綁定EIP為例,為您介紹如何使用Count功能。

背景信息

ALIYUN::VPC::EIP類型用于申請彈性公網IP(EIP)。如果需要申請多個彈性公網IP,則需要在模板中編寫多個ALIYUN::VPC::EIP資源,這樣模板會變得冗長。此時您可以使用Count功能批量創建資源。Count功能詳情,請參見Count。此外,使用Count批量創建多組資源時可以通過為資源指定DependsOn并設置參數(ParallelCount)進行資源創建的并發控制。

步驟一:編寫模板

您可以使用Count功能編寫模板,創建以下資源:

  • 1個VPC(專有網絡)

  • 1個vSwitch(交換機)

  • 1個SecurityGroup(安全組)

  • 4個ECS(按量付費的ECS)

  • 4個EIP(彈性公網IP)

模板示例代碼和模板說明如下:

  • 模板示例代碼

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      Count:
        Type: Number
        Default: 4
      ZoneId:
        Type: String
      InstanceType:
        Type: String
        Default: ecs.c6.large
      Password:
        Type: String
        Default: Abc1****
        NoEcho: true
      ParallelCount:
        Type: Number
        Default: 2
      SystemDiskCategory:
        Type: String
    Resources:
      Vpc:
        Type: ALIYUN::ECS::VPC
        Properties:
          CidrBlock: 10.0.0.0/8
          VpcName: test-resource-count
      VSwitch:
        Type: ALIYUN::ECS::VSwitch
        Properties:
          CidrBlock: 10.0.10.0/24
          ZoneId:
            Ref: ZoneId
          VpcId:
            Ref: Vpc
      SecurityGroup:
        Type: ALIYUN::ECS::SecurityGroup
        Properties:
          SecurityGroupName: test-resource-count
          VpcId:
            Ref: Vpc
      Eip:
        Type: ALIYUN::VPC::EIP
        Count:
          Ref: Count
        DependsOn:
          Fn::Select:
            - Fn::Calculate:
                - 1-{0}//{1}
                - 0
                - - Fn::Min:
                      - Ref: ALIYUN::Index
                      - Ref: ParallelCount
                  - Ref: ParallelCount
            - - Fn::Replace:
                  - index:
                      Fn::Calculate:
                        - '{0}-{1}'
                        - 0
                        - - Ref: ALIYUN::Index
                          - Ref: ParallelCount
                  - Eip[index]
        Properties:
          Bandwidth: 5
      Servers:
        Type: ALIYUN::ECS::InstanceGroup
        Properties:
          ImageId: centos_7
          InstanceType:
            Ref: InstanceType
          VpcId:
            Ref: Vpc
          VSwitchId:
            Ref: VSwitch
          SecurityGroupId:
            Ref: SecurityGroup
          Password:
            Ref: Password
          AllocatePublicIP: false
          MaxAmount:
            Ref: Count
          SystemDiskCategory:
            Ref: SystemDiskCategory
      EipBind:
        Type: ALIYUN::VPC::EIPAssociation
        Count:
          Ref: Count
        DependsOn:
          Fn::Select:
            - Fn::Calculate:
                - 1-{0}//{1}
                - 0
                - - Fn::Min:
                      - Ref: ALIYUN::Index
                      - Ref: ParallelCount
                  - Ref: ParallelCount
            - - Fn::Replace:
                  - index:
                      Fn::Calculate:
                        - '{0}-{1}'
                        - 0
                        - - Ref: ALIYUN::Index
                          - Ref: ParallelCount
                  - EipBind[index]
        Properties:
          InstanceId:
            Fn::Select:
              - Ref: ALIYUN::Index
              - Fn::GetAtt:
                  - Servers
                  - InstanceIds
          AllocationId:
            Fn::Select:
              - Ref: ALIYUN::Index
              - Ref: Eip
    Outputs:
      InstanceIds:
        Value:
          Fn::GetAtt:
            - Servers
            - InstanceIds
      AllocationIds:
        Value:
          Ref: Eip
      EipAddresses:
        Value:
          Fn::GetAtt:
            - Eip
            - EipAddress
  • 模板說明

    • 創建4個EIP。

      Count取值為4。使用Count功能時,ParallelCount取值為2,此時會分兩批創建4個EIP資源。通過ROS的預處理,會生成名為Eip[0]和Eip[1](第一批)、Eip[2]和Eip[3](第二批)的4個EIP資源。

      Eip:
        Type: ALIYUN::VPC::EIP
        Count:
          Ref: Count
        DependsOn:
          Fn::Select:
            - Fn::Calculate:
                - 1-{0}//{1}
                - 0
                - - Fn::Min:
                      - Ref: ALIYUN::Index
                      - Ref: ParallelCount
                  - Ref: ParallelCount
            - - Fn::Replace:
                  - index:
                      Fn::Calculate:
                        - '{0}-{1}'
                        - 0
                        - - Ref: ALIYUN::Index
                          - Ref: ParallelCount
                  - Eip[index]
        Properties:
          Bandwidth: 5
    • 創建4個ECS實例。

      Count取值為4。將ALIYUN::ECS::InstanceGroup的MaxAmount指定為Count,取值為4,生成4個ECS資源。

      Servers:
        Type: ALIYUN::ECS::InstanceGroup
        Properties:
          ImageId: centos_7
          InstanceType:
            Ref: InstanceType
          VpcId:
            Ref: Vpc
          VSwitchId:
            Ref: VSwitch
          SecurityGroupId:
            Ref: SecurityGroup
          Password:
            Ref: Password
          AllocatePublicIP: false
          MaxAmount:
            Ref: Count
          SystemDiskCategory:
            Ref: SystemDiskCategory
    • 創建4個EipBind資源,通過ALIYUN::Index偽參數逐一綁定ECS實例和EIP。

      Count取值為4。使用Count功能時,ParallelCount取值為2,此時會分兩批創建4個EipBind資源。通過ROS的預處理,會生成名為EipBind[0]和EipBind[1](第一批)、EipBind[2]和EipBind[3](第二批)的4個資源。ALIYUN::Index在Count中使用,在預處理時會被替換為相應的數值。本示例中將逐一綁定ECS實例與EIP,即第1個實例綁定Eip[0]、第2個實例綁定Eip[1]、第3個實例綁定Eip[2]、第4個實例綁定Eip[3]。

      EipBind:
        Type: ALIYUN::VPC::EIPAssociation
        Count:
          Ref: Count
        DependsOn:
          Fn::Select:
            - Fn::Calculate:
                - 1-{0}//{1}
                - 0
                - - Fn::Min:
                      - Ref: ALIYUN::Index
                      - Ref: ParallelCount
                  - Ref: ParallelCount
            - - Fn::Replace:
                  - index:
                      Fn::Calculate:
                        - '{0}-{1}'
                        - 0
                        - - Ref: ALIYUN::Index
                          - Ref: ParallelCount
                  - EipBind[index]
        Properties:
          InstanceId:
            Fn::Select:
              - Ref: ALIYUN::Index
              - Fn::GetAtt:
                  - Servers
                  - InstanceIds
          AllocationId:
            Fn::Select:
              - Ref: ALIYUN::Index
              - Ref: Eip

步驟二:創建資源棧

  1. 登錄資源編排控制臺

  2. 在左側導航欄單擊資源棧

  3. 在頂部菜單欄的地域下拉列表,選擇資源棧的所在地域,例如:華東1(杭州)。

  4. 資源棧列表頁面,單擊創建資源棧,然后在下拉列表中選擇使用ROS

  5. 選擇模板頁面的指定模板區域,單擊選擇已有模板

  6. 模板錄入方式區域單擊輸入模板,輸入步驟一:編寫模板中編寫的模板內容,然后單擊下一步

  7. 配置參數頁面,根據控制臺提示,配置資源棧名稱模板參數

  8. 配置資源棧區塊,根據控制臺提示,配置資源棧策略失敗時回滾超時設置刪除保護RAM角色標簽資源組,然后單擊下一步

    資源的創建或更新未在超時設置的時間內完成,系統自動判斷該操作失敗,再根據失敗時回滾設置,判斷是否回滾到創建或更新資源之前的狀態。

  9. 合規預檢頁面,完成合規檢測,然后單擊下一步

    說明

    目前合規預檢功能僅支持為部分資源提供合規預檢功能。更多信息,請參見資源編排支持合規預檢

    1. 檢測規則區域,添加檢測規則。

      您可以根據ROS模板中的云資源選擇需要檢測的規則。

    2. 單擊開始檢測

      您可以根據不合規或不適用資源的修正方案修改模板內容,從而保證資源的合規性。

  10. 檢查并確認頁面,單擊創建

步驟三(可選):查詢資源和模板

資源棧創建成功后,您可以按需在資源棧詳情頁查詢經過ROS預處理的資源和模板信息。

  1. 在資源棧詳情頁,單擊資源頁簽,查詢資源信息。

  2. 在資源棧詳情頁,單擊模板頁簽,查詢模板信息。

    本文示例中,預處理后的模板如下:

    ROSTemplateFormatVersion: '2015-09-01'
    Resources:
      EipBind[1]:
        Type: ALIYUN::VPC::EIPAssociation
        Properties:
          InstanceId:
            Fn::Select:
              - 1
              - Fn::GetAtt:
                  - Servers
                  - InstanceIds
          AllocationId:
            Ref: Eip[1]
      Eip[1]:
        Type: ALIYUN::VPC::EIP
        Properties:
          Bandwidth: 5
      SecurityGroup:
        Type: ALIYUN::ECS::SecurityGroup
        Properties:
          VpcId:
            Ref: Vpc
          SecurityGroupName: test-resource-count
      Servers:
        Type: ALIYUN::ECS::InstanceGroup
        Properties:
          SystemDiskCategory:
            Ref: SystemDiskCategory
          VpcId:
            Ref: Vpc
          SecurityGroupId:
            Ref: SecurityGroup
          ImageId: centos_7
          AllocatePublicIP: false
          VSwitchId:
            Ref: VSwitch
          Password:
            Ref: Password
          InstanceType:
            Ref: InstanceType
          MaxAmount:
            Ref: Count
      Eip[2]:
        Type: ALIYUN::VPC::EIP
        Properties:
          Bandwidth: 5
        DependsOn: Eip[0]
      Eip[0]:
        Type: ALIYUN::VPC::EIP
        Properties:
          Bandwidth: 5
      Vpc:
        Type: ALIYUN::ECS::VPC
        Properties:
          VpcName: test-resource-count
          CidrBlock: 10.0.0.0/8
      Eip[3]:
        Type: ALIYUN::VPC::EIP
        Properties:
          Bandwidth: 5
        DependsOn: Eip[1]
      VSwitch:
        Type: ALIYUN::ECS::VSwitch
        Properties:
          VpcId:
            Ref: Vpc
          CidrBlock: 10.0.10.0/24
          ZoneId:
            Ref: ZoneId
      EipBind[3]:
        Type: ALIYUN::VPC::EIPAssociation
        Properties:
          InstanceId:
            Fn::Select:
              - 3
              - Fn::GetAtt:
                  - Servers
                  - InstanceIds
          AllocationId:
            Ref: Eip[3]
        DependsOn: EipBind[1]
      EipBind[0]:
        Type: ALIYUN::VPC::EIPAssociation
        Properties:
          InstanceId:
            Fn::Select:
              - 0
              - Fn::GetAtt:
                  - Servers
                  - InstanceIds
          AllocationId:
            Ref: Eip[0]
      EipBind[2]:
        Type: ALIYUN::VPC::EIPAssociation
        Properties:
          InstanceId:
            Fn::Select:
              - 2
              - Fn::GetAtt:
                  - Servers
                  - InstanceIds
          AllocationId:
            Ref: Eip[2]
        DependsOn: EipBind[0]
    Parameters:
      Count:
        Default: 4
        Type: Number
      SystemDiskCategory:
        Type: String
      ZoneId:
        Type: String
      Password:
        Default: Abc1****
        NoEcho: true
        Type: String
      InstanceType:
        Default: ecs.c6.large
        Type: String
      ParallelCount:
        Default: 2
        Type: Number
    Outputs:
      AllocationIds:
        Value:
          - Ref: Eip[0]
          - Ref: Eip[1]
          - Ref: Eip[2]
          - Ref: Eip[3]
      InstanceIds:
        Value:
          Fn::GetAtt:
            - Servers
            - InstanceIds
      EipAddresses:
        Value:
          - Fn::GetAtt:
              - Eip[0]
              - EipAddress
          - Fn::GetAtt:
              - Eip[1]
              - EipAddress
          - Fn::GetAtt:
              - Eip[2]
              - EipAddress
          - Fn::GetAtt:
              - Eip[3]
              - EipAddress