From: Ondrej Lichtner <olichtne(a)redhat.com>
The property contains the name of the attribute that the class instance
was first assigned to when created on a Namespace instance. Example:
host1.my_vlan_device = VlanDevice(...)
The _id attribute in this case is "my_vlan_device".
The attribute starts with "_" to indicate that it's for internal LNST
code use. Specifically it will be used for logging messages involving
the device.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Host.py | 1 +
lnst/Controller/Namespace.py | 1 +
lnst/Devices/RemoteDevice.py | 9 +++++++++
3 files changed, 11 insertions(+)
diff --git a/lnst/Controller/Host.py b/lnst/Controller/Host.py
index d19ea67..89b6b25 100644
--- a/lnst/Controller/Host.py
+++ b/lnst/Controller/Host.py
@@ -61,6 +61,7 @@ def map_device(self, dev_id, how):
dev = self._machine.get_dev_by_hwaddr(hwaddr)
if dev:
self._objects[dev_id] = dev
+ dev._id = dev_id
dev._enable()
else:
raise ControllerError("Device with macaddr {} not found on {}."
diff --git a/lnst/Controller/Namespace.py b/lnst/Controller/Namespace.py
index 8c96ced..7ff7f2a 100644
--- a/lnst/Controller/Namespace.py
+++ b/lnst/Controller/Namespace.py
@@ -158,6 +158,7 @@ def _custom_setattr(self, name, value):
self._objects[name] = value
return True
else:
+ value._id = name
if isinstance(value, VirtualDevice):
# TODO creation of VirtualDevices should be disabled during
# test execution, it's commented out right now because I
diff --git a/lnst/Devices/RemoteDevice.py b/lnst/Devices/RemoteDevice.py
index 4184bed..1f2c286 100644
--- a/lnst/Devices/RemoteDevice.py
+++ b/lnst/Devices/RemoteDevice.py
@@ -32,6 +32,7 @@ def __init__(self, dev_cls, args=[], kwargs={}):
self.__dev_args = args
self.__dev_kwargs = kwargs
self.__netns = None
+ self.__id = None
self._machine = None
self.ifindex = None
@@ -79,6 +80,14 @@ def _dev_args(self):
def _dev_kwargs(self):
return self.__dev_kwargs
+ def __id_get(self):
+ return self.__id
+
+ def __id_set(self, value):
+ self.__id = value
+
+ _id = property(__id_get, __id_set)
+
def _get_dev_cls(self):
return self._dev_cls
--
2.21.0