clean up potential conflict veth before creating new one in create_ns
Signed-off-by: Yonghong Song <yhs@plumgrid.com>
diff --git a/examples/simulation.py b/examples/simulation.py
index 269ad3f..9e2e677 100644
--- a/examples/simulation.py
+++ b/examples/simulation.py
@@ -1,3 +1,4 @@
+import os
import subprocess
import pyroute2
from pyroute2 import IPRoute, NetNS, IPDB, NSPopen
@@ -46,6 +47,9 @@
# move half of veth into namespace
v.net_ns_fd = ns_ipdb.nl.netns
else:
+ # delete the potentially leaf-over veth interfaces
+ subprocess.call(["ip", "link", "del", "%sa" % ifc_base_name],
+ stderr=open(os.devnull, 'w'))
try:
out_ifc = self.ipdb.create(ifname="%sa" % ifc_base_name, kind="veth",
peer="%sb" % ifc_base_name).commit()