use pyroute2 IProute to remove the stale veth
authorYonghong Song <yhs@plumgrid.com>
Tue, 11 Aug 2015 02:04:58 +0000 (19:04 -0700)
committerYonghong Song <yhs@plumgrid.com>
Wed, 12 Aug 2015 15:02:21 +0000 (08:02 -0700)
Signed-off-by: Yonghong Song <yhs@plumgrid.com>
examples/simulation.py

index 9e2e677..e2c8b2d 100644 (file)
@@ -48,8 +48,8 @@ class Simulation(object):
                 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'))
+            ipr = IPRoute()
+            for i in ipr.link_lookup(ifname='%sa' % ifc_base_name): ipr.link_remove(i)
             try:
                 out_ifc = self.ipdb.create(ifname="%sa" % ifc_base_name, kind="veth",
                                            peer="%sb" % ifc_base_name).commit()