diff options
Diffstat (limited to 'resources/libraries/python')
-rw-r--r-- | resources/libraries/python/IPUtil.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/resources/libraries/python/IPUtil.py b/resources/libraries/python/IPUtil.py index ed38272645..f3c037fdf0 100644 --- a/resources/libraries/python/IPUtil.py +++ b/resources/libraries/python/IPUtil.py @@ -139,6 +139,26 @@ class IPUtil(object): raise RuntimeError( 'Could not set IP for interface, reason:{}'.format(stderr)) + @staticmethod + def set_linux_interface_route(node, interface, route, namespace=None): + """Set route via interface in linux. + + :param node: Node where to execute command. + :param interface: Interface in namespace. + :param route: Route to be added via interface. + :param namespace: Execute command in namespace. Optional parameter. + :type node: dict + :type interface: str + :type route: str + :type namespace: str + """ + if namespace is not None: + cmd = 'ip netns exec {} ip route add {} dev {}'.format( + namespace, route, interface) + else: + cmd = 'ip route add {} dev {}'.format(route, interface) + exec_cmd_no_error(node, cmd, sudo=True) + def convert_ipv4_netmask_prefix(network): """Convert network mask to equivalent network prefix length or vice versa. |