Ejemplo n.º 1
0
 def remove(self, path):
     netnspath = netns._get_netnspath(path)
     info = None
     try:
         info = self.ipr._dump_one_ns(netnspath, set())
     except SkipInode:
         raise NetlinkError(errno.EEXIST)
     info['header']['type'] = RTM_DELNETNS
     info['header']['target'] = self.target
     info['event'] = 'RTM_DELNETNS'
     del info['value']
     try:
         netns.remove(netnspath, self.libc)
     except OSError as e:
         raise NetlinkError(e.errno)
     return (info,)
Ejemplo n.º 2
0
 def teardown(self):
     '''
     1. close the test NDB
     2. remove the registered interfaces, ignore not existing
     '''
     self.ndb.close()
     self.ipr.close()
     for (ifname, nsname) in self.interfaces.items():
         try:
             ipr = None
             #
             # spawn ipr to remove the interface
             if nsname is not None:
                 ipr = NetNS(nsname)
             else:
                 ipr = IPRoute()
             #
             # lookup the interface index
             index = list(ipr.link_lookup(ifname=ifname))
             if len(index):
                 index = index[0]
             else:
                 #
                 # ignore not existing interfaces
                 continue
             #
             # try to remove it
             ipr.link('del', index=index)
         except NetlinkError as e:
             #
             # ignore if removed (t.ex. by another process)
             if e.code != errno.ENODEV:
                 raise
         finally:
             if ipr is not None:
                 ipr.close()
     for nsname in self.namespaces:
         netns.remove(nsname)
     for net in self.ipnets:
         free_network(net)
Ejemplo n.º 3
0
 def remove(self):
     '''
     Try to remove this network namespace from the system.
     '''
     remove(self.netns)