1+ #! /bin/bash
2+ set -xe
3+
4+ cd /etc/chef
5+ cat << 'EOF ' > support_secondary_network_interface_patch
6+ Subject: [PATCH] Configure proper priority for route tables
7+ Raise priority of ParallelCluster configured route tables (#2857)
8+ Support attaching multiple network interfaces to the same network card
9+ ---
10+ Index: cookbooks/aws-parallelcluster-environment/files/amazon-2023/network_interfaces/configure_nw_interface.sh
11+ <+>UTF-8
12+ ===================================================================
13+ diff --git a/cookbooks/aws-parallelcluster-environment/files/amazon-2023/network_interfaces/configure_nw_interface.sh b/cookbooks/aws-parallelcluster-environment/files/amazon-2023/network_interfaces/configure_nw_interface.sh
14+ --- a/cookbooks/aws-parallelcluster-environment/files/amazon-2023/network_interfaces/configure_nw_interface.sh (revision 9fe7e20db84ca556bcb830210c1f9ea852a38a89)
15+ +++ b/cookbooks/aws-parallelcluster-environment/files/amazon-2023/network_interfaces/configure_nw_interface.sh (revision e3949f39db1248a6a373283dc6132ac2edff1ff9)
16+ @@ -4,7 +4,8 @@
17+
18+ if
19+ [ -z "${DEVICE_NAME}" ] || # name of the device
20+ - [ -z "${DEVICE_NUMBER}" ] || # number of the device
21+ + [ -z "${DEVICE_NUMBER}" ] || # index of the device
22+ + [ -z "${NETWORK_CARD_INDEX}" ] || # index of the network card
23+ [ -z "${DEVICE_IP_ADDRESS}" ] || # ip of the device
24+ [ -z "${MAC}" ] || # mac address of the device
25+ [ -z "${CIDR_BLOCK}" ] # CIDR block of the subnet
26+ @@ -12,7 +13,7 @@
27+ echo 'One or more environment variables missing'
28+ exit 1
29+ fi
30+ -echo "Configuring NIC, Device name: ${DEVICE_NAME}, Device number: ${DEVICE_NUMBER}"
31+ +echo "Configuring NIC, Device name: ${DEVICE_NAME}, Device number: ${DEVICE_NUMBER}, Network card index:${NETWORK_CARD_INDEX}"
32+
33+ configuration_directory="/etc/systemd/network"
34+ file_name="70-${DEVICE_NAME}.network"
35+ @@ -23,12 +24,13 @@
36+
37+ cd "$configuration_directory"
38+
39+ -ROUTE_TABLE=100${DEVICE_NUMBER}
40+ +SUFFIX=$NETWORK_CARD_INDEX$(printf "%02d" $DEVICE_NUMBER)
41+ +ROUTE_TABLE="$(( $SUFFIX + 1000 ))"
42+
43+ ln -s /usr/lib/systemd/network/80-ec2.network ${file_name} # Use default EC2 configuration. This include MTU, etc.
44+
45+ /bin/cat <<EOF > ${sub_directory}/eni.conf
46+ -# Configuration for ${DEVICE_NUMBER} generated by ParallelCluster
47+ +# Configuration for network card: ${NETWORK_CARD_INDEX}, device number: ${DEVICE_NUMBER} generated by ParallelCluster
48+ # This is inspired by https://github.com/amazonlinux/amazon-ec2-net-utils/blob/v2.4.1/lib/lib.sh
49+ [Match]
50+ MACAddress=${MAC}
51+ Index: cookbooks/aws-parallelcluster-environment/files/default/network_interfaces/configure_nw_interface.sh
52+ IDEA additional info:
53+ Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
54+ <+>UTF-8
55+ ===================================================================
56+ diff --git a/cookbooks/aws-parallelcluster-environment/files/default/network_interfaces/configure_nw_interface.sh b/cookbooks/aws-parallelcluster-environment/files/default/network_interfaces/configure_nw_interface.sh
57+ --- a/cookbooks/aws-parallelcluster-environment/files/default/network_interfaces/configure_nw_interface.sh (revision 9fe7e20db84ca556bcb830210c1f9ea852a38a89)
58+ +++ b/cookbooks/aws-parallelcluster-environment/files/default/network_interfaces/configure_nw_interface.sh (revision e3949f39db1248a6a373283dc6132ac2edff1ff9)
59+ @@ -10,7 +10,8 @@
60+
61+ if
62+ [ -z "${DEVICE_NAME}" ] || # name of the device
63+ - [ -z "${DEVICE_NUMBER}" ] || # number of the device
64+ + [ -z "${DEVICE_NUMBER}" ] || # index of the device
65+ + [ -z "${NETWORK_CARD_INDEX}" ] || # index of the network card
66+ [ -z "${GW_IP_ADDRESS}" ] || # gateway ip address
67+ [ -z "${DEVICE_IP_ADDRESS}" ] || # ip address to assign to the interface
68+ [ -z "${CIDR_PREFIX_LENGTH}" ] || # the prefix length of the device IP cidr block
69+ @@ -20,9 +21,11 @@
70+ exit 1
71+ fi
72+
73+ -ROUTE_TABLE="100${DEVICE_NUMBER}"
74+ +SUFFIX=$NETWORK_CARD_INDEX$(printf "%02d" $DEVICE_NUMBER)
75+
76+ -echo "Configuring ${DEVICE_NAME} with IP:${DEVICE_IP_ADDRESS} CIDR_PREFIX:${CIDR_PREFIX_LENGTH} NETMASK:${NETMASK} GW:${GW_IP_ADDRESS} ROUTING_TABLE:${ROUTE_TABLE}"
77+ +ROUTE_TABLE="$(( $SUFFIX + 1000 ))"
78+ +
79+ +echo "Configuring device name: ${DEVICE_NAME} with IP:${DEVICE_IP_ADDRESS} CIDR_PREFIX:${CIDR_PREFIX_LENGTH} NETMASK:${NETMASK} GW:${GW_IP_ADDRESS} ROUTING_TABLE:${ROUTE_TABLE}"
80+
81+ # config file
82+ FILE="/etc/sysconfig/network-scripts/ifcfg-${DEVICE_NAME}"
83+ Index: cookbooks/aws-parallelcluster-environment/files/redhat-8.network_interfaces/configure_nw_interface.sh
84+ IDEA additional info:
85+ Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
86+ <+>UTF-8
87+ ===================================================================
88+ diff --git a/cookbooks/aws-parallelcluster-environment/files/redhat-8.network_interfaces/configure_nw_interface.sh b/cookbooks/aws-parallelcluster-environment/files/redhat-8.network_interfaces/configure_nw_interface.sh
89+ --- a/cookbooks/aws-parallelcluster-environment/files/redhat-8.network_interfaces/configure_nw_interface.sh (revision 9fe7e20db84ca556bcb830210c1f9ea852a38a89)
90+ +++ b/cookbooks/aws-parallelcluster-environment/files/redhat-8.network_interfaces/configure_nw_interface.sh (revision e3949f39db1248a6a373283dc6132ac2edff1ff9)
91+ @@ -13,7 +13,8 @@
92+
93+ if
94+ [ -z "${DEVICE_NAME}" ] || # name of the device
95+ - [ -z "${DEVICE_NUMBER}" ] || # number of the device
96+ + [ -z "${DEVICE_NUMBER}" ] || # index of the device
97+ + [ -z "${NETWORK_CARD_INDEX}" ] || # index of the network card
98+ [ -z "${GW_IP_ADDRESS}" ] || # gateway ip address
99+ [ -z "${DEVICE_IP_ADDRESS}" ] || # ip address to assign to the interface
100+ [ -z "${CIDR_PREFIX_LENGTH}" ] # the prefix length of the device IP cidr block
101+ @@ -23,9 +24,10 @@
102+ fi
103+
104+ con_name="System ${DEVICE_NAME}"
105+ -route_table="100${DEVICE_NUMBER}"
106+ -priority="100${DEVICE_NUMBER}"
107+ -metric="100${DEVICE_NUMBER}"
108+ +SUFFIX=$NETWORK_CARD_INDEX$(printf "%02d" $DEVICE_NUMBER)
109+ +route_table="$(( $SUFFIX + 1000 ))"
110+ +priority="${route_table}"
111+ +metric="${route_table}"
112+
113+ # Rename connection
114+ original_con_name=`nmcli -t -f GENERAL.CONNECTION device show ${DEVICE_NAME} | cut -f2 -d':'`
115+ Index: cookbooks/aws-parallelcluster-environment/files/rocky/network_interfaces/configure_nw_interface.sh
116+ IDEA additional info:
117+ Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
118+ <+>UTF-8
119+ ===================================================================
120+ diff --git a/cookbooks/aws-parallelcluster-environment/files/rocky/network_interfaces/configure_nw_interface.sh b/cookbooks/aws-parallelcluster-environment/files/rocky/network_interfaces/configure_nw_interface.sh
121+ --- a/cookbooks/aws-parallelcluster-environment/files/rocky/network_interfaces/configure_nw_interface.sh (revision 9fe7e20db84ca556bcb830210c1f9ea852a38a89)
122+ +++ b/cookbooks/aws-parallelcluster-environment/files/rocky/network_interfaces/configure_nw_interface.sh (revision e3949f39db1248a6a373283dc6132ac2edff1ff9)
123+ @@ -13,7 +13,8 @@
124+
125+ if
126+ [ -z "${DEVICE_NAME}" ] || # name of the device
127+ - [ -z "${DEVICE_NUMBER}" ] || # number of the device
128+ + [ -z "${DEVICE_NUMBER}" ] || # index of the device
129+ + [ -z "${NETWORK_CARD_INDEX}" ] || # index of the network card
130+ [ -z "${GW_IP_ADDRESS}" ] || # gateway ip address
131+ [ -z "${DEVICE_IP_ADDRESS}" ] || # ip address to assign to the interface
132+ [ -z "${CIDR_PREFIX_LENGTH}" ] # the prefix length of the device IP cidr block
133+ @@ -23,9 +24,10 @@
134+ fi
135+
136+ con_name="System ${DEVICE_NAME}"
137+ -route_table="100${DEVICE_NUMBER}"
138+ -priority="100${DEVICE_NUMBER}"
139+ -metric="100${DEVICE_NUMBER}"
140+ +SUFFIX=$NETWORK_CARD_INDEX$(printf "%02d" $DEVICE_NUMBER)
141+ +route_table="$(( $SUFFIX + 1000 ))"
142+ +priority="${route_table}"
143+ +metric="${route_table}"
144+
145+ # Rename connection
146+ original_con_name=`nmcli -t -f GENERAL.CONNECTION device show ${DEVICE_NAME} | cut -f2 -d':'`
147+ Index: cookbooks/aws-parallelcluster-environment/files/ubuntu/network_interfaces/configure_nw_interface.sh
148+ IDEA additional info:
149+ Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
150+ <+>UTF-8
151+ ===================================================================
152+ diff --git a/cookbooks/aws-parallelcluster-environment/files/ubuntu/network_interfaces/configure_nw_interface.sh b/cookbooks/aws-parallelcluster-environment/files/ubuntu/network_interfaces/configure_nw_interface.sh
153+ --- a/cookbooks/aws-parallelcluster-environment/files/ubuntu/network_interfaces/configure_nw_interface.sh (revision 9fe7e20db84ca556bcb830210c1f9ea852a38a89)
154+ +++ b/cookbooks/aws-parallelcluster-environment/files/ubuntu/network_interfaces/configure_nw_interface.sh (revision e3949f39db1248a6a373283dc6132ac2edff1ff9)
155+ @@ -10,7 +10,8 @@
156+
157+ if
158+ [ -z "${DEVICE_NAME}" ] || # name of the device
159+ - [ -z "${DEVICE_NUMBER}" ] || # number of the device
160+ + [ -z "${DEVICE_NUMBER}" ] || # index of the device
161+ + [ -z "${NETWORK_CARD_INDEX}" ] || # index of the network card
162+ [ -z "${GW_IP_ADDRESS}" ] || # gateway ip address
163+ [ -z "${DEVICE_IP_ADDRESS}" ] || # ip address to assign to the interface
164+ [ -z "${CIDR_PREFIX_LENGTH}" ] || # the prefix length of the device IP cidr block
165+ @@ -40,7 +41,8 @@
166+ fi
167+
168+ FILE="/etc/netplan/${DEVICE_NAME}.yaml"
169+ -ROUTE_TABLE="100${DEVICE_NUMBER}"
170+ +SUFFIX=$NETWORK_CARD_INDEX$(printf "%02d" $DEVICE_NUMBER)
171+ +ROUTE_TABLE="$(( $SUFFIX + 1000 ))"
172+
173+ echo "Configuring ${DEVICE_NAME} with IP:${DEVICE_IP_ADDRESS} CIDR_PREFIX:${CIDR_PREFIX_LENGTH} NETMASK:${NETMASK} GW:${GW_IP_ADDRESS} ROUTING_TABLE:${ROUTE_TABLE}"
174+
175+ Index: cookbooks/aws-parallelcluster-environment/recipes/config/network_interfaces.rb
176+ IDEA additional info:
177+ Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
178+ <+>UTF-8
179+ ===================================================================
180+ diff --git a/cookbooks/aws-parallelcluster-environment/recipes/config/network_interfaces.rb b/cookbooks/aws-parallelcluster-environment/recipes/config/network_interfaces.rb
181+ --- a/cookbooks/aws-parallelcluster-environment/recipes/config/network_interfaces.rb (revision 9fe7e20db84ca556bcb830210c1f9ea852a38a89)
182+ +++ b/cookbooks/aws-parallelcluster-environment/recipes/config/network_interfaces.rb (revision cb83f4c721ead74d826b433e285eac80b88ad6dc)
183+ @@ -16,7 +16,13 @@
184+ return if on_docker?
185+
186+ def network_card_index(mac, token)
187+ + # This IMDS call is not available on single NIC instance, therefore fallback to 0
188+ uri = URI("http://169.254.169.254/latest/meta-data/network/interfaces/macs/#{mac}/network-card")
189+ + get_metadata_with_token(token, uri) || 0
190+ +end
191+ +
192+ +def device_number(mac, token)
193+ + uri = URI("http://169.254.169.254/latest/meta-data/network/interfaces/macs/#{mac}/device-number")
194+ get_metadata_with_token(token, uri)
195+ end
196+
197+ @@ -69,6 +75,7 @@
198+ # Configure nw interfaces
199+ macs.each do |mac|
200+ device_name = device_name(mac)
201+ + device_number = device_number(mac, token)
202+ network_card_index = network_card_index(mac, token)
203+ gw_ip_address = gateway_address
204+ device_ip_address = device_ip(mac, token)
205+ @@ -84,7 +91,8 @@
206+ environment(
207+ # TODO: The variables are a superset of what's required by individual scripts. Consider simplification.
208+ 'DEVICE_NAME' => device_name,
209+ - 'DEVICE_NUMBER' => "#{network_card_index}", # in configure_nw_interface DEVICE_NUMBER actually means network card index
210+ + 'DEVICE_NUMBER' => "#{device_number}",
211+ + 'NETWORK_CARD_INDEX' => "#{network_card_index}",
212+ 'GW_IP_ADDRESS' => gw_ip_address,
213+ 'DEVICE_IP_ADDRESS' => device_ip_address,
214+ 'CIDR_PREFIX_LENGTH' => cidr_prefix_length,
215+ EOF
216+
217+ git apply support_secondary_network_interface_patch
0 commit comments