There's barely anything can be used to distinguish but only the name (or
ifindex) itself.


root@node-1970:~# udevadm info /sys/class/net/ens3nsby
P: /devices/pci0000:00/0000:00:03.0/virtio0/net/ens3nsby
E: DEVPATH=/devices/pci0000:00/0000:00:03.0/virtio0/net/ens3nsby
E: ID_BUS=pci
E: ID_MODEL_FROM_DATABASE=Virtio network device
E: ID_MODEL_ID=0x1000
E: ID_NET_DRIVER=virtio_net
E: ID_NET_LINK_FILE=/lib/systemd/network/99-default.link
E: ID_NET_NAME_MAC=enx02001701d517
E: ID_NET_NAME_PATH=enp0s3nsby
E: ID_NET_NAME_SLOT=ens3nsby
E: ID_PATH=pci-0000:00:03.0
E: ID_PATH_TAG=pci-0000_00_03_0
E: ID_PCI_CLASS_FROM_DATABASE=Network controller
E: ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller
E: ID_VENDOR_FROM_DATABASE=Red Hat, Inc.
E: ID_VENDOR_ID=0x1af4
E: IFINDEX=3
E: INTERFACE=ens3nsby
E: SUBSYSTEM=net
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/ens3nsby
E: TAGS=:systemd:
E: USEC_INITIALIZED=2496132
E: net.ifnames=1

root@node-1970:~# udevadm info /sys/class/net/ens3
P: /devices/pci0000:00/0000:00:03.0/virtio0/net/ens3
E: DEVPATH=/devices/pci0000:00/0000:00:03.0/virtio0/net/ens3
E: ID_BUS=pci
E: ID_MODEL_FROM_DATABASE=Virtio network device
E: ID_MODEL_ID=0x1000
E: ID_NET_DRIVER=net_failover
E: ID_NET_LINK_FILE=/lib/systemd/network/99-default.link
E: ID_NET_NAME_MAC=enx02001701d517
E: ID_NET_NAME_PATH=enp0s3
E: ID_NET_NAME_SLOT=ens3
E: ID_PATH=pci-0000:00:03.0
E: ID_PATH_TAG=pci-0000_00_03_0
E: ID_PCI_CLASS_FROM_DATABASE=Network controller
E: ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller
E: ID_VENDOR_FROM_DATABASE=Red Hat, Inc.
E: ID_VENDOR_ID=0x1af4
E: IFINDEX=2
E: INTERFACE=ens3
E: SUBSYSTEM=net
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/ens3
E: TAGS=:systemd:
E: USEC_INITIALIZED=2472184
E: net.ifnames=1


Below is a script we are using, which gets executed early in udev rules, to 
identify the role of each interface for 3-netdev.

# cat /lib/udev/detect_failover
#!/bin/sh -e
#
# Copyright (C) 2019 Oracle Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation version 2 of the License.
#
# This script is run to detect the role of failover network device
# so as to define naming rules based on properties of the device.

get_drvname() {
        /bin/basename `/bin/readlink ${1}/device/driver`
}

has_standby() {
        features=`cat ${1}/device/features`
        [ "${features:62:1}" = "1" ]
}

# debug, if UDEV_LOG=<debug>
if [ -n "$UDEV_LOG" ]; then
        if [ "$UDEV_LOG" -ge 7 ]; then
                set -x
        fi
fi
if [ -z "$INTERFACE" ]; then
        exit 1
fi

devpath="/sys/class/net/$INTERFACE"
if [ ! -d $devpath -o ! -d ${devpath}/device ]; then
        exit 1
fi

if [ `get_drvname $devpath` = virtio_net ] && has_standby $devpath; then
        if [ -d ${devpath}/master ]; then
                echo 3 # Failover standby
        else
                echo 1 # Failover master
        fi
elif [ -d ${devpath}/master ] && [ `get_drvname ${devpath}/master` = virtio_net 
] && has_standby ${devpath}/master; then
        echo 2 # Failover primary
fi
exit 0

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1820929

Title:
  netplan should consider adding more udev attribute for exact matching
  of failover 3-netdev interfaces

To manage notifications about this bug go to:
https://bugs.launchpad.net/netplan/+bug/1820929/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to