-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS-SMC-CreateAndVerifyInstance.yml
754 lines (753 loc) · 23.8 KB
/
ACS-SMC-CreateAndVerifyInstance.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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
FormatVersion: OOS-2019-06-01
Description:
en: Create and verify instance by commands
zh-cn: SMC创建并通过执行命令验证目标实例
name-en: ACS-SMC-CreateAndVerifyInstance
name-zh-cn: SMC创建并验证目标实例
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: 地域ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
zoneId:
Label:
en: ZoneId
zh-cn: 可用区
Description:
en: The target zone id of VSwitch to create
zh-cn: 将创建交换机的目标可用区
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
Type: String
AssociationPropertyMetadata:
RegionId: regionId
hostName:
Label:
en: HostName
zh-cn: 将创建实例的主机名
Type: String
AllowedPattern: '^(?!\.|\-)(?!.*\.\.|.*\-\-)(?!.*_).*(?<!\.|\-)$'
MinLength: 2
imageId:
Label:
en: ImageId
zh-cn: 将创建实例的镜像ID
Type: String
AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
AssociationPropertyMetadata:
RegionId: regionId
instanceType:
Label:
en: InstanceType
zh-cn: 将创建实例的规格
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
privateIp:
Label:
en: PrivateIp
zh-cn: 将创建实例的内网IP
Type: String
systemDiskSize:
Label:
en: SystemDiskSize
zh-cn: 系统盘大小
Type: Number
Default: 19
MinValue: 19
MaxValue: 500
instancesCount:
Label:
en: InstancesCount
zh-cn: 将创建实例的数量
Type: Number
Default: 1
MinValue: 1
MaxValue: 999
isDeleteInstance:
Label:
en: IsDeleteInstance
zh-cn: 检查实例完成后是否删除实例
Type: Boolean
Default: true
commandType:
Label:
en: CommandType
zh-cn: 实例自定义检查云助手命令类型
Type: String
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
commandContent:
Label:
en: CommandContent
zh-cn: 实例自定义检查预云助手命令内容
Type: String
AssociationProperty: Code
Default: ''
timeout:
Label:
en: Timeout
zh-cn: 执行脚本的超时时间
Type: Number
Default: 600
workingDir:
Label:
en: WorkingDir
zh-cn: 在实例中运行命令的目录
Type: String
Default: /root
passwordInherit:
Description:
en: To use the PasswordInherit parameter, the Password parameter must be empty and you must make sure that the selected image has a password configured(default:false)
zh-cn: 使用该参数时,Password参数必须为空,同时您需要确保使用的镜像已经设置了密码,默认为false
Label:
en: IsUsePasswordInherit
zh-cn: 是否使用镜像预设的密码
Type: Boolean
Default: false
rateControl:
Label:
en: RateControl
zh-cn: 任务执行的并发比率
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: describeImages
Action: 'ACS::ExecuteAPI'
Description:
en: Query the image ostype by image id
zh-cn: 查询镜像的操作系统
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ imageId }}'
Outputs:
osType:
ValueSelector: 'Images.Image[0].OSType'
Type: String
- Name: converConstant
Action: 'ACS::ECS::SMCConversionConstantByJqScript'
Description:
en: Automatically convert to available CidrBlock according to PrivateIp
zh-cn: 根据PrivateIp自动转换成可用的CidrBlock
Properties:
parameter: '{{ privateIp }}'
jqScript:
- '.[0] | split(".") as $item | $item | if .[0]=="10" then "10.0.0.0/8" elif .[0]=="172" then "172.16.0.0/12" elif .[0]=="192" then "192.168.0.0/16" else "" end'
- '.[0] | split(".") as $item | $item | if .[0]=="10" then "10."+.[1]+".0.0/16" elif .[0]=="172" then "172."+.[1]+"."+.[2]+".0/24" elif .[0]=="192" then "192.168."+.[2]+".0/24" else "" end'
Outputs:
vswCidrBlock:
Type: String
ValueSelector: secondValue
vpcCidrBlock:
Type: String
ValueSelector: firstValue
- Name: createStack
Action: 'ACS::ExecuteAPI'
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: hostName
ParameterValue: '{{ hostName }}'
- ParameterKey: privateIp
ParameterValue: '{{ privateIp }}'
- ParameterKey: instanceType
ParameterValue: '{{ instanceType }}'
- ParameterKey: zoneId
ParameterValue: '{{ zoneId }}'
- ParameterKey: regionId
ParameterValue: '{{ regionId }}'
- ParameterKey: imageId
ParameterValue: '{{imageId}}'
- ParameterKey: executionId
ParameterValue: '{{ ACS::ExecutionId }}'
- ParameterKey: instancesCount
ParameterValue: '{{ instancesCount }}'
- ParameterKey: systemDiskSize
ParameterValue: '{{ systemDiskSize }}'
- ParameterKey: passwordInherit
ParameterValue: '{{ passwordInherit }}'
TemplateBody:
'Fn::If':
- 'Fn::Equals':
- windows
- '{{ describeImages.osType }}'
- |
{
"Description": "Create VPC ECS instance",
"Parameters": {
"imageId": {
"Type": "String"
},
"hostName": {
"Type": "String"
},
"privateIp": {
"Type": "String"
},
"instanceType": {
"Type": "String"
},
"executionId": {
"Type": "String"
},
"instancesCount": {
"Type": "String"
},
"zoneId": {
"Type": "String"
},
"regionId": {
"Type": "String"
},
"systemDiskSize": {
"Type": "Number"
},
"passwordInherit": {
"Type": "Boolean"
},
"resourcePrefix": {
"Type": "String",
"Default": "oos-generated"
}
},
"Conditions":{
"CreateSystemDiskSize":{
"Fn::Equals":[
19,
{
"Ref":"systemDiskSize"
}
]
}
},
"ROSTemplateFormatVersion": "2015-09-01",
"Outputs": {
"ecs_instance_id": {
"Value": {
"Fn::GetAtt": [
"ecs",
"InstanceIds"
]
}
}
},
"Resources": {
"vswitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "vpc"
},
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"ZoneId": {
"Ref": "zoneId"
},
"CidrBlock": "{{ converConstant.vswCidrBlock }}"
}
},
"sg": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
],
"VpcId": {
"Ref": "vpc"
},
"SecurityGroupName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"sg"
]
]
},
"SecurityGroupEgress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
],
"SecurityGroupIngress": [
{
"PortRange": "3389/3389",
"Priority": 1,
"IpProtocol": "tcp",
"SourceCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
]
}
},
"vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "{{ converConstant.vpcCidrBlock }}",
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"VpcName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"vpc"
]
]
}
}
},
"ecs": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"ImageId": {
"Ref": "imageId"
},
"HostName": {
"Ref": "hostName"
},
"PrivateIpAddress": {
"Ref": "privateIp"
},
"SecurityGroupId": {
"Ref": "sg"
},
"VpcId": {
"Ref": "vpc"
},
"VSwitchId": {
"Ref": "vswitch"
},
"InstanceType": {
"Ref": "instanceType"
},
"PasswordInherit": {
"Ref": "passwordInherit"
},
"SystemDiskSize": {
"Fn::If": [
"CreateSystemDiskSize",
{
"Ref": "ALIYUN::NoValue"
},
{
"Ref": "systemDiskSize"
}
]
},
"MinAmount": {
"Ref": "instancesCount"
},
"MaxAmount": {
"Ref": "instancesCount"
},
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"TemplateTags": [
"acs:integrate:oos:smc_create_and_verify_instance"
]
}
}
}
- |
{
"Description": "Create VPC ECS instance",
"Parameters": {
"imageId": {
"Type": "String"
},
"hostName": {
"Type": "String"
},
"privateIp": {
"Type": "String"
},
"instanceType": {
"Type": "String"
},
"passwordInherit": {
"Type": "Boolean"
},
"executionId": {
"Type": "String"
},
"instancesCount": {
"Type": "String"
},
"zoneId": {
"Type": "String"
},
"regionId": {
"Type": "String"
},
"systemDiskSize": {
"Type": "Number"
},
"resourcePrefix": {
"Type": "String",
"Default": "oos-generated"
}
},
"Conditions":{
"CreateSystemDiskSize":{
"Fn::Equals":[
19,
{
"Ref":"systemDiskSize"
}
]
}
},
"ROSTemplateFormatVersion": "2015-09-01",
"Outputs": {
"ecs_instance_id": {
"Value": {
"Fn::GetAtt": [
"ecs",
"InstanceIds"
]
}
}
},
"Resources": {
"vswitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "vpc"
},
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"ZoneId": {
"Ref": "zoneId"
},
"CidrBlock": "{{ converConstant.vswCidrBlock }}"
}
},
"sg": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
],
"VpcId": {
"Ref": "vpc"
},
"SecurityGroupName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"sg"
]
]
},
"SecurityGroupEgress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
],
"SecurityGroupIngress": [
{
"PortRange": "22/22",
"Priority": 1,
"IpProtocol": "tcp",
"SourceCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
]
}
},
"vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "{{ converConstant.vpcCidrBlock }}",
"Description": {
"Fn::Join": [
" ",
[
"OOS execution id is",
{
"Ref": "executionId"
}
]
]
},
"VpcName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"vpc"
]
]
}
}
},
"ecs": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"ImageId": {
"Ref": "imageId"
},
"HostName": {
"Ref": "hostName"
},
"PrivateIpAddress": {
"Ref": "privateIp"
},
"SecurityGroupId": {
"Ref": "sg"
},
"VpcId": {
"Ref": "vpc"
},
"VSwitchId": {
"Ref": "vswitch"
},
"InstanceType": {
"Ref": "instanceType"
},
"PasswordInherit": {
"Ref": "passwordInherit"
},
"SystemDiskSize": {
"Fn::If": [
"CreateSystemDiskSize",
{
"Ref": "ALIYUN::NoValue"
},
{
"Ref": "systemDiskSize"
}
]
},
"MinAmount": {
"Ref": "instancesCount"
},
"MaxAmount": {
"Ref": "instancesCount"
},
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"TemplateTags": [
"acs:integrate:oos:smc_create_and_verify_instance"
]
}
}
}
Outputs:
StackId:
Type: String
ValueSelector: StackId
- Name: untilStackReady
Action: 'ACS::WaitFor'
Description:
en: Wait for the stack status CREATE_COMPLETE
zh-cn: 等待资源栈至创建成功状态
OnSuccess: doInstanceCheck
OnError: queryStackStatusReason
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:
instanceIds:
Type: String
ValueSelector: 'Outputs[0].OutputValue'
- Name: doInstanceCheck
Action: 'ACS::ECS::SMCVerifyInstanceByRunCommand'
OnSuccess: 'ACS::END'
OnError: deleteStack
Description:
en: Execute cloud assistant command to check Instance
zh-cn: 执行云助手命令检查实例
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
isDeleteInstance: '{{ isDeleteInstance }}'
commandContent: '{{ commandContent }}'
commandType: '{{ commandType }}'
workingDir: '{{ workingDir }}'
timeout: '{{ timeout }}'
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ untilStackReady.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
- Name: queryStackStatusReason
Action: 'ACS::ExecuteAPI'
Description:
en: Query the reson of failed created stack
zh-cn: 查询资源栈未创建成功的原因
OnError: deleteStack
OnSuccess: deleteStack
Properties:
Service: ROS
API: GetStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{ createStack.StackId }}'
Outputs:
statusReason:
Type: String
ValueSelector: StatusReason
- Name: deleteStack
Description:
en: Delete the stack
zh-cn: 删除资源栈
OnSuccess: 'ACS::END'
Action: 'ACS::ExecuteApi'
Properties:
Service: ROS
API: DeleteStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{createStack.StackId}}'
Outputs:
instanceCheckResults:
Type: List
Value: '{{ doInstanceCheck.commandOutputs }}'