pyroute2
pyroute2 copied to clipboard
enable IPRoute to pass teamd config
Currently it is impossible to add a team device with specific configuration using IPRoute. Instead a hardcoded config is used.
Code sample:
from pyroute2 import IPRoute
ipr = IPRoute()
ret_val = ipr.link('add', ifname='myteam', kind='team')
$ pgrep -fa teamd
5727 teamd -d -n -c {"device": "myteam", "runner": {"name": "activebackup"}, "link_watch": {"name": "ethtool"}}
Yep, to be fixed asap. Thanks for heads-up!
It should work now like that:
import json
from pyroute2 import IPRoute
config = {'runner': {'name': 'activebackup'},
'link_watch': {'name': 'ethtool'},
'hwaddr': '00:11:22:33:44:55'}
ipr = IPRoute()
ipr.link('add',
ifname='myteam',
kind='team',
team_config=json.dumps(config))
Note regarding the device
config option: the ifname
argument for ipr.link('add',…)
is mandatory, and the device
option is filled authomatically from it, so you may omit it in the config.
In the case of conflict between the config and ipr.link()
arguments, the arguments will override the config.
TODO: support config options like hwaddr that are common for all the devices as normal arguments as well. Not closing the issue.
Thanks Pete! That was fast! Ack on device being autofilled from ifname.
Tested locally with the following script:
from pyroute2 import IPRoute
import json
ipr = IPRoute()
obj = getattr(ipr, 'link')
config = {
'runner': {'name': 'roundrobin'},
'link_watch': {'name': 'ethtool'},
'hwaddr': '00:11:22:33:44:55'
}
ret_val = obj('add', ifname='myteam', kind='team',
team_config=json.dumps(config))
$ sudo python3 test-pyroute-team.py
$ pgrep -fa teamd
20027 teamd -d -n -c {"runner": {"name": "roundrobin"}, "link_watch": {"name": "ethtool"}, "hwaddr": "00:11:22:33:44:55", "device": "myteam"}
Hi,
I have a related question, for Team pyroute2 is directly calling teamd/teamdctl. Is this because team doesn't use netlink configuration at all or because it is somehow complicated?
I'm asking because currently LNST uses pyroute2 specifically for netlink quite a bit and it feels a little weird having Team be different but still through pyroute2...
@olichtne , as I understand, team interfaces are backed with the teamd
, the logic is implemented in the userspace, not in the kernel. Thus we can not simply start it by the netlink — pyroute2 can create the interface, but has no team
userspace code to run the created interface.
There are several solutions. One is implemented right now: we don't run any team
logic in pyroute2, but start the reference implementation, teamd
by @jtluka . Another solution would be to implement all the team
logic in the pyroute2 library, but I wouldn't like to do that, I simply have no time resource to write and support it.
That makes sense, like I've said I'm not too familiar with how teams are implemented so I was just asking for clarification. Thanks for the answer :).