资源编排服务 RFS-ECS.CloudServer:blueprint样例

时间:2024-04-18 10:02:52

blueprint样例

以编排CloudServer资源的blueprint为例:

  • 在现有的VPC、Subnet下创建E CS 实例
    tosca_definitions_version: huaweicloud_tosca_version_1_0
    inputs:
      ecs-name:
        default: "my-cloudserver"
      ecs-image:
        default: "327946b5-e954-42c3-949a-3312688c9269"
      ecs-flavor:
        default: "c2.large"
      vpc-id:
        default: "ba6e4347-99d2-4649-b114-85c28d3d71b0"
      az:
        default: "az1.dc1"
      subnet-vpcid:
        default: "3be61f68-9bfc-41bf-8f5e-66c57122f270"
      ecs-volumetype:
        default: "SATA"
      ecs-sshKeyName:
        default: "KeyPair-magento"
    node_templates:
      my-ecs:
        type: HuaweiCloud.ECS.CloudServer
        properties:
          name: {get_input: ecs-name}
          instances: 2
          imageId: {get_input: ecs-image}
          flavor: {get_input: ecs-flavor}
          vpcId: {get_input: vpc-id}
          availabilityZone: {get_input: az}
          nics:
            - subnetId: {get_input: subnet-vpcid}
          rootVolume: 
            volumeType: {get_input: ecs-volumetype}
          dataVolumes:
            - volumeType: SATA
              size: 100
          sshKeyName: {get_input: ecs-sshKeyName}
  • 与VPC、Subnet联动,在新创建的VPC、Subnet下自动创建CloudServer

    如果您没有创建过VPC、Subnet,或不需要使用已有的VPC、Subnet,那么可以通过一个blueprint文件,同时创建VPC、Subnet和CloudServer,创建CloudServer时可以自动关联新创建的VPC和Subnet。如下示例所描述:

    • 在Subnet中加入依赖关系requirements,这样在blueprint执行时,会先创建Subnet所依赖的对象。
    • 在Subnet中的vpcId字段,取值,使用了get_attribute函数,来获取所创建的VPC(my-vpc)的响应属性refID。
    • 在CloudServer中的vpcId、nics的subnetId字段,取值,使用了get_attribute函数,来获取所创建的subnet(my-subnet)的响应属性refID。
    tosca_definitions_version: huaweicloud_tosca_version_1_0
    inputs:
      ecs-name:
        default: "my-cloudserver"
      ecs-image:
        default: "327946b5-e954-42c3-949a-3312688c9269"
      ecs-flavor:
        default: "c2.large"
      ecs-volumetype:
        default: "SATA"
      az:
        default: "az1.dc1"
      subnet-name:
        default: "my-ecs-subnet2"
      subnet-cidr:
        default: "192.168.1.0/24"
      subnet-gateway:
        default: "192.168.1.1"
      vpc-name:
        default: "my-ecs-vpc2"
      vpc-cidr:
        default: "192.168.0.0/16"
    node_templates:
      my-ecs:
        type: HuaweiCloud.ECS.CloudServer
        properties:
          name: {get_input: ecs-name}
          instances: 1
          imageId: {get_input: ecs-image}
          flavor: {get_input: ecs-flavor}
          vpcId: {get_attribute: [my-vpc, refID]}
          availabilityZone: {get_input: az}
          nics:
            - subnetId: {get_attribute: [my-subnet, refID]}
          rootVolume: 
            volumeType: {get_input: ecs-volumetype}
          dataVolumes:
            - volumeType: SATA
              size: 100
        requirements:
          - nics.subnetId:
              node: my-subnet
              relationship: HuaweiCloud.Relationships.ConnectsTo
      my-subnet:
        type: HuaweiCloud.VPC.Subnet
        properties:
          name: {get_input: subnet-name}
          cidr: {get_input: subnet-cidr}
          gateway: {get_input: subnet-gateway}
          dnsList: [114.114.114.115,114.114.114.114]
          vpcId: {get_attribute: [my-vpc, refID]}
          availabilityZone: {get_input: az}
        requirements:
          - vpcId:
              node: my-vpc
              relationship: HuaweiCloud.Relationships.ContainedIn
      my-vpc:
        type: HuaweiCloud.VPC.VPC
        properties:
          name: {get_input: vpc-name}
          cidr: {get_input: vpc-cidr}
support.huaweicloud.com/tr-aos/ecs-cloudserver.html