This patch adds implementation of a device class for the loopback device (lo) so that users can benefit from the common API for the other devices, for example IP address configuration.
The up() and down() methods are disabled for this type of device as this breaks connection between the controller and LNST agents during recipe execution.
Signed-off-by: Jan Tluka jtluka@redhat.com --- lnst/Devices/LoopbackDevice.py | 29 +++++++++++++++++++++++++++++ lnst/Devices/__init__.py | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 lnst/Devices/LoopbackDevice.py
diff --git a/lnst/Devices/LoopbackDevice.py b/lnst/Devices/LoopbackDevice.py new file mode 100644 index 00000000..2154897d --- /dev/null +++ b/lnst/Devices/LoopbackDevice.py @@ -0,0 +1,29 @@ +""" +Defines the LoopbackDevice class. + +Copyright 2021 Red Hat, Inc. +Licensed under the GNU General Public License, version 2 as +published by the Free Software Foundation; see COPYING for details. +""" + +__author__ = """ +jtluka@redhat.com (Jan Tluka) +""" + +import pyroute2 +import logging +from lnst.Devices.Device import Device + +class LoopbackDevice(Device): + @Device.name.getter + def name(self): + return "lo" + + def _create(self): + pass + + def up(self): + logging.warning("Link state operations on LoopbackDevice are disallowed") + + def down(self): + logging.warning("Link state operations on LoopbackDevice are disallowed") diff --git a/lnst/Devices/__init__.py b/lnst/Devices/__init__.py index 52e4499e..b294ff57 100644 --- a/lnst/Devices/__init__.py +++ b/lnst/Devices/__init__.py @@ -1,5 +1,6 @@ from lnst.Common.DeviceError import DeviceError from lnst.Devices.Device import Device +from lnst.Devices.LoopbackDevice import LoopbackDevice from lnst.Devices.BridgeDevice import BridgeDevice from lnst.Devices.OvsBridgeDevice import OvsBridgeDevice from lnst.Devices.BondDevice import BondDevice @@ -22,6 +23,7 @@ from lnst.Devices.RemoteDevice import RemoteDevice, remotedev_decorator
device_classes = [ ("Device", Device), + ("LoopbackDevice", LoopbackDevice), ("BridgeDevice", BridgeDevice), ("OvsBridgeDevice", OvsBridgeDevice), ("MacvlanDevice", MacvlanDevice),