From: Ondrej Lichtner <olichtne(a)redhat.com>
The factory method shouldn't arbitrarily select the first ipaddress of
the provided Device. I think the factory should just accept something
that can be parsed to create an IpAddress object, in all other cases we
should explicitly use property getters to access already existing
objects.
My reasoning is that I don't think hiding device.ips[0] fits within what
a user would expect to see from a factory method. The specific "magic"
[0] selection should be explicitly visible to the user to avoid
confusion so I think the user should choose to write it himself.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Common/IpAddress.py | 8 --------
1 file changed, 8 deletions(-)
diff --git a/lnst/Common/IpAddress.py b/lnst/Common/IpAddress.py
index 73802c5..e54553d 100644
--- a/lnst/Common/IpAddress.py
+++ b/lnst/Common/IpAddress.py
@@ -99,9 +99,6 @@ class Ip6Address(BaseIpAddress):
def ipaddress(addr):
"""Factory method to create a BaseIpAddress object"""
- #runtime import this because the Device class arrives on the Slave
- #during recipe execution, not during Slave init
- from lnst.Devices.Device import Device
if isinstance(addr, BaseIpAddress):
return addr
elif isinstance(addr, str):
@@ -109,11 +106,6 @@ def ipaddress(addr):
return Ip4Address(addr)
except:
return Ip6Address(addr)
- elif isinstance(addr, Device):
- try:
- return addr.ips[0]
- except IndexError:
- raise LnstError("No usable Ip Addresses on the provided Device.")
else:
raise LnstError("Value must be a BaseIpAddress or string object."
" Not {}".format(type(addr)))
--
2.17.0