Skip to content

Commit

Permalink
Configure multi-nic
Browse files Browse the repository at this point in the history
Signed-off-by: Hanwen <[email protected]>
  • Loading branch information
hanwen-cluster committed Jun 25, 2024
1 parent 673f874 commit d3b60ea
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh

set -ex

if
[ -z "${DEVICE_NAME}" ] || # name of the device
[ -z "${DEVICE_NUMBER}" ] || # number of the device
[ -z "${DEVICE_IP_ADDRESS}" ] || # ip of the device
[ -z "${MAC}" ] || # mac address of the device
[ -z "${CIDR_BLOCK}" ] # CIDR block of the subnet
then
echo 'One or more environment variables missing'
exit 1
fi
echo "Device name: ${DEVICE_NAME}, Device number: ${DEVICE_NUMBER}"

configuration_directory="/etc/systemd/network"
file_name="70-${DEVICE_NAME}.network"
sub_directory="${configuration_directory}/${file_name}.d"
if [ ! -d "$sub_directory" ]; then
mkdir -p "$sub_directory";
fi

cd "$configuration_directory"

ROUTE_TABLE=200${DEVICE_NUMBER}

ln -s /usr/lib/systemd/network/80-ec2.network ${file_name}

if ! grep "RoutingPolicyRule" $files_list; then
/bin/cat <<EOF > ${sub_directory}/eni.conf
# Configuration for ${DEVICE_NUMBER} generated by ParallelCluster
[Match]
MACAddress=${MAC}
[Network]
DHCP=yes
[DHCPv4]
RouteMetric=$ROUTE_TABLE
UseRoutes=true
UseGateway=true
[IPv6AcceptRA]
RouteMetric=$ROUTE_TABLE
UseGateway=true
[Route]
Table=$ROUTE_TABLE
Gateway=_ipv6ra
[Route]
Gateway=_dhcp4
Table=$ROUTE_TABLE
[Route]
Table=$ROUTE_TABLE
Destination=$CIDR_BLOCK
[RoutingPolicyRule]
From=${DEVICE_IP_ADDRESS}
Priority=$ROUTE_TABLE
Table=$ROUTE_TABLE
EOF
fi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

# amazon-ec2-net-utils is pre-installed in AL2023 and handles multi-nics instances properly
return if on_docker? || platform?('amazon') && node['platform_version'].to_i == 2023
return if on_docker?

def network_card_index(mac, token)
uri = URI("http://169.254.169.254/latest/meta-data/network/interfaces/macs/#{mac}/network-card")
Expand Down Expand Up @@ -88,7 +88,8 @@ def cidr_to_netmask(cidr)
'DEVICE_IP_ADDRESS' => device_ip_address,
'CIDR_PREFIX_LENGTH' => cidr_prefix_length,
'NETMASK' => netmask,
'CIDR_BLOCK' => cidr_block
'CIDR_BLOCK' => cidr_block,
'MAC' => mac
)

command 'sh /tmp/configure_nw_interface.sh'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@
end

use 'partial/_network_service'
use 'partial/_network_service_redhat_based'

def network_service_name
'systemd-resolved'
'systemd-networkd'
end

action :restart do
log "Restarting 'systemd-networkd systemd-resolved' service, platform #{node['platform']} '#{node['platform_version']}'"

execute "Reload system configuration" do
command "systemctl daemon-reload"
end

%w(systemd-networkd systemd-resolved).each do |service_name|
service service_name do
action :restart
ignore_failure true
end
end
end
2 changes: 2 additions & 0 deletions cookbooks/aws-parallelcluster-slurm/recipes/init/init_dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@
path "/etc/hosts"
line(lazy { "#{get_primary_ip} #{node['cluster']['assigned_hostname'].chomp('.')} #{node['cluster']['assigned_short_hostname']}" })
notifies :reload, "ohai[reload_hostname]"
retries 20
retry_delay 5
end

0 comments on commit d3b60ea

Please sign in to comment.