forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecs-json-data-transmission.yml
556 lines (523 loc) · 13.2 KB
/
ecs-json-data-transmission.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建ECS实例对,配置SSH密钥自动分发与回传,实现VPC内实例间安全通信与数据交换。
en: Create ECS instance pairs, configure automatic distribution and return of SSH
keys, enabling secure communication and data exchange between instances within
a VPC.
Mappings:
VpcCidrs:
pubsubnet:
cidr: 192.168.1.0/24
vpc:
cidr: 192.168.0.0/16
Parameters:
ZoneId:
Type: String
Label:
en: Zone ID
zh-cn: 可用区ID
Description:
en: The available zone ID, you should confirm the zone support ECS、VPC、VSwitch
or not.
zh-cn: 可用区ID,需确认所选可用区下是否支持ECS、VPC、VSwitch等资源。
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
InstanceType:
Type: String
Label:
en: ECS Instance Type
zh-cn: ECS实例类型
Description:
en: 'The ECS instance type, <a href=''https://www.alibabacloud.com/help/en/doc-detail/25378.html''
target=''_blank''>View instance types</a>, please confirm the instance type
if in the specific zone in ECS console. '
zh-cn: ECS实例规格,详情请参见<a href='https://help.aliyun.com/document_detail/25378.html'
target='_blank'>实例规格族</a>,请在ECS控制台确认所选可用区下是否有您选的规格。
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ZoneId
ImageId:
Type: String
Label:
en: ECS Image ID
zh-cn: 镜像ID
Description:
en: Image ID, represents the image resource to startup one ECS instance, <a
href='https://www.alibabacloud.com/help/en/doc-detail/112977.html' target='_blank'>View
image resources</a>.
zh-cn: 镜像ID,详情请参考<a href='https://help.aliyun.com/document_detail/112977.html'
target='_blank'>公共镜像</a>。
AssociationProperty: ALIYUN::ECS::Image::ImageId
AssociationPropertyMetadata:
InstanceType: ${InstanceType}
SupportedImageOwnerAlias:
- system
- self
- others
Default: centos_7_04_64_20G_alibase_201701015.vhd
SystemDiskCategory:
Type: String
Label:
en: ECS System Disk Category
zh-cn: ECS系统盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
LocaleKey: DiskCategory
InstanceType: ${InstanceType}
InternetChargeType:
Type: String
Label:
en: Internet Charge Type
zh-cn: 网络类型
Description:
en: The charge type of public internet.Support 'PayByBandwidth' and 'PayByTraffic'
only.
zh-cn: 访问公网计费方式,可用值:PayByBandwidth(按固定带宽计费)、PayByTraffic(按流量计费)。
AssociationPropertyMetadata:
LocaleKey: InternetChargeType
Default: PayByTraffic
AllowedValues:
- PayByBandwidth
- PayByTraffic
Bandwidth:
Type: Number
Label:
en: EIP Bandwidth
zh-cn: EIP带宽峰值
Description:
en: Specify the peak bandwidth of public internet type instance, if PayByBandwidth
is selected. The unit is 5Mbps.
zh-cn: 公网带宽峰值,1~1000Mbps
Default: 1
MinValue: 1
MaxValue: 1000
InstancePassword:
Type: String
Label:
en: ECS Instance Password
zh-cn: 实例密码
Description:
en: The 8-30 long login password of instance, consists of the uppercase, lowercase
letter and number. <br> special characters include()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三个;<br>特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
ConstraintDescription:
en: 'Length 8-30, must contain upper case letters, lower case letters, Numbers,
special symbols three; special characters include: ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三种;特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;' <>,.?/
AllowedPattern: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: 8
MaxLength: 30
NoEcho: true
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Fn::FindInMap:
- VpcCidrs
- vpc
- cidr
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
Description: Wide open
SecurityGroupEgress:
- DestCidrIp: 0.0.0.0/0
IpProtocol: all
NicType: intranet
PortRange: -1/-1
Priority: 1
SecurityGroupIngress:
- IpProtocol: all
NicType: intranet
PortRange: -1/-1
Priority: 1
SourceCidrIp: 0.0.0.0/0
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
CidrBlock:
Fn::FindInMap:
- VpcCidrs
- pubsubnet
- cidr
ECSFirst:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Fn::GetAtt:
- SecurityGroup
- SecurityGroupId
ImageId:
Ref: ImageId
AllocatePublicIP: 'false'
InstanceType:
Ref: InstanceType
IoOptimized: optimized
Password:
Ref: InstancePassword
SystemDiskCategory:
Ref: SystemDiskCategory
UserData:
Fn::Replace:
- ros-notify:
Fn::GetAtt:
- ECSFirstConditionHandle
- CurlCli
- Fn::Join:
- ''
- - '#!/bin/sh
'
- 'apt-get update
'
- 'apt-get install -y curl
'
- 'apt-get install -y jq
'
- 'apt-get install -y expect
'
- 'echo ''#!/usr/bin/expect'' > /tmp/ssh_gen_key
'
- 'echo spawn ssh-keygen -t rsa >> /tmp/ssh_gen_key
'
- 'echo ''expect {'' >> /tmp/ssh_gen_key
'
- 'echo '' "*(/root/.ssh/id_rsa)" {send "\\n\\r";exp_continue}''
>> /tmp/ssh_gen_key
'
- 'echo '' "*(empty for no passphrase)" {send "\\n\\r";exp_continue}''
>> /tmp/ssh_gen_key
'
- 'echo '' "*again" {send "\\n\\r"}'' >> /tmp/ssh_gen_key
'
- 'echo ''}'' >> /tmp/ssh_gen_key
'
- 'echo ''expect eof'' >> /tmp/ssh_gen_key
'
- '
'
- '/usr/bin/expect /tmp/ssh_gen_key
'
- 'pub_key=`cat /root/.ssh/id_rsa.pub`
'
- 'cmd="ros-notify -d ''{\"id\" : \"ssh_pub_key\", \"data\" : \"$pub_key\"}''"
'
- 'eval $cmd
'
ECSFirstConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
ECSFirstWaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: ECSFirstConditionHandle
Timeout: 300
DependsOn: ECSFirst
ECSSecond:
Type: ALIYUN::ECS::InstanceGroup
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Fn::GetAtt:
- SecurityGroup
- SecurityGroupId
ImageId:
Ref: ImageId
InstanceType:
Ref: InstanceType
IoOptimized: optimized
MaxAmount: '1'
Password:
Ref: InstancePassword
SystemDiskCategory:
Ref: SystemDiskCategory
UserData:
Fn::Replace:
- ros-notify:
Fn::GetAtt:
- ECSSecondConditionHandle
- CurlCli
- Fn::Join:
- ''
- - '#!/bin/sh
'
- ssh_pub_key_json='
- Fn::GetAtt:
- ECSFirstWaitCondition
- Data
- '''
'
- 'echo $ssh_pub_key_json > /tmp/pubkey
'
- 'apt-get update
'
- 'apt-get install -y curl
'
- 'apt-get install -y jq
'
- 'apt-get install -y expect
'
- 'pub_key=`echo "$ssh_pub_key_json" | jq ''.ssh_pub_key'' | xargs echo
`
'
- 'echo "$pub_key" > /root/.ssh/authorized_keys
'
- 'chmod 600 /root/.ssh/authorized_keys
'
- 'sudo service ssh restart
'
- 'cmd="ros-notify -d ''{\"data\" : \"$pub_key\"}''"
'
- 'eval $cmd
'
- 'echo $pub_key > /tmp/real_pub_key
'
DependsOn: ECSFirst
ECSSecondConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
ECSSecondWaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: ECSSecondConditionHandle
Timeout: 600
DependsOn: ECSSecond
ElasticIp:
Type: ALIYUN::VPC::EIP
Properties:
Bandwidth:
Ref: Bandwidth
InternetChargeType:
Ref: InternetChargeType
ElasticIpAssociation:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Fn::GetAtt:
- ECSFirst
- InstanceId
AllocationId:
Fn::GetAtt:
- ElasticIp
- AllocationId
Outputs:
ECSFirst:
Description: Private IP address of created ecs instance. Only for VPC instance.
Value:
Fn::GetAtt:
- ECSFirst
- PrivateIp
ECSSecondIps:
Description: Private IP address list of created ecs instance. Only for VPC instance.
Value:
Fn::GetAtt:
- ECSSecond
- PrivateIps
EipAddress:
Description: IP address of created EIP.
Value:
Fn::GetAtt:
- ElasticIp
- EipAddress
PubKey:
Description: Received the data sent by the second ecs, JSON serialized dict containing
data associated with wait condition signals sent to the handle.
Value:
Fn::GetAtt:
- ECSSecondWaitCondition
- Data
SSHPubKey:
Description: Received the data sent by the first ecs, JSON serialized dict containing
data associated with wait condition signals sent to the handle.
Value:
Fn::GetAtt:
- ECSFirstWaitCondition
- Data
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- ZoneId
- InstanceType
- ImageId
- SystemDiskCategory
- InternetChargeType
- Bandwidth
- InstancePassword
Label:
default:
en: ECS Configuration
zh-cn: ECS 配置(必填)
TemplateTags:
- acs:example:弹性计算:在ECS之间实现复杂数据传递(Json)
ALIYUN::ROS::Composer:
d2668a7d:
Rect:
- 654
- 540
- 40
- 30
- 1
- 0
ResT: Composer::ROSParameter::AlibabaCloud
2d726d25:
Parent: d2668a7d
Rect:
- 618
- 480
- 60
- 70
- 2
- 0
ResT: Composer::ROSParameter::Region
acabe0d0:
Res:
- Vpc
Parent: 2d726d25
Rect:
- 440
- 270
- 80
- 200
- 3
- 0
7f06ce40:
Res:
- ECSFirstWaitCondition
Parent: 2d726d25
Rect:
- 40
- 40
- 540
- 200
- 3
- 0
b4a1b69e:
Res:
- ECSSecondConditionHandle
Parent: 2d726d25
Rect:
- 40
- 40
- 622
- 410
- 3
- 0
7081385a:
Res:
- ECSSecondWaitCondition
Parent: 2d726d25
Rect:
- 40
- 40
- 622
- 200
- 3
- 0
72e5b3aa:
Res:
- ElasticIp
- ElasticIpAssociation
Parent: 2d726d25
Rect:
- 40
- 40
- 237
- 114
- 3
- 0
dcb968b6:
Res:
- ECSFirstConditionHandle
Parent: 2d726d25
Rect:
- 40
- 40
- 540
- 410
- 3
- 0
00e1eada:
Res:
- VSwitch
Parent: acabe0d0
Rect:
- 400
- 200
- 100
- 250
- 4
- 0
b99fff1b:
Parent: 2d726d25
Edge:
- 7f06ce40
- dcb968b6
Line: 0:0:0:gray:0
995120c2:
Parent: 2d726d25
Edge:
- 7081385a
- b4a1b69e
Line: 0:0:0:gray:0
e5995883:
Parent: 2d726d25
Edge:
- 72e5b3aa
- 3df037f3
Line: 0:0:0:gray:0
409b6bf1:
Res:
- SecurityGroup
Parent: acabe0d0
Rect:
- 237
- 116
- 192
- 302
- 12
- 0
450671c3:
Res:
- ECSSecond
Parent: 00e1eada
Rect:
- 40
- 40
- 353
- 340
- 13
- 0
Layer:
- 409b6bf1
3df037f3:
Res:
- ECSFirst
Parent: 00e1eada
Rect:
- 40
- 40
- 237
- 340
- 13
- 0
Layer:
- 409b6bf1