This is to support so called lightweight tunnels when tunnel metadata is defined externally, e.g. using 'ip route .. encap' command.
Since the external flag makes any mandatory options irrelevant, the mandatory options are defined dynamically.
Signed-off-by: Jan Tluka jtluka@redhat.com --- lnst/Devices/GeneveDevice.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/lnst/Devices/GeneveDevice.py b/lnst/Devices/GeneveDevice.py index a188ef4c..2418c7c9 100644 --- a/lnst/Devices/GeneveDevice.py +++ b/lnst/Devices/GeneveDevice.py @@ -21,7 +21,12 @@ from lnst.Devices.SoftDevice import SoftDevice class GeneveDevice(SoftDevice): _name_template = "t_gnv" _link_type = "geneve" - _mandatory_opts = ["id", "remote"] + + def __init__(self, ifmanager, *args, **kwargs): + if "external" not in kwargs: + self._mandatory_opts = ["id", "remote"] + + super(GeneveDevice, self).__init__(ifmanager, *args, **kwargs)
@property def id(self): @@ -63,3 +68,13 @@ class GeneveDevice(SoftDevice): def dst_port(self, val): self._set_linkinfo_data_attr("IFLA_GENEVE_PORT", int(val)) self._nl_link_sync("set") + + @property + def external(self): + return self._get_linkinfo_data_attr("IFLA_GENEVE_COLLECT_METADATA") is not None + + @external.setter + def external(self, val): + if val: + self._set_linkinfo_data_attr("IFLA_GENEVE_COLLECT_METADATA", True) + self._nl_link_sync("set")
This is to support so called lightweight tunnels when tunnel metadata is defined externally, e.g. using 'ip route .. encap' command.
Since the external flag makes any mandatory options irrelevant, the mandatory options are defined dynamically.
Signed-off-by: Jan Tluka jtluka@redhat.com --- lnst/Devices/GreDevice.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/lnst/Devices/GreDevice.py b/lnst/Devices/GreDevice.py index d1affbc3..5abf9fd4 100644 --- a/lnst/Devices/GreDevice.py +++ b/lnst/Devices/GreDevice.py @@ -17,7 +17,12 @@ from lnst.Devices.SoftDevice import SoftDevice class GreDevice(SoftDevice): _name_template = "t_gre" _link_type = "gre" - _mandatory_opts = ["remote"] + + def __init__(self, ifmanager, *args, **kwargs): + if "external" not in kwargs: + self._mandatory_opts = ["remote"] + + super(GreDevice, self).__init__(ifmanager, *args, **kwargs)
@property def local(self): @@ -41,4 +46,13 @@ class GreDevice(SoftDevice): @remote.setter def remote(self, val): self._set_linkinfo_data_attr("IFLA_GRE_REMOTE", str(ipaddress(val))) + + @property + def external(self): + return self._get_linkinfo_data_attr("IFLA_GRE_COLLECT_METADATA") is not None + + @external.setter + def external(self, val): + if val: + self._set_linkinfo_data_attr("IFLA_GRE_COLLECT_METADATA", True) self._nl_link_sync("set")
This is to support so called lightweight tunnels when tunnel metadata is defined externally, e.g. using 'ip route .. encap' command.
Since the external flag makes any mandatory options irrelevant, the mandatory options are defined dynamically.
Signed-off-by: Jan Tluka jtluka@redhat.com --- lnst/Devices/VxlanDevice.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/lnst/Devices/VxlanDevice.py b/lnst/Devices/VxlanDevice.py index f5e0e50f..1426d3e2 100644 --- a/lnst/Devices/VxlanDevice.py +++ b/lnst/Devices/VxlanDevice.py @@ -22,23 +22,23 @@ class VxlanDevice(SoftDevice): _name_template = "t_vxlan" _link_type = "vxlan"
- _mandatory_opts = ["vxlan_id"] - def __init__(self, ifmanager, *args, **kwargs): - if "group" in kwargs and "remote" in kwargs: - raise DeviceError("group and remote cannot both be specified for vxlan") + if "external" not in kwargs: + self._mandatory_opts = ["vxlan_id"] + if "group" in kwargs and "remote" in kwargs: + raise DeviceError("group and remote cannot both be specified for vxlan")
- if "group" not in kwargs and "remote" not in kwargs: - raise DeviceError("One of group or remote must be specified for vxlan") + if "group" not in kwargs and "remote" not in kwargs: + raise DeviceError("One of group or remote must be specified for vxlan")
- if "group" in kwargs and "realdev" not in kwargs: - raise DeviceError("'group' requires realdev to be specified") + if "group" in kwargs and "realdev" not in kwargs: + raise DeviceError("'group' requires realdev to be specified")
- if kwargs.get("remote", False) and ipaddress(kwargs["remote"]).is_multicast: - logging.debug("ATTENTION: non-unicast remote IP set: %s" % str(kwargs["remote"])) + if kwargs.get("remote", False) and ipaddress(kwargs["remote"]).is_multicast: + logging.debug("ATTENTION: non-unicast remote IP set: %s" % str(kwargs["remote"]))
- if kwargs.get("group", False) and not ipaddress(kwargs["group"]).is_multicast: - logging.debug("ATTENTION: non-multicast group IP set: %s" % str(kwargs["group"])) + if kwargs.get("group", False) and not ipaddress(kwargs["group"]).is_multicast: + logging.debug("ATTENTION: non-multicast group IP set: %s" % str(kwargs["group"]))
super(VxlanDevice, self).__init__(ifmanager, *args, **kwargs)
@@ -107,3 +107,13 @@ class VxlanDevice(SoftDevice): def dst_port(self, val): self._set_linkinfo_data_attr("IFLA_VXLAN_PORT", int(val)) self._nl_link_sync("set") + + @property + def external(self): + return self._get_linkinfo_data_attr("IFLA_VXLAN_COLLECT_METADATA") is not None + + @external.setter + def external(self, val): + if val: + self._set_linkinfo_data_attr("IFLA_VXLAN_COLLECT_METADATA", True) + self._nl_link_sync("set")
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),
I think the InterfaceManager automatically creates a "disabled" Device class instance for the loopback device.
So I'm not against the creation of a special class type for it but I think maybe we need a bit more integration if we want to go that way so that we avoid having 2 instances for loopback tracked in the Interfacemanager.
On the other hand maybe we don't need this at all and the Device class already suuports all of this... we should check.
-Ondrej
On Tue, May 18, 2021 at 03:10:36PM +0200, Jan Tluka wrote:
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),
-- 2.26.3 _______________________________________________ LNST-developers mailing list -- lnst-developers@lists.fedorahosted.org To unsubscribe send an email to lnst-developers-leave@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/lnst-developers@lists.fedorahos... Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
lnst-developers@lists.fedorahosted.org