Cloud Assembly 範本設計可以部署機器叢集並連結磁碟叢集。
若要部署機器叢集和磁碟叢集,請在雲端範本中利用 allocatePerInstance
資源旗標以及 count.index
和 map_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}