pyroute2
pyroute2 copied to clipboard
IPRoute.link_lookup('some-alt-name') does not work.
What I think:
ipr.link_lookup(ifname='xxx') - should lookup by iface name (works OK)
This one gives nothing:
ipr.link_lookup(alt_ifname='xxx') - should lookup by alternative name (IFLA_ALT_IFNAME)
This one works partly:
ipr.link_lookup('xxx') - should lookup EITHER by alternative name or ifname (like in ip command)
This one, works OK:
ipr.link("get", alt_ifname=altname)
Hello,
I think that this simple patch could fix the second one:
diff --git a/pyroute2/iproute/linux.py b/pyroute2/iproute/linux.py
index a284b621..65a14761 100644
--- a/pyroute2/iproute/linux.py
+++ b/pyroute2/iproute/linux.py
@@ -778,7 +778,7 @@ class RTNL_API:
Please note, that link_lookup() returns list, not one
value.
'''
- if set(kwarg) in ({'index'}, {'ifname'}, {'index', 'ifname'}):
+ if kwarg and set(kwarg).issubset({"index", "ifname", "alt_ifname"}):
# shortcut for index and ifname
try:
for link in self.link('get', **kwarg):
altname keyword in link_lookup is fixed:
ipr.link_lookup(ifname='eth0')
ipr.link_lookup(altname='external')
Pls notice that link_lookup() takes as the only positional argument either a function, or a dictionary, used to filter messages.
I'm not sure that support for ifname and altname as a positional argument too is a good idea, but if you have reasons for that -- pls tell me.
FYI: This feature works since version 0.7.6
@svinota ipr.link("get", alt_ifname='xxx') uses alt_ifname, but link_lookup uses altname. Please rework to consistent API. Seems compatibility with old API should be considered.