Cloud Assembly 模板设计可以部署计算机集群和连接磁盘集群。

要部署计算机和磁盘集群,请在云模板中利用 allocatePerInstance 资源标志以及 count.indexmap_to_object 表达式语法

以下云模板代码示例可以作为部署集群的设计准则。

两个计算机共享一个磁盘集群

resources:
  app0:
    type: Cloud.Machine
    allocatePerInstance: true
    properties:
      image: ubuntu
      flavor: small
      attachedDisks: '${map_to_object(slice(resource.disk[*].id, 0,2), "source")}'
  app1:
    type: Cloud.Machine
    allocatePerInstance: true
    properties:
      image: ubuntu
      flavor: small
      attachedDisks: '${map_to_object(slice(resource.disk[*].id, 2,4), "source")}'
  disk:
    type: Cloud.Volume
    allocatePerInstance: true
    properties:
      count: 4
      capacityGb: 5

计算机数量不等,且每个计算机具有一个磁盘

inputs:
  count:
    type: integer
    default: 2
resources:
  Cloud_Machine_1:
    type: Cloud.Machine
    allocatePerInstance: true
    properties:
      image: ubuntu
      flavor: small
      count: '${input.count}'
      attachedDisks: '${map_to_object(slice(resource.disk[*].id, count.index, count.index + 1), "source")}'
  disk:
    type: Cloud.Volume
    allocatePerInstance: true
    properties:
      count: '${input.count}'
      capacityGb: 5

计算机数量不等,且每个计算机具有两个磁盘

inputs:
  count:
    type: integer
    default: 2
resources:
  Cloud_Machine_1:
    type: Cloud.Machine
    allocatePerInstance: true
    properties:
      image: ubuntu
      flavor: small
      count: ${input.count}
      attachedDisks: '${map_to_object(slice(resource.disk[*].id, 2*count.index, 2*(count.index + 1)), "source")}'
  disk:
    type: Cloud.Volume
    allocatePerInstance: true
    properties:
      count: ${2*input.count}
      capacityGb: 5

在请求时设置磁盘大小

inputs:
  disksize:
    type: array
    minItems: 2
    maxItems: 2
    items:
      type: object
      properties:
        size:
          type: integer
resources:
  app:
    type: Cloud.Machine
    allocatePerInstance: true
    properties:
      flavor: small
      image: ubuntu
      attachedDisks: ${map_to_object(slice(resource.disk[*].id, 0, 2), 'source')}
  disk:
    type: Cloud.Volume
    allocatePerInstance: true
    properties:
      count: 2
      capacityGb: ${input.disksize[count.index].size}