25 class _IpMixin(context_module.ContextConsumer):
27 raise NotImplementedError
32 return self.context.shared_registry.fetch(IPDBRoot)
37 return self.context.shared_registry.fetch(NetworkNamespace)
40 class Abstract(context_module.ContextConsumer):
55 raise NotImplementedError
61 raise NotImplementedError
75 with self.
get_ipdb().interfaces[name]
as iface:
84 iface = self.
get_ipdb().interfaces[name].ro
92 with self.
get_ipdb().interfaces[name]
as iface:
102 with self.
get_ipdb().interfaces[name]
as iface:
103 for addr
in tuple(iface.ipaddr):
109 klass, self.context.iface)
115 ip = self.context.shared_registry.fetch(
type(self), remove=
True)
124 instance = pyroute2.IPDB()
125 self.context.shared_registry.add(
type(self), instance)
130 name = self.context.make_network_namespace_name()
133 pyroute2.netns.create(name)
135 if e.errno == errno.EEXIST:
142 name = self.context.make_network_namespace_name()
144 pyroute2.netns.remove(name)
149 name = self.context.make_network_namespace_name()
150 nsip = pyroute2.IPDB(nl=pyroute2.NetNS(name))
151 self.context.shared_registry.add(
type(self), nsip)
154 GWDescriptor = collections.namedtuple(
'GWDescription', (
'root',
'ns'))
166 with self.
get_ipdb().
create(kind=
'veth', ifname=left, peer=right):
169 except pyroute2.CreateException:
171 except Exception
as e:
180 ns_name = self.context.make_network_namespace_name()
189 with ip.interfaces[right]
as iface:
190 iface.net_ns_fd = ns_name
197 nsip = self.context.shared_registry.fetch(NetworkNamespace)
199 with nsip.interfaces[right]
as iface:
207 with ip.interfaces[left].ro
as iface_left:
208 with nsip.interfaces[self.
ns_gw_name].ro
as iface_right:
209 ok = iface_left[
'kind'] == iface_right[
'kind'] ==
'veth' 210 ok = ok
and iface_left[
'peer'] == right
215 'is not a veth pair created in previous ' 217 except KeyError
as e:
220 self.context.shared_registry.add(
224 base = self.context.make_veth_base_name()
225 return (
'.'.join((base, tail))
for tail
in 'AB')
230 name = self.context.make_bridge_name()
234 except pyroute2.CreateException:
238 self.
iface_drop(self.context.make_bridge_name())
241 name = self.context.make_bridge_name()
242 veth = self.context.shared_registry.fetch(VEthPair)
245 self.context.iface.index,
250 with self.
get_ipdb().interfaces[name]
as iface:
252 ports = set(iface.ports)
253 for port
in ports - need_ports:
255 for port
in need_ports - ports:
261 klass, name,
'interface not found')
272 class TargetIfaceCleanUp(RootIPDBMixin, _IfaceManager, _ConfigureMixin):
279 veth = self.context.shared_registry.fetch(VEthPair)
283 with self.
get_ipdb().interfaces[self.context.iface.index]
as iface:
284 iface.add_port(veth_index)
289 type(self), self.context.iface.name,
'interface not found')
301 veth = self.context.shared_registry.fetch(VEthPair)
307 veth = self.context.shared_registry.fetch(VEthPair)
321 keep_iface_kinds = {
None,
'sit'}
323 for name
in tuple(self.
get_ipdb().interfaces):
324 if not isinstance(name, int):
326 if name
in keep_iface:
333 except pyroute2.NetlinkError
as e:
334 if e.code != errno.EOPNOTSUPP:
340 self.
iface_set_up(self.context.shared_registry.fetch(VEthPair).ns)
def release_acquire(self)
def iface_get_info(self, name)
def cleanup_gateway_iface(self, veth)
def iface_set_up(self, name)
def iface_drop_all_addresses(self, name)
def iface_drop(self, name)
def drop_all_ifaces(self, veth)
def __init__(self, context)