svinota / pyroute2

Python Netlink and PF_ROUTE library — network configuration and monitoring
https://pyroute2.org/
Other
944 stars 243 forks source link

question: how to add vlan to bridge? #684

Open DFritzsche opened 4 years ago

DFritzsche commented 4 years ago

Good morning,

I want to use pyroute2 to add a VLAN to a bridge. In iproute2 I would run the following command:

bridge vlan add vid 500 dev bridge1 self

I could find the documentation on how to set vlan_filter on ports, but I have no idea on how to set the keyword "self" (or "master").

That is the example I found in https://github.com/svinota/pyroute2/blob/master/pyroute2/iproute/linux.py#L688

I also saw that the bridge flags self/master exist here: https://github.com/svinota/pyroute2/blob/master/pyroute2/netlink/rtnl/ifinfmsg/__init__.py#L126

Could you please provide an example.

Thank you very much Daniel

svinota commented 4 years ago

Yep, I'll update the docs asap.

ipr.vlan_filter("add",
                index=ipr.link_lookup(ifname='bridge1'),
                vlan_info={'vid': 500},
                vlan_flags='self')

Same for master, just use the word master instead of self, more details: https://github.com/svinota/pyroute2/blob/0aacc7a26874c3ccba30d6e3a4d497b167573ffd/pyroute2/netlink/rtnl/ifinfmsg/__init__.py#L897-L905