-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS-ECS-UpdateImage.yml
588 lines (588 loc) · 17.8 KB
/
ACS-ECS-UpdateImage.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
FormatVersion: OOS-2019-06-01
Description:
en: 'Update an existing ECS image by running commands and create a new ECS image. This is applicable to scenarios requiring batch updates and management of ECS images, such as software installation and system configuration changes. During configuration, users need to provide the following required parameters: Region ID (regionId), which specifies the region where the image update and creation operations occur, and Source Image ID (sourceImageId), which identifies the original ECS image that needs updating. Additional parameters that can be modified from their default values include: Target Image Name (targetImageName) for naming the newly created ECS image, Instance Type (instanceType) for the type of instance to install and configure the new image on, and Update Type (updateType), which can be selected to either run commands or install packages. Upon execution, the template will return the ID of the newly created image, facilitating the verification and management of the created ECS image.'
zh-cn: 通过运行命令更新一个已存在的ECS镜像后创建一个新ECS镜像,适用于需要对ECS镜像进行批量更新和管理的场景,例如软件安装和系统配置更改。在配置过程中,用户需要提供以下必填参数信息,地域ID(regionId):用于指定创建和更新镜像的操作区域,源镜像ID(sourceImageId):用于指定需要更新的原始ECS镜像。其他可在默认值基础上修改的参数包括:目标镜像名称(targetImageName):用于为新创建的ECS镜像命名,实例类型(instanceType):用于安装和配置新的镜像实例类型,以及更新方式(updateType):可选择运行命令或安装软件包。模板在执行后会返回新创建的镜像ID,方便用户验证和管理创建的ECS镜像。
name-en: Update Image
name-zh-cn: 更新镜像
categories:
- image_manage
- application_manage
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: 地域ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
zoneId:
Type: String
Label:
en: VSwitch Availability Zone
zh-cn: 交换机可用区
Default: ''
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
AssociationPropertyMetadata:
RegionId: regionId
targetImageName:
Label:
en: TargetImageName
zh-cn: 新镜像的名称
Type: String
Description:
en: <p class="p">Note:</p> <ul class="ul"> <li class="li">Length is 2~128 English or Chinese characters</li> <li class="li"><font color='red'>must start with big or small letters or Chinese, not http:// and https://. </font></li> <li class="li">Can contain numbers, colons (:), underscores (_), or dashes (-). </li> </ul>
zh-cn: <p class="p">注意:</p> <ul class="ul"> <li class="li">长度为2~128个英文或中文字符</li> <li class="li"><font color='red'>必须以大小字母或中文开头,不能以http://和https://开头。</font></li> <li class="li">可以包含数字、半角冒号(:)、下划线(_)或者短划线(-)。</li> </ul>
Default: 'UpdateImage_from_{{sourceImageId}}_on_{{ACS::ExecutionId}}'
sourceImageId:
Label:
en: SourceImageId
zh-cn: 源镜像ID
Type: String
AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
AssociationPropertyMetadata:
RegionId: regionId
ImageOwnerAlias:
- self
instanceType:
Label:
en: InstanceType
zh-cn: 实例类型
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
RegionId: regionId
ZoneId: zoneId
whetherCreateVpc:
Type: Boolean
Label:
en: WhetherCreateVpc
zh-cn: 是否新建VPC
Default: false
vpcCidrBlock:
Type: String
Label:
en: VPC CIDR IPv4 Block
zh-cn: 专有网络IPv4网段
Description:
zh-cn: VPC的ip地址段范围,<br>您可以使用以下的ip地址段或其子网:<br><font color='green'>[10.0.0.0/8]</font><br><font color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
en: 'The ip address range of the VPC in the CidrBlock form; <br>You can use the following ip address ranges and their subnets: <br><font color=''green''>[10.0.0.0/8]</font><br><font color=''green''>[172.16.0.0/12]</font><br><font color=''green''>[192.168.0.0/16]</font>'
Default: 192.168.0.0/16
AssociationProperty: ALIYUN::VPC::VPC::CidrBlock
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${whetherCreateVpc}
- true
vSwitchCidrBlock:
Type: String
Label:
en: VSwitch CIDR Block
zh-cn: 交换机子网网段
Description:
zh-cn: 必须属于VPC的子网段
en: Must belong to the subnet segment of VPC
Default: 192.168.1.0/24
AssociationProperty: ALIYUN::VPC::VSwitch::CidrBlock
AssociationPropertyMetadata:
VpcCidrBlock: vpcCidrBlock
Visible:
Condition:
Fn::Equals:
- ${whetherCreateVpc}
- true
securityGroupId:
Label:
en: SecurityGroupId
zh-cn: 安全组ID
Type: String
Default: ''
AssociationProperty: 'ALIYUN::ECS::SecurityGroup::SecurityGroupId'
AssociationPropertyMetadata:
RegionId: regionId
Visible:
Condition:
Fn::Equals:
- ${whetherCreateVpc}
- false
vSwitchId:
Label:
en: VSwitchId
zh-cn: 交换机ID
Type: String
Default: ''
AssociationProperty: 'ALIYUN::VPC::VSwitch::VSwitchId'
AssociationPropertyMetadata:
RegionId: regionId
ZoneId: zoneId
Filters:
- SecurityGroupId: securityGroupId
Visible:
Condition:
Fn::Equals:
- ${whetherCreateVpc}
- false
internetMaxBandwidthOut:
Type: Number
Label:
zh-cn: 流量公网带宽
en: Internet Max Bandwidth Out
Description:
zh-cn: 取值范围0-100, 0为不开公网ip
en: no public ip if zero
Default: 0
MinValue: 0
MaxValue: 100
ramRoleName:
Label:
en: RamRoleName
zh-cn: 实例的RAM角色
Type: String
AssociationProperty: ALIYUN::ECS::RAM::Role
Default: ''
systemDiskCategory:
Label:
en: SystemDiskCategory
zh-cn: 系统盘的云盘种类
Type: String
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
RegionId: regionId
InstanceType: instanceType
Default: cloud_essd
systemDiskSize:
Label:
en: SystemDiskSize
zh-cn: 系统盘大小
Description:
zh-cn: 系统盘大小,单位GB,普通云盘容量:20-500G,ESSD云盘PL0:1-2048G,ESSD云盘PL1:20-2048G,ESSD云盘PL2:461-2048G,ESSD云盘PL3:1261-2048G,ESSD AutoPL云盘:1-2048G,其他云盘类型:20-2048G.
en: 'System disk size, in GB, regular cloud: 20-500G, cloud_essd PL0:1-2048G, cloud_essd PL1:20-2048G, cloud_essd PL2:461-2048G, cloud_essd PL3:1261-2048G, ESSD AutoPL cloud disk: 1-2048G, other cloud disk types: 20-2048G.'
ConstraintDescription:
zh-cn: 必须输入整数,单位GB
en: 'Must be an integer.'
Type: String
Default: ''
commandType:
Label:
en: CommandType
zh-cn: 云助手命令类型
Type: String
AssociationPropertyMetadata:
LocaleKey: PricingCycle
Visible:
Condition:
Fn::Equals:
- ${updateType}
- RunCommand
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
tags:
Label:
en: Tags
zh-cn: 镜像标签
Type: Json
AssociationProperty: Tags
AssociationPropertyMetadata:
ShowSystem: false
Default: []
commandContent:
Label:
en: CommandContent
zh-cn: 在ECS实例中执行的云助手命令
Type: String
AssociationProperty: Code
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${updateType}
- RunCommand
Default: 'echo hello'
contentEncoding:
Label:
en: ContentEncoding
zh-cn: 命令编码方式
Type: String
Default: PlainText
timeout:
Label:
en: Timeout
zh-cn: 超时时间
Type: Number
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${updateType}
- RunCommand
Default: 600
updateType:
Label:
en: UpdateType
zh-cn: 更新方式
Type: String
AllowedValues:
- RunCommand
- InstallPackage
Default: RunCommand
AssociationPropertyMetadata:
ValueLabelMapping:
RunCommand:
zh-cn: 运行命令
en: RunCommand
InstallPackage:
zh-cn: 安装软件包
en: InstallPackage
packageName:
Label:
en: packageName
zh-cn: 要配置的软件包名称
Type: String
Default: ''
AssociationProperty: 'ALIYUN::OOS::Package::PackageName'
AssociationPropertyMetadata:
RegionId: regionId
Visible:
Condition:
Fn::Equals:
- ${updateType}
- InstallPackage
packageVersion:
Label:
en: packageVersion
zh-cn: 要配置的软件包版本
Type: String
AssociationProperty: 'ALIYUN::OOS::Package::PackageVersion'
AssociationPropertyMetadata:
TemplateName: ${packageName}
Visible:
Condition:
Fn::Equals:
- ${updateType}
- InstallPackage
Default: ''
parameters:
Label:
en: Parameters
zh-cn: 命令中的参数
Type: Json
Default: {}
AssociationProperty: TemplateParameter
AssociationPropertyMetadata:
TemplateName: packageName
TemplateVersion: packageVersion
TemplateType: Package
Visible:
Condition:
Fn::Equals:
- ${updateType}
- InstallPackage
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: checkNewImageName
Action: ACS::CheckFor
Description:
en: Check image name is available
zh-cn: 检查镜像名称是可用的
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ regionId }}'
ImageName: '{{ targetImageName }}'
DesiredValues:
- 0
PropertySelector: TotalCount
- Name: createStack
Action: 'ACS::ExecuteAPI'
When:
Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
Description:
en: Create a resource stack
zh-cn: 创建资源栈
Properties:
Service: ROS
API: CreateStack
Parameters:
RegionId: '{{ regionId }}'
StackName: 'OOS-{{ACS::ExecutionId}}'
TimeoutInMinutes: 10
DisableRollback: false
Parameters:
- ParameterKey: ZoneId
ParameterValue: '{{ zoneId }}'
- ParameterKey: VpcCidrBlock
ParameterValue: '{{ vpcCidrBlock }}'
- ParameterKey: VSwitchCidrBlock
ParameterValue: '{{ vSwitchCidrBlock }}'
TemplateBody: |
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
ZoneId:
Type: String
VpcCidrBlock:
Type: String
VSwitchCidrBlock:
Type: String
Resources:
EcsVpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: ALIYUN::StackName
EcsVSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: EcsVpc
CidrBlock:
Ref: VSwitchCidrBlock
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: EcsVpc
Outputs:
SecurityGroupId:
Value:
Ref: EcsSecurityGroup
VSwitchId:
Value:
Ref: EcsVSwitch
Outputs:
StackId:
Type: String
ValueSelector: StackId
- Name: untilStackReady
Action: 'ACS::WaitFor'
When:
Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
Description:
en: Wait for the stack status CREATE_COMPLETE
zh-cn: 等待资源栈至创建成功状态
OnError: deleteStack
Properties:
Service: ROS
API: GetStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{createStack.StackId}}'
DesiredValues:
- CREATE_COMPLETE
StopRetryValues:
- CREATE_FAILED
- CHECK_FAILED
- ROLLBACK_FAILED
- ROLLBACK_COMPLETE
- CREATE_ROLLBACK_COMPLETE
PropertySelector: Status
Outputs:
securityGroupId:
Type: String
ValueSelector: 'Outputs[0].OutputValue'
vSwitchId:
Type: String
ValueSelector: 'Outputs[1].OutputValue'
- Name: runInstances
Action: ACS::ECS::RunInstances
Description:
en: Create a ECS instance with source image
zh-cn: 用源镜像创建一台ECS实例
OnError: deleteStack
Properties:
regionId: '{{ regionId }}'
imageId: '{{ sourceImageId }}'
instanceType: '{{ instanceType }}'
securityGroupId:
Fn::If:
- Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
- '{{ untilStackReady.securityGroupId }}'
- '{{ securityGroupId }}'
vSwitchId:
Fn::If:
- Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
- '{{ untilStackReady.vSwitchId }}'
- '{{ vSwitchId }}'
internetMaxBandwidthOut: '{{ internetMaxBandwidthOut }}'
ramRoleName: '{{ ramRoleName }}'
systemDiskCategory: '{{ systemDiskCategory }}'
systemDiskSize: '{{ systemDiskSize }}'
Outputs:
instanceId:
ValueSelector: instanceIds[0]
Type: String
- Name: installCloudAssistant
Action: ACS::ECS::InstallCloudAssistant
Description:
en: Install cloud assistant for ECS instance
zh-cn: 给实例安装云助手
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ runInstances.instanceId }}'
- Name: runCommand
Action: ACS::ECS::RunCommand
When:
Fn::Equals:
- '{{ updateType }}'
- RunCommand
Description:
en: Run cloud assistant command on ECS instance
zh-cn: 在实例中运行云助手命令
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
commandContent: '{{ commandContent }}'
contentEncoding: '{{ contentEncoding }}'
commandType: '{{ commandType }}'
instanceId: '{{ runInstances.instanceId }}'
timeout: '{{ timeout }}'
- Name: configurePackage
Action: ACS::ECS::ConfigureOOSPackageWithTemporaryURL
Description:
en: Configure Package
zh-cn: 配置软件包
When:
Fn::Equals:
- '{{ updateType }}'
- InstallPackage
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ runInstances.instanceId }}'
packageName: '{{ packageName }}'
packageVersion: '{{ packageVersion }}'
parameters: '{{ parameters }}'
Outputs:
commandOutput:
Type: String
ValueSelector: .commandOutput
- Name: stopInstance
Action: ACS::ECS::StopInstance
Description:
en: Stops the ECS instance
zh-cn: 停止ECS实例
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ runInstances.instanceId }}'
- Name: createImage
Action: ACS::ECS::CreateImage
Description:
en: Create new image with the specified image name and instance ID
zh-cn: 通过指定实例ID和镜像名称创建新的镜像
OnError: deleteInstance
Properties:
regionId: '{{ regionId }}'
imageName: '{{ targetImageName }}'
instanceId: '{{ runInstances.instanceId }}'
tags: '{{tags}}'
Outputs:
imageId:
ValueSelector: imageId
Type: String
- Name: deleteInstance
Action: ACS::ExecuteAPI
Description:
en: Deletes the ECS instance
zh-cn: 删除ECS实例
Properties:
Service: ECS
API: DeleteInstance
Risk: Normal
Parameters:
RegionId: '{{ regionId }}'
InstanceId: '{{ runInstances.instanceId }}'
Force: true
- Name: deleteStack
Action: 'ACS::ExecuteApi'
When:
Fn::Equals:
- '{{ whetherCreateVpc }}'
- true
Description:
en: Delete the stack
zh-cn: 删除资源栈
Properties:
Service: ROS
API: DeleteStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{ createStack.StackId }}'
Outputs:
imageId:
Type: String
Value: '{{ createImage.imageId }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- regionId
- sourceImageId
Label:
default:
zh-cn: 选择源镜像
en: Select Origin Image
- Parameters:
- targetImageName
- tags
Label:
default:
zh-cn: 镜像设置
en: Image Configure
- Parameters:
- zoneId
- instanceType
- whetherCreateVpc
- vpcCidrBlock
- vSwitchCidrBlock
- securityGroupId
- vSwitchId
- internetMaxBandwidthOut
- systemDiskCategory
- systemDiskSize
- ramRoleName
Label:
default:
zh-cn: 配置中转实例
en: ECS Instance Configure
- Parameters:
- updateType
- packageName
- packageVersion
- parameters
- commandType
- commandContent
- timeout
Label:
default:
zh-cn: 更新镜像配置
en: Update Image Configuration
- Parameters:
- OOSAssumeRole
Label:
default:
zh-cn: 高级选项
en: Control Options
Hidden:
- contentEncoding