Commit 62e29870 authored by Martín Ferrari's avatar Martín Ferrari

Change the semantics of the migrate flag, to make it more intuitive

parent 3103ec9f
...@@ -182,36 +182,37 @@ class P2PInterface(NSInterface): ...@@ -182,36 +182,37 @@ class P2PInterface(NSInterface):
class ImportedNodeInterface(NSInterface): class ImportedNodeInterface(NSInterface):
"""Class to handle already existing interfaces inside a name space: """Class to handle already existing interfaces inside a name space:
real devices, tun devices, etc. real devices, tun devices, etc.
The flag 'migrate' in the constructor indicates that the interface was The flag 'migrate' in the constructor indicates that the interface needs
migrated inside the name space. to be moved inside the name space.
On destruction, the interface will be restored to the original name space On destruction, the interface will be restored to the original name space
and will try to restore the original state.""" and will try to restore the original state."""
def __init__(self, node, iface, migrate = False): def __init__(self, node, iface, migrate = True):
self._slave = None self._slave = None
self._migrate = migrate self._migrate = migrate
if self._migrate: if self._migrate:
iface = node._slave.get_if_data(iface)
self._original_state = iface.copy()
else:
iface = netns.iproute.get_if(iface) iface = netns.iproute.get_if(iface)
self._original_state = iface.copy() self._original_state = iface.copy()
# Change the name to avoid clashes # Change the name to avoid clashes
iface.name = self._gen_if_name() iface.name = self._gen_if_name()
netns.iproute.set_if(iface) netns.iproute.set_if(iface)
# Migrate it
netns.iproute.change_netns(iface, node.pid) netns.iproute.change_netns(iface, node.pid)
else:
iface = node._slave.get_if_data(iface)
self._original_state = iface.copy()
super(ImportedNodeInterface, self).__init__(node, iface.index) super(ImportedNodeInterface, self).__init__(node, iface.index)
def destroy(self): # override: restore as much as possible def destroy(self): # override: restore as much as possible
if self._slave: if not self._slave:
return
if self.index in self._slave.get_if_data(): if self.index in self._slave.get_if_data():
if self._migrate: if self._migrate:
self._slave.set_if(self._original_state)
else:
self._slave.change_netns(self.index, os.getpid()) self._slave.change_netns(self.index, os.getpid())
if not self._migrate: else:
# else, assume it is in the main name space self._slave.set_if(self._original_state)
if self._migrate:
# else, assume it is already in the main name space
netns.iproute.set_if(self._original_state) netns.iproute.set_if(self._original_state)
self._slave = None self._slave = None
......
...@@ -120,7 +120,7 @@ class Node(object): ...@@ -120,7 +120,7 @@ class Node(object):
for i in ifaces: for i in ifaces:
if i not in self._interfaces: if i not in self._interfaces:
iface = netns.interface.ImportedNodeInterface(self, i, iface = netns.interface.ImportedNodeInterface(self, i,
migrate = True) migrate = False)
self._auto_interfaces.append(iface) # keep it referenced! self._auto_interfaces.append(iface) # keep it referenced!
self._interfaces[i] = iface self._interfaces[i] = iface
# by the way, clean up _interfaces # by the way, clean up _interfaces
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment