-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS::ECS::SMCVerifyInstanceByRunCommand.json
506 lines (506 loc) · 14.3 KB
/
ACS::ECS::SMCVerifyInstanceByRunCommand.json
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
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"name-en": "ACS::ECS::SMCVerifyInstanceByRunCommand",
"name-zh-cn": "通过执行云助手命令验证实例",
"en": "Checking by customer command and default command for ecs instance",
"zh-cn": "在ECS实例上,检测客户命令和默认命令"
},
"Parameters": {
"regionId": {
"Type": "String",
"Description": {
"en": "The ID of region",
"zh-cn": "地域ID"
},
"AssociationProperty": "RegionId",
"Default": "{{ ACS::RegionId }}"
},
"instanceId": {
"Description": {
"en": "The ID of ECS instance",
"zh-cn": "ECS实例ID"
},
"Type": "String"
},
"isDeleteInstance": {
"Description": {
"en": "Whether delete ECS instance after check, (default is false)",
"zh-cn": "在检测完毕后,选择是否删除实例(默认为不删除)"
},
"Type": "Boolean",
"Default": false
},
"commandType": {
"Description": {
"en": "The type of command",
"zh-cn": "命令类型"
},
"Type": "String",
"AllowedValues": [
"RunBatScript",
"RunPowerShellScript",
"RunShellScript"
],
"Default": "RunShellScript"
},
"commandContent": {
"Description": {
"en": "The content of command",
"zh-cn": "命令内容"
},
"Type": "String",
"AssociationProperty": "Code",
"Default": ""
},
"timeout": {
"Description": {
"en": "Timeout for executing script",
"zh-cn": "执行脚本的超时时间"
},
"Type": "Number",
"Default": 60
},
"workingDir": {
"Description": {
"en": "The directory where the created command runs on the ECS instances",
"zh-cn": "在ECS实例上执行脚本的位置"
},
"Type": "String",
"Default": "/root"
}
},
"Tasks": [
{
"Name": "waitInstanceReady",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait the ECS instance status is running",
"zh-cn": "等待ECS实例至Running状态"
},
"Retries": 7,
"Delay": 15,
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ instanceId }}"
]
},
"DesiredValues": [
"Running"
],
"PropertySelector": "Instances.Instance[].Status"
},
"Outputs": {
"oSType": {
"Type": "String",
"ValueSelector": "Instances.Instance[].OSType"
},
"vpcId": {
"Type": "String",
"ValueSelector": "Instances.Instance[].VpcAttributes.VpcId"
},
"vSwitchId": {
"Type": "String",
"ValueSelector": "Instances.Instance[].VpcAttributes.VSwitchId"
},
"securityGroupIds": {
"Type": "List",
"ValueSelector": "Instances.Instance[].SecurityGroupIds.SecurityGroupId[]"
}
}
},
{
"Name": "installCloudAssistant",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Install cloud assistant with specified instance ID",
"zh-cn": "通过实例ID下载云助手客户端"
},
"Properties": {
"Service": "ECS",
"API": "InstallCloudAssistant",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ instanceId }}"
]
}
}
},
{
"Name": "rebootInstance",
"Action": "ACS::ECS::RebootInstance",
"Description": {
"en": "Restarts an ECS instance",
"zh-cn": "重启ECS实例"
},
"Properties": {
"regionId": "{{ regionId }}",
"instanceId": "{{ instanceId }}"
}
},
{
"Name": "waitCloudAssistantStatusReachtrue",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait for the cloud assistant status reach true",
"zh-cn": "等待云助手客户端安装完成"
},
"Retries": 7,
"Delay": 30,
"DelayType": "Constant",
"Properties": {
"Service": "ECS",
"API": "DescribeCloudAssistantStatus",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ instanceId }}"
]
},
"DesiredValues": [
"true"
],
"PropertySelector": "InstanceCloudAssistantStatusSet.InstanceCloudAssistantStatus[].CloudAssistantStatus"
}
},
{
"Name": "doInstanceDefaultCheck",
"Action": "ACS::ECS::RunCommand",
"Description": {
"en": "Execute cloud assistant command to check Instance",
"zh-cn": "执行云助手命令检测实例"
},
"OnError": "whetherExecuteCustomerCheck",
"Properties": {
"regionId": "{{ regionId }}",
"commandContent": {
"Fn::If": [
{
"Fn::Equals": [
"linux",
"{{ waitInstanceReady.oSType }}"
]
},
"#!/bin/bash\nfunction print_title() { echo -e \"\\n========================= $1:\\n\"; }\nprint_title \"ip addr\"\nip addr\nprint_title \"df -hPT\"\ndf -hPT\nprint_title \"cat /etc/fstab\"\ncat /etc/fstab\nprint_title \"Default Result\"\nif mount -a; then echo DISK_DEVICE_OK; fi\nif curl -s --connect-timeout 3 100.100.100.200 >/dev/null; then\n echo PRIVATE_NET_OK\n if curl -s --connect-timeout 3 www.aliyun.com >/dev/null; then echo PUBLIC_NET_OK; fi\nfi\n",
"function print_title($title) { echo \"========================= $title :\" }\nprint_title \"ipconfig\"\nipconfig\nprint_title \"list disk/volume\"\nget-wmiobject -class win32_logicaldisk\nprint_title \"Default Result\"\nif (get-wmiobject -class win32_logicaldisk) { echo DISK_DEVICE_OK }\nTry {\n if (Invoke-WebRequest -UseBasicParsing 100.100.100.200 -TimeoutSec 3) {\n echo PRIVATE_NET_OK\n if (Invoke-WebRequest -UseBasicParsing www.aliyun.com -TimeoutSec 3) { echo PUBLIC_NET_OK }\n }\n} Catch {}\n"
]
},
"instanceId": "{{ instanceId }}",
"commandType": {
"Fn::If": [
{
"Fn::Equals": [
"linux",
"{{ waitInstanceReady.oSType }}"
]
},
"RunShellScript",
"RunPowerShellScript"
]
},
"workingDir": "{{ workingDir }}",
"timeout": "180"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
},
{
"Name": "whetherExecuteCustomerCheck",
"Action": "ACS::Choice",
"Description": "Choose next task by IsDeleteInstance.",
"Properties": {
"DefaultTask": "doInstanceCustomerCheck",
"Choices": [
{
"When": {
"Fn::Equals": [
"",
"{{ commandContent }}"
]
},
"NextTask": "whetherDeleteInstanceIsTrue"
}
]
}
},
{
"Name": "doInstanceCustomerCheck",
"Description": {
"en": "Execute customer command to check Instance",
"zh-cn": "执行客户的云助手命令检测实例"
},
"Action": "ACS::ECS::RunCommand",
"OnError": "whetherDeleteInstanceIsTrue",
"Properties": {
"regionId": "{{ regionId }}",
"commandContent": "{{ commandContent }}",
"instanceId": "{{ instanceId }}",
"commandType": "{{ commandType }}",
"workingDir": "{{ workingDir }}",
"timeout": "{{ timeout }}"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
},
{
"Name": "whetherDeleteInstanceIsTrue",
"Action": "ACS::Choice",
"Description": {
"en": "Choose next task by IsDeleteInstance",
"zh-cn": "选择是否删除实例"
},
"Properties": {
"DefaultTask": "ACS::END",
"Choices": [
{
"When": {
"Fn::Equals": [
true,
"{{ isDeleteInstance }}"
]
},
"NextTask": "waitDataRecover"
}
]
}
},
{
"Name": "waitDataRecover",
"Action": "ACS::Sleep",
"Description": {
"en": "Wait the cloud assistanat status",
"zh-cn": "等待云助手客户端的状态"
},
"Properties": {
"Duration": "PT1M"
}
},
{
"Name": "deleteInstance",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Deletes ECS instance with the specified instance ID",
"zh-cn": "通过实例ID删除ECS实例"
},
"Properties": {
"Service": "ECS",
"API": "DeleteInstance",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceId": "{{ instanceId }}",
"Force": true
}
}
},
{
"Name": "waitInstanceDeleted",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait for the ECS instance deletion to complete",
"zh-cn": "等待ECS实例删除完成"
},
"Retries": 7,
"Delay": 15,
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ instanceId }}"
]
},
"DesiredValues": [
null
],
"PropertySelector": "Instances.Instance[]"
}
},
{
"Name": "waitSecurityGroupAvailable",
"Action": "ACS::Sleep",
"Description": {
"en": "Wait for the instance to remove the security group",
"zh-cn": "等待实例解除安全组"
},
"Properties": {
"Duration": "PT30S"
}
},
{
"Name": "deleteSecurityGroup",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Call DeleteSecurityGroup to delete a security group",
"zh-cn": "调用DeleteSecurityGroup删除一个安全组"
},
"OnError": "waitVSwitchAvailable",
"Properties": {
"Service": "ECS",
"API": "DeleteSecurityGroup",
"Parameters": {
"RegionId": "{{ regionId }}",
"SecurityGroupId": "{{ ACS::TaskLoopItem }}"
}
},
"Loop": {
"RateControl": {
"Mode": "Concurrency",
"MaxErrors": 10,
"Concurrency": 10
},
"Items": "{{ waitInstanceReady.securityGroupIds }}"
}
},
{
"Name": "waitVSwitchAvailable",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait for the VSwitches status utilAvailable",
"zh-cn": "等待交换机至可用状态"
},
"Retries": 7,
"Delay": 15,
"OnError": "deleteVSwitch",
"Properties": {
"Service": "VPC",
"API": "DescribeVSwitches",
"Parameters": {
"RegionId": "{{ regionId }}",
"VSwitchId": "{{ waitInstanceReady.vSwitchId }}"
},
"DesiredValues": [
"Available"
],
"PropertySelector": ".VSwitches.VSwitch[].Status"
}
},
{
"Name": "deleteVSwitch",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Call the DeleteVSwitch interface to delete the switch",
"zh-cn": "调用DeleteVSwitch接口删除交换机"
},
"OnError": "waitVSwitchDeleted",
"Properties": {
"Service": "VPC",
"API": "DeleteVSwitch",
"Parameters": {
"RegionId": "{{ regionId }}",
"VSwitchId": "{{ waitInstanceReady.vSwitchId }}"
}
}
},
{
"Name": "waitVSwitchDeleted",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait for the VSwitches deletion to complete",
"zh-cn": "等待交换机删除完成"
},
"Retries": 7,
"Delay": 15,
"OnError": "waitVpcUtilAvailable",
"Properties": {
"Service": "VPC",
"API": "DescribeVSwitches",
"Parameters": {
"RegionId": "{{ regionId }}",
"VSwitchId": "{{ waitInstanceReady.vSwitchId }}"
},
"DesiredValues": [
null
],
"PropertySelector": ".VSwitches.VSwitch[]"
}
},
{
"Name": "waitVpcUtilAvailable",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait for the VPC status util available",
"zh-cn": "等待专有网络至可用状态"
},
"Retries": 7,
"Delay": 15,
"OnError": "waitVpcCustomRouteUnbind",
"Properties": {
"Service": "VPC",
"API": "DescribeVpcs",
"Parameters": {
"RegionId": "{{ regionId }}",
"VpcId": "{{ waitInstanceReady.vpcId }}"
},
"DesiredValues": [
"Available"
],
"PropertySelector": "Vpcs.Vpc[].Status"
}
},
{
"Name": "waitVpcCustomRouteUnbind",
"Action": "ACS::Sleep",
"Description": {
"en": "Waiting for the VPC to unbind the route",
"zh-cn": "等待专有网络解绑路由"
},
"Properties": {
"Duration": "PT30S"
}
},
{
"Name": "deleteVpc",
"Action": "ACS::ExecuteAPI",
"Description": {
"en": "Call the DeleteVpc interface to delete a private network (VPC)",
"zh-cn": "调用DeleteVpc接口删除一个专有网络(VPC)"
},
"Properties": {
"Service": "VPC",
"API": "DeleteVpc",
"Parameters": {
"RegionId": "{{ regionId }}",
"VpcId": "{{ waitInstanceReady.vpcId }}"
}
}
}
],
"Outputs": {
"invocationOutput": {
"Type": "Json",
"Value": {
"Fn::If": [
{
"Fn::Equals": [
"",
"{{ commandContent }}"
]
},
{
"instanceId": "{{ instanceId }}",
"instanceDefaultCheck": "{{ doInstanceDefaultCheck.commandOutput }}"
},
{
"instanceId": "{{ instanceId }}",
"instanceDefaultCheck": "{{ doInstanceDefaultCheck.commandOutput }}",
"instanceCustomerCheck": "{{ doInstanceCustomerCheck.commandOutput }}"
}
]
}
}
}
}