pyroute2 icon indicating copy to clipboard operation
pyroute2 copied to clipboard

IPRoute.link_lookup('some-alt-name') does not work.

Open socketpair opened this issue 2 years ago • 2 comments

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)

socketpair avatar Jan 22 '23 17:01 socketpair

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):

ffourcot avatar Jan 23 '23 08:01 ffourcot

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.

svinota avatar Feb 16 '23 20:02 svinota

FYI: This feature works since version 0.7.6

socketpair avatar Jul 29 '24 18:07 socketpair

@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.

socketpair avatar Jul 29 '24 18:07 socketpair