TT#53682 Assign eth* devices by PCIID

In the past we were associating them by MAC address and only in some cases, like
Pro/Carrier and in Virtual Machine environments.

However, it's beneficial to have this in other scenarios, so we will create udev
rules to pin them down during deployment.

Change-Id: Ic1b397e81af673b974961158a0e9a05ce5b80a69
changes/25/30525/8
Manuel Montecelo 6 years ago
parent 310752a503
commit d3c7919a88

@ -1536,23 +1536,23 @@ EOF
NETWORK_DEVICES="$(tail -n +3 /proc/net/dev | sed -r 's/^ *([0-9a-zA-Z]+):.*$/\1/g' | \
grep -ve '^vmnet' -ve '^vboxnet' -ve '^docker' -ve '^usb' -ve '^vlan' -ve '^bond' | sort -u)"
if "$PRO_EDITION" && [[ $(imvirt) != "Physical" ]] ; then
echo "Generating udev persistent net rules."
echo "## Generated by Sipwise deployment script" > \
"${TARGET}/etc/udev/rules.d/70-persistent-net.rules"
for dev in ${NETWORK_DEVICES}; do
[[ "${dev}" =~ ^lo ]] && continue
mac=$(udevadm info -a -p "/sys/class/net/${dev}" | sed -nr 's/^ *ATTR\{address\}=="(.+)".*$/\1/p')
if [[ "${mac}" =~ ^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ ]]; then
echo "Adding device '${dev}' with MAC '${mac}'"
cat >> "${TARGET}/etc/udev/rules.d/70-persistent-net.rules" <<EOL
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="${mac}", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="${dev}"
echo "Generating udev persistent net rules."
TARGET_UDEV_PERSISTENT_NET_RULES="${TARGET}/etc/udev/rules.d/70-persistent-net.rules"
echo "## Generated by Sipwise deployment script" > "${TARGET_UDEV_PERSISTENT_NET_RULES}"
for dev in ${NETWORK_DEVICES}; do
[[ "${dev}" =~ ^lo ]] && continue
pciid=$(ethtool -i "${dev}" | awk '/^bus-info: / {print $2}')
if [[ "${pciid}" =~ ^([0-9a-fA-F:.])+$ ]]; then
echo "Adding device '${dev}' with PCIID '${pciid}'"
cat >> "${TARGET_UDEV_PERSISTENT_NET_RULES}" <<EOL
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", KERNELS=="${pciid}", NAME="${dev}"
EOL
fi
done
unset mac
fi
else
echo "WARNING: could not find valid PCIID '${pciid}' for device '${dev}'"
fi
unset pciid
done
get_installer_path() {
if [ -z "$SP_VERSION" ] && ! $TRUNK_VERSION ; then
@ -1886,8 +1886,8 @@ vagrant_configuration() {
# MACs are different on buildbox and on local VirtualBox
# see http://ablecoder.com/b/2012/04/09/vagrant-broken-networking-when-packaging-ubuntu-boxes/
echo "Removing /etc/udev/rules.d/70-persistent-net.rules"
rm -f "${TARGET}/etc/udev/rules.d/70-persistent-net.rules"
echo "Removing '${TARGET_UDEV_PERSISTENT_NET_RULES}'"
rm -f "${TARGET_UDEV_PERSISTENT_NET_RULES:?}"
if [ -d "${TARGET}/etc/.git" ]; then
echo "Commit /etc/* changes using etckeeper"

Loading…
Cancel
Save