From: Jiri Pirko jiri@mellanox.com
Would be nice to have some helper for this, also most of the changes are untested.
Signed-off-by: Jiri Pirko jiri@mellanox.com --- lnst/Devices/Device.py | 8 ++++---- lnst/Devices/MacvlanDevice.py | 11 ++++++----- lnst/Devices/SoftDevice.py | 3 +-- lnst/Devices/VethDevice.py | 8 +++++--- lnst/Devices/VlanDevice.py | 9 +++++---- lnst/Devices/VxlanDevice.py | 18 +++++++++++++----- 6 files changed, 34 insertions(+), 23 deletions(-)
diff --git a/lnst/Devices/Device.py b/lnst/Devices/Device.py index bd750a9..f71cb9d 100644 --- a/lnst/Devices/Device.py +++ b/lnst/Devices/Device.py @@ -251,7 +251,7 @@ class Device(object): """ with pyroute2.IPRoute() as ipr: try: - ipr.link("set", index=self.ifindex, IFLA_IFNAME=new_name) + ipr.link("set", index=self.ifindex, ifname=new_name) self._if_manager.handle_netlink_msgs() except pyroute2.netlink.NetlinkError: log_exc_traceback() @@ -278,7 +278,7 @@ class Device(object): addr = hwaddress(addr) with pyroute2.IPRoute() as ipr: try: - ipr.link("set", index=self.ifindex, IFLA_ADDRESS=str(addr)) + ipr.link("set", index=self.ifindex, address=str(addr)) self._if_manager.handle_netlink_msgs() except pyroute2.netlink.NetlinkError: log_exc_traceback() @@ -321,7 +321,7 @@ class Device(object): value -- the new MTU.""" with pyroute2.IPRoute() as ipr: try: - ipr.link("set", index=self.ifindex, IFLA_MTU=value) + ipr.link("set", index=self.ifindex, mtu=value) self._if_manager.handle_netlink_msgs() except pyroute2.netlink.NetlinkError: log_exc_traceback() @@ -355,7 +355,7 @@ class Device(object): raise DeviceError("Invalid dev argument.") with pyroute2.IPRoute() as ipr: try: - ipr.link("set", index=self.ifindex, IFLA_MASTER=master_idx) + ipr.link("set", index=self.ifindex, master=master_idx) self._if_manager.handle_netlink_msgs() except pyroute2.netlink.NetlinkError: log_exc_traceback() diff --git a/lnst/Devices/MacvlanDevice.py b/lnst/Devices/MacvlanDevice.py index 4a62844..cd731f9 100644 --- a/lnst/Devices/MacvlanDevice.py +++ b/lnst/Devices/MacvlanDevice.py @@ -29,11 +29,12 @@ class MacvlanDevice(SoftDevice): def _create(self): with pyroute2.IPRoute() as ipr: try: - ipr.link("add", IFLA_IFNAME=self.name, - IFLA_INFO_KIND=self._link_type, - IFLA_INFO_LINK=self._real_dev.ifindex, - IFLA_MACVLAN_MODE=self._mode, - IFLA_MACVLAN_MACADDR=self._hwaddr) + data = {"attrs": [["IFLA_MACVLAN_MODE", self._mode], + ["IFLA_MACVLAN_MACADDR", self._hwaddr]]} + linkinfo = {"attrs": [["IFLA_INFO_KIND", self._link_type], + ["IFLA_INFO_DATA", data]]} + ipr.link("add", ifname=self.name, link=self._real_dev.ifindex, + IFLA_LINKINFO=linkinfo) self._if_manager.handle_netlink_msgs() except pyroute2.netlink.NetlinkError: log_exc_traceback() diff --git a/lnst/Devices/SoftDevice.py b/lnst/Devices/SoftDevice.py index 5b903e3..753ca62 100644 --- a/lnst/Devices/SoftDevice.py +++ b/lnst/Devices/SoftDevice.py @@ -36,8 +36,7 @@ class SoftDevice(Device): def _create(self): with pyroute2.IPRoute() as ipr: try: - ipr.link("add", IFLA_IFNAME=self.name, - IFLA_INFO_KIND=self._link_type) + ipr.link("add", ifname=self.name, kind=self._link_type) self._if_manager.handle_netlink_msgs() except pyroute2.netlink.NetlinkError: log_exc_traceback() diff --git a/lnst/Devices/VethDevice.py b/lnst/Devices/VethDevice.py index 2ada039..38bcce3 100644 --- a/lnst/Devices/VethDevice.py +++ b/lnst/Devices/VethDevice.py @@ -36,9 +36,11 @@ class VethDevice(SoftDevice): def _create(self): with pyroute2.IPRoute() as ipr: try: - ipr.link("add", IFLA_IFNAME=self.name, - IFLA_INFO_KIND=self._link_type, - VETH_INFO_PEER=self._peer_name) + data = {"attrs": [["VETH_INFO_PEER", self._peer_name]]} + linkinfo = {"attrs": [["IFLA_INFO_KIND", self._link_type], + ["IFLA_INFO_DATA", data]]} + ipr.link("add", ifname=self.name, link=self._real_dev.ifindex, + IFLA_LINKINFO=linkinfo) self._if_manager.handle_netlink_msgs() except pyroute2.netlink.NetlinkError: log_exc_traceback() diff --git a/lnst/Devices/VlanDevice.py b/lnst/Devices/VlanDevice.py index 49290ff..bf1fa83 100644 --- a/lnst/Devices/VlanDevice.py +++ b/lnst/Devices/VlanDevice.py @@ -36,10 +36,11 @@ class VlanDevice(SoftDevice): def _create(self): with pyroute2.IPRoute() as ipr: try: - ipr.link("add", IFLA_IFNAME=self.name, - IFLA_INFO_KIND=self._link_type, - IFLA_INFO_LINK=self.real_dev.ifindex, - IFLA_VLAN_ID=self.vlan_id) + data = {"attrs": [["IFLA_VLAN_ID", self._vlan_id]]} + linkinfo = {"attrs": [["IFLA_INFO_KIND", self._link_type], + ["IFLA_INFO_DATA", data]]} + ipr.link("add", ifname=self.name, link=self._real_dev.ifindex, + IFLA_LINKINFO=linkinfo) self._if_manager.handle_netlink_msgs() except pyroute2.netlink.NetlinkError: log_exc_traceback() diff --git a/lnst/Devices/VxlanDevice.py b/lnst/Devices/VxlanDevice.py index 4cb23b6..050ff54 100644 --- a/lnst/Devices/VxlanDevice.py +++ b/lnst/Devices/VxlanDevice.py @@ -57,20 +57,28 @@ class VxlanDevice(SoftDevice): def _create(self): with pyroute2.IPRoute() as ipr: try: - kwargs = {"IFLA_VXLAN_ID": self.vxlan_id, - "IFLA_VXLAN_PORT": self.dst_port} + data = {"attrs": [["IFLA_VXLAN_ID", self.vxlan_id], + ["IFLA_VXLAN_PORT", self.dst_port]]}
if self.real_dev: - kwargs["IFLA_VXLAN_LINK"] = self._real_dev.ifindex + data["attrs"].append(["IFLA_VXLAN_LINK", + self._real_dev.ifindex])
if self.group_ip: - kwargs["IFLA_VXLAN_GROUP"] = self.group_ip + data["attrs"].append(["IFLA_VXLAN_GROUP", self.group_ip]) + elif self.remote_ip: - kwargs["IFLA_VXLAN_GROUP"] = self.remote_ip + data["attrs"].append(["IFLA_VXLAN_GROUP", self.remote_ip])
ipr.link("add", IFLA_IFNAME=self.name, IFLA_INFO_KIND=self._link_type, **kwargs)
+ data = {"attrs": [["IFLA_MACVLAN_MODE", self._mode], + ["IFLA_MACVLAN_MACADDR", self._hwaddr]]} + linkinfo = {"attrs": [["IFLA_INFO_KIND", self._link_type], + ["IFLA_INFO_DATA", data]]} + ipr.link("add", ifname=self.name, IFLA_LINKINFO=linkinfo) + self._if_manager.handle_netlink_msgs() except pyroute2.netlink.NetlinkError: log_exc_traceback()
From: Jiri Pirko jiri@mellanox.com
Signed-off-by: Jiri Pirko jiri@mellanox.com --- lnst/Devices/MasterDevice.py | 4 ++-- lnst/Devices/TeamDevice.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lnst/Devices/MasterDevice.py b/lnst/Devices/MasterDevice.py index afd2060..0ed4751 100644 --- a/lnst/Devices/MasterDevice.py +++ b/lnst/Devices/MasterDevice.py @@ -27,7 +27,7 @@ class MasterDevice(SoftDevice): return ret
def slave_add(self, dev): - dev.master_set(self) + dev.master = self
def slave_del(self, dev): - dev.master_set(None) + dev.master = None diff --git a/lnst/Devices/TeamDevice.py b/lnst/Devices/TeamDevice.py index 7ae797a..c7d151d 100644 --- a/lnst/Devices/TeamDevice.py +++ b/lnst/Devices/TeamDevice.py @@ -58,4 +58,4 @@ class TeamDevice(MasterDevice): dev.name, prepare_json_str(port_config)))
- dev.master_set(self) + dev.master = self
Wed, Sep 20, 2017 at 08:19:44PM CEST, jiri@resnulli.us wrote:
From: Jiri Pirko jiri@mellanox.com
Would be nice to have some helper for this, also most of the changes are untested.
Signed-off-by: Jiri Pirko jiri@mellanox.com
Both self-applied.
lnst-developers@lists.fedorahosted.org