Last active
November 9, 2021 03:05
-
-
Save swamibluedata/1c153562c7eea3b19147e8e8ea6eaf5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
cat > /usr/bin/sriov.sh <<EOF | |
HOSTNAME="$(hostname -f)" | |
PEN_CARDS=`/sbin/lspci -Dnn|grep -i pensando|grep -v Virtual|awk '{print $1}'` | |
## Enable SRIOV Profile, 16 for each card | |
for l in $PEN_CARDS | |
do | |
SRV=`find /sys -name sriov_numvfs|grep $l` | |
if [ -z "$SRV" ] | |
then | |
continue | |
fi | |
# Enable sriov profile | |
echo 16 >$SRV | |
# Generate a unique prefix based on hostname and the pci id of the Card | |
MAC_ADDR_PREFIX=$(echo ${HOSTNAME}-$l|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4/') | |
# Find all interfaces with all zeros mac address and assign them based on the prefix above | |
index=0 | |
for i in $(ip -o link show | awk -F': ' '{print $2}') | |
do | |
if [ "$i" != "lo" ] | |
then | |
mac=$(cat /sys/class/net/$i/address) | |
if [[ $mac == *"00:00:00:00:00:00"* ]] | |
then | |
x=$(printf "%02X\n" $index) | |
echo "setting mac addr for device $i $MAC_ADDR_PREFIX:$x" | |
index=$((index + 1)) | |
ip link set "$i" address "$MAC_ADDR_PREFIX:$x" | |
fi | |
fi | |
done | |
done | |
EOF | |
chmod +x /usr/bin/sriov.sh | |
cat > /etc/systemd/system/pen-sriov.service <<EOF | |
[Unit] | |
Description=Oneshot service to enable sriov profile and configure mac addresses for VFs | |
[Service] | |
Type=oneshot | |
ExecStart=//usr/bin/sriov.sh | |
RemainAfterExit=yes | |
TimeoutSec=0 | |
# Output needs to appear in instance console output | |
StandardOutput=journal+console | |
StandardError=journal+console | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
systemctl daemon-reload | |
systemctl enable pen-sriov | |
systemctl start pen-sriov | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment