forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ecs-bind-multi-eip-address.yml
505 lines (505 loc) · 16.5 KB
/
ecs-bind-multi-eip-address.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
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
EcsCondition:
Type: String
Label:
zh-cn: 是否创建ECS/Eip/Eni
en: Create an ECS/Eip/Eni
AllowedValues:
- 使用已有ECS/Eip/Eni
- 创建ECS/Eip/Eni
Default: 使用已有ECS/Eip/Eni
EcsInstanceId:
Type: String
Default: Null
Label:
en: ECS Instance ID
zh-cn: ECS实例ID
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 创建ECS/Eip/Eni
ECSNetworkInterfaceId:
Type: String
Default: Null
Label:
en: ECS Network Interface ID
zh-cn: ECS弹性网卡ID
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 创建ECS/Eip/Eni
EipId1:
Type: String
Default: Null
Label:
en: Elastic IP Address1 Instance ID
zh-cn: 弹性公网IP1实例ID
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 创建ECS/Eip/Eni
EipId2:
Type: String
Default: Null
Label:
en: Elastic IP Address2 Instance ID
zh-cn: 弹性公网IP2实例ID
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 创建ECS/Eip/Eni
EipId3:
Type: String
Default: Null
Label:
en: Elastic IP Address3 Instance ID
zh-cn: 弹性公网IP3实例ID
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 创建ECS/Eip/Eni
SystemDiskCategory:
Default: Null
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
InstanceType: ${InstanceType}
ZoneId: ${ZoneId}
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 使用已有ECS/Eip/Eni
Type: String
Description:
zh-cn: '<font color=''blue''><b>可选值:</b></font><br>[cloud_efficiency: <font color=''green''>高效云盘</font>]<br>[cloud_ssd: <font color=''green''>SSD云盘</font>]<br>[cloud_essd: <font color=''green''>ESSD云盘</font>]<br>[cloud: <font color=''green''>普通云盘</font>]<br>[ephemeral_ssd: <font color=''green''>本地SSD盘</font>]'
en: '<font color=''blue''><b>Optional values:</b></font><br>[cloud_efficiency: <font color=''green''>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color=''green''>SSD Cloud Disk</font>]<br>[cloud_essd: <font color=''green''>ESSD Cloud Disk</font>]<br>[cloud: <font color=''green''>Cloud Disk</font>]<br>[ephemeral_ssd: <font color=''green''>Local SSD Cloud Disk</font>]'
Label:
zh-cn: 系统磁盘类型
en: System Disk Category
InstancePassword:
ConstraintDescription:
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三种;特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;' <>,.?/
en: 'Length 8-30, must contain upper case letters, lower case letters, Numbers, special symbols three; special characters include: ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
Description:
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三个;<br>特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
en: The 8-30 long login password of instance, consists of the uppercase, lowercase letter and number. <br> special characters include()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
MinLength: '8'
Label:
zh-cn: 实例密码
en: Instance Password
AllowedPattern: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
NoEcho: true
Default: Null
MaxLength: '30'
Type: String
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 使用已有ECS/Eip/Eni
InstanceType:
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 使用已有ECS/Eip/Eni
Type: String
Default: Null
Label:
zh-cn: 实例类型
en: Instance Type
ZoneId:
Default: Null
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
Type: String
Description:
zh-cn: 可用区ID。<br><b>注: <font color='blue'>选择可用区前请确认该可用区是否支持创建ECS资源的规格</font></b>
en: Availability Zone ID,<br><b>note: <font color='blue'>Before selecting, please confirm that the Availability Zone supports the specification of creating ECS resources</font></b>
Label:
zh-cn: 可用区ID
en: Available Zone ID
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 使用已有ECS/Eip/Eni
Resources:
DS_Instances:
Condition: HasEcs
Type: DATASOURCE::ECS::Instances
Properties:
InstanceIds:
- Ref: EcsInstanceId
DS_NetworkInterfaces:
Condition: HasEcs
Type: DATASOURCE::ECS::NetworkInterfaces
Properties:
NetworkInterfaceIds:
- Ref: ECSNetworkInterfaceId
DS_Eip1:
Condition: HasEcs
Type: DATASOURCE::EIP::Addresses
Properties:
AllocationId:
Ref: EipId1
DS_Eip2:
Condition: HasEcs
Type: DATASOURCE::EIP::Addresses
Properties:
AllocationId:
Ref: EipId2
DS_Eip3:
Condition: HasEcs
Type: DATASOURCE::EIP::Addresses
Properties:
AllocationId:
Ref: EipId3
AssignPrivateIpAddresses:
Type: ALIYUN::ECS::AssignPrivateIpAddresses
Properties:
NetworkInterfaceId:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- EcsENI
- NetworkInterfaceId
- Ref: ECSNetworkInterfaceId
SecondaryPrivateIpAddressCount: 2
EipAssociationPrimaryPrivateIp:
DependsOn:
- AssignPrivateIpAddresses
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- EcsENI
- NetworkInterfaceId
- Ref: ECSNetworkInterfaceId
AllocationId:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- Eip1
- AllocationId
- Ref: EipId1
PrivateIpAddress:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- EcsENI
- PrivateIpAddress
- Fn::Jq:
- First
- .[0].PrivateIpAddress
- Fn::GetAtt:
- DS_NetworkInterfaces
- NetworkInterfaces
Mode: NAT
EipAssociationSecondaryPrivateIp1:
Type: ALIYUN::VPC::EIPAssociation
DependsOn:
- EipAssociationPrimaryPrivateIp
Properties:
InstanceId:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- EcsENI
- NetworkInterfaceId
- Ref: ECSNetworkInterfaceId
AllocationId:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- Eip2
- AllocationId
- Ref: EipId2
PrivateIpAddress:
Fn::Select:
- '0'
- Fn::GetAtt:
- AssignPrivateIpAddresses
- PrivateIpAddresses
Mode: NAT
EipAssociationSecondaryPrivateIp2:
DependsOn:
- EipAssociationSecondaryPrivateIp1
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- EcsENI
- NetworkInterfaceId
- Ref: ECSNetworkInterfaceId
AllocationId:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- Eip3
- AllocationId
- Ref: EipId3
PrivateIpAddress:
Fn::Select:
- '1'
- Fn::GetAtt:
- AssignPrivateIpAddresses
- PrivateIpAddresses
Mode: NAT
EcsEniAttachment:
DependsOn:
- EipAssociationPrimaryPrivateIp
- EipAssociationSecondaryPrivateIp1
- EipAssociationSecondaryPrivateIp2
Type: ALIYUN::ECS::NetworkInterfaceAttachment
Properties:
InstanceId:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- EcsInstance
- InstanceId
- Ref: EcsInstanceId
NetworkInterfaceId:
Fn::If:
- CreateEcs
- Fn::GetAtt:
- EcsENI
- NetworkInterfaceId
- Ref: ECSNetworkInterfaceId
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: { }
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Handle:
Ref: WaitConditionHandle
Timeout: 3720
Count: 1
SecurityGroupIngress_22:
Condition: HasEcs
Type: ALIYUN::ECS::SecurityGroupIngress
DependsOn:
- EcsEniAttachment
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 22/22
InitEcsEni:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
- Fn::If:
- CreateEcs
- Fn::GetAtt:
- EcsInstance
- InstanceId
- Ref: EcsInstanceId
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub:
- |
#!/bin/bash
if [ ! -f .ros.provision ]; then
echo "Name: 普通模式下实现ECS绑定多EIP(CentOS 7)" > .ros.provision
fi
name=$(grep "^Name:" .ros.provision | awk -F':' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [[ "$name" != "普通模式下实现ECS绑定多EIP(CentOS 7)" ]]; then
echo "当前实例已使用过\"$name\"教程的一键配置,不能再使用本教程的一键配置"
${WaitConditionHandle.CurlCli} --data-binary "{\"status\": \"FAILURE\", \"reason\": \"The current instance has already applied the configuration of the \\\"$name\\\" tutorial, and the configuration of this tutorial can no longer be applied.\"}"
exit 0
fi
secondary_eni=`ip address show | grep eth | grep DOWN | awk -F: '{print $2}'`
secondary_eni_name=`eval echo "$secondary_eni"`
if [[ "$secondary_eni_name" != "" ]]; then
echo "#########################"
echo "# The secondary Eni is not fully configured"
echo "#########################"
secondary_eni_mac=`cat /sys/class/net/"$secondary_eni_name"/address`
echo "DEVICE=$secondary_eni_name" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
echo "BOOTPROTO=dhcp" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
echo "USERCTL=yes" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
echo "PEERDNS=no" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
echo "IPV6INIT=no" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
echo "PERSISTENT_DHCLIENT=yes" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
echo "HWADDR=$secondary_eni_mac" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
echo "DEFROUTE=no" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name"
systemctl restart network
else
echo "#########################"
echo "# Secondary Eni has been configured"
echo "#########################"
fi
netmask_address=`ifconfig "$secondary_eni_name"| grep netmask | awk '{print $4}'`
echo "DEVICE=$secondary_eni_name:0" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":0
echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":0
echo "BOOTPROTO=static" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":0
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":0
echo "IPADDR=${PrivateIpAddresses1}" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":0
echo "NETMASK=$netmask_address" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":0
echo "DEVICE=$secondary_eni_name:1" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":1
echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":1
echo "BOOTPROTO=static" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":1
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":1
echo "IPADDR=${PrivateIpAddresses2}" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":1
echo "NETMASK=$netmask_address" >> /etc/sysconfig/network-scripts/ifcfg-"$secondary_eni_name":1
systemctl restart network
echo "# Secondary Eni PrivateIpAddresses has been configured"
${WaitConditionHandle.CurlCli} --data-binary '{"status": "SUCCESS"}'
- PrivateIpAddresses1:
Fn::Select:
- '0'
- Fn::GetAtt:
- AssignPrivateIpAddresses
- PrivateIpAddresses
PrivateIpAddresses2:
Fn::Select:
- '1'
- Fn::GetAtt:
- AssignPrivateIpAddresses
- PrivateIpAddresses
DependsOn:
- EcsEniAttachment
EcsVpc:
Condition: CreateEcs
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 192.168.0.0/16
EcsVSwitch:
Type: ALIYUN::ECS::VSwitch
Condition: CreateEcs
Properties:
VpcId:
Ref: EcsVpc
CidrBlock: 192.168.1.0/24
ZoneId:
Ref: ZoneId
EcsSecurityGroup:
Condition: CreateEcs
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupIngress:
- Priority: 1
PortRange: 22/22
NicType: internet
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
VpcId:
Ref: EcsVpc
EcsInstance:
Condition: CreateEcs
Type: ALIYUN::ECS::Instance
Properties:
SystemDiskCategory:
Ref: SystemDiskCategory
VpcId:
Fn::GetAtt:
- EcsVpc
- VpcId
AllocatePublicIP: false
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7
VSwitchId:
Ref: EcsVSwitch
Password:
Ref: InstancePassword
InstanceType:
Ref: InstanceType
EcsENI:
Condition: CreateEcs
Type: ALIYUN::ECS::NetworkInterface
Properties:
VSwitchId:
Ref: EcsVSwitch
SecurityGroupId:
Ref: EcsSecurityGroup
Eip1:
Condition: CreateEcs
Type: ALIYUN::VPC::EIP
Properties:
InstanceChargeType: Postpaid
InternetChargeType: PayByTraffic
Eip2:
Condition: CreateEcs
Type: ALIYUN::VPC::EIP
Properties:
InstanceChargeType: Postpaid
InternetChargeType: PayByTraffic
Eip3:
Condition: CreateEcs
Type: ALIYUN::VPC::EIP
Properties:
InstanceChargeType: Postpaid
InternetChargeType: PayByTraffic
Outputs: { }
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- EcsCondition
- EcsInstanceId
- ZoneId
- InstanceType
- SystemDiskCategory
- InstancePassword
- ECSNetworkInterfaceId
- EipId1
- EipId2
- EipId3
TemplateTags:
- acs:document-help:eip:普通模式下实现ECS绑定多EIP
Conditions:
CreateEcs:
Fn::Equals:
- 创建ECS/Eip/Eni
- Ref: EcsCondition
HasEcs:
Fn::Equals:
- 使用已有ECS/Eip/Eni
- Ref: EcsCondition
Description:
zh-cn: 将弹性公网IP与辅助弹性网卡以普通模式绑定,实现单个ECS实例(CentOS 7)绑定多个EIP。
en: Bind an EIP to a secondary ENI in normal mode to bind multiple EIPs to a single ECS instance (CentOS 7).