View | Details | Raw Unified | Return to bug 51368
Collapse All | Expand All

(-)a/base/univention-config-registry/debian/control (+2 lines)
 Lines 11-16   Build-Depends: Link Here 
11
 libunivention-debug-dev (>= 5.0.6-1),
11
 libunivention-debug-dev (>= 5.0.6-1),
12
 python-all,
12
 python-all,
13
 python-ipaddr,
13
 python-ipaddr,
14
 python-ipaddress,
14
 python-mock,
15
 python-mock,
15
 python-pytest,
16
 python-pytest,
16
 python-pytest-cov,
17
 python-pytest-cov,
 Lines 116-121   Architecture: all Link Here 
116
Depends:
117
Depends:
117
 ifupdown,
118
 ifupdown,
118
 python-ipaddr,
119
 python-ipaddr,
120
 python-ipaddress,
119
 python-six,
121
 python-six,
120
 python-univention-debhelper,
122
 python-univention-debhelper,
121
 python-univention-namespace,
123
 python-univention-namespace,
(-)a/base/univention-config-registry/python/univention/config_registry/interfaces.py (-9 / +27 lines)
 Lines 128-133   RE_ALNUM = re.compile(r'([0-9]+)|([^0-9]+)') Link Here 
128
class _Iface(dict):
128
class _Iface(dict):
129
	"""Single network interface."""
129
	"""Single network interface."""
130
130
131
	IPv4Address = IPv4Address
132
	IPv6Address = IPv6Address
133
	IPv4Interface = IPv4Interface
134
	IPv6Interface = IPv6Interface
135
131
	def __init__(self, *args, **kwargs):
136
	def __init__(self, *args, **kwargs):
132
		dict.__init__(self, *args, **kwargs)
137
		dict.__init__(self, *args, **kwargs)
133
		self.ipv6_names = set()
138
		self.ipv6_names = set()
 Lines 162-188   class _Iface(dict): Link Here 
162
	def network(self):
167
	def network(self):
163
		# type: () -> IPv4Address
168
		# type: () -> IPv4Address
164
		"""Return network address."""
169
		"""Return network address."""
165
		return IPv4Address(u'%(network)s' % self)
170
		return self.IPv4Address(u'%(network)s' % self)
166
171
167
	@property  # type: ignore
172
	@property  # type: ignore
168
	@forgiving_addr
173
	@forgiving_addr
169
	def broadcast(self):
174
	def broadcast(self):
170
		# type: () -> IPv4Address
175
		# type: () -> IPv4Address
171
		"""Return broadcast address."""
176
		"""Return broadcast address."""
172
		return IPv4Address(u'%(broadcast)s' % self)
177
		return self.IPv4Address(u'%(broadcast)s' % self)
173
178
174
	@forgiving_addr
179
	@forgiving_addr
175
	def ipv4_address(self):
180
	def ipv4_address(self):
176
		# type: () -> IPv4Interface
181
		# type: () -> IPv4Interface
177
		"""Return IPv4 address."""
182
		"""Return IPv4 address."""
178
		return IPv4Interface(u'%(address)s/%(netmask)s' % self)
183
		return self.IPv4Interface(u'%(address)s/%(netmask)s' % self)
179
184
180
	@forgiving_addr
185
	@forgiving_addr
181
	def ipv6_address(self, name='default'):
186
	def ipv6_address(self, name='default'):
182
		# type: (str) -> IPv6Interface
187
		# type: (str) -> IPv6Interface
183
		"""Return IPv6 address."""
188
		"""Return IPv6 address."""
184
		key = u'%%(ipv6/%s/address)s/%%(ipv6/%s/prefix)s' % (name, name)
189
		key = u'%%(ipv6/%s/address)s/%%(ipv6/%s/prefix)s' % (name, name)
185
		return IPv6Interface(key % self)
190
		return self.IPv6Interface(key % self)
186
191
187
	@property
192
	@property
188
	def routes(self):
193
	def routes(self):
 Lines 204-209   class _Iface(dict): Link Here 
204
			yield v
209
			yield v
205
210
206
211
212
class _NewIface(_Iface):
213
214
	from ipaddress import IPv4Address, IPv6Address, IPv4Interface, IPv6Interface
215
216
207
class VengefulConfigRegistry(ConfigRegistry):
217
class VengefulConfigRegistry(ConfigRegistry):
208
	"""
218
	"""
209
	Instance wrapper for Config Registry throwing exceptions.
219
	Instance wrapper for Config Registry throwing exceptions.
 Lines 244-263   class Interfaces(object): Link Here 
244
	Handle network interfaces configured by UCR.
254
	Handle network interfaces configured by UCR.
245
255
246
	:param ucr: UCR instance.
256
	:param ucr: UCR instance.
257
	:param use_python3_api bool: Whether to use the module :py:mod:`ipaddress` from Python 3 or the legacy module :py:mod:`ipaddr` for Python 2 as the interface.
258
259
	.. deprecated:: 5.0
260
		`use_python3_api` is only relevant for Python 2 code.
247
	"""
261
	"""
248
262
249
	def __init__(self, ucr=None):
263
	def __init__(self, ucr=None, use_python3_api=six.PY3):
250
		# type: (ConfigRegistry) -> None
264
		# type: (ConfigRegistry, bool) -> None
251
		if ucr is None:
265
		if ucr is None:
252
			ucr = ConfigRegistry()
266
			ucr = ConfigRegistry()
253
			ucr.load()
267
			ucr.load()
254
		if isinstance(ucr, ConfigRegistry):
268
		if isinstance(ucr, ConfigRegistry):
255
			ucr = VengefulConfigRegistry(ucr)
269
			ucr = VengefulConfigRegistry(ucr)
256
270
271
		IPv4AddressClass = _NewIface.IPv4Address if use_python3_api else IPv4Address
272
		IPv6AddressClass = _NewIface.IPv6Address if use_python3_api else IPv6Address
273
		IfaceClass = _NewIface if use_python3_api else _Iface
274
257
		self.handler = ucr.get('interfaces/handler', 'ifplugd')
275
		self.handler = ucr.get('interfaces/handler', 'ifplugd')
258
		self.primary = ucr.get('interfaces/primary', 'eth0')
276
		self.primary = ucr.get('interfaces/primary', 'eth0')
259
		try:
277
		try:
260
			self.ipv4_gateway = IPv4Address(ucr['gateway'])
278
			self.ipv4_gateway = IPv4AddressClass(ucr['gateway'])
261
		except KeyError:
279
		except KeyError:
262
			self.ipv4_gateway = None
280
			self.ipv4_gateway = None
263
		except ValueError:
281
		except ValueError:
 Lines 270-276   class Interfaces(object): Link Here 
270
			parts = ucr['ipv6/gateway'].rsplit('%', 1)
288
			parts = ucr['ipv6/gateway'].rsplit('%', 1)
271
			gateway = parts.pop(0)
289
			gateway = parts.pop(0)
272
			zone_index = parts[0] if parts else None
290
			zone_index = parts[0] if parts else None
273
			self.ipv6_gateway = IPv6Address(gateway)
291
			self.ipv6_gateway = IPv6AddressClass(gateway)
274
			self.ipv6_gateway_zone_index = zone_index
292
			self.ipv6_gateway_zone_index = zone_index
275
		except KeyError:
293
		except KeyError:
276
			self.ipv6_gateway = None
294
			self.ipv6_gateway = None
 Lines 287-293   class Interfaces(object): Link Here 
287
			if not match:
305
			if not match:
288
				continue
306
				continue
289
			iface, subkey, ipv6_name = match.groups()
307
			iface, subkey, ipv6_name = match.groups()
290
			data = self._all_interfaces.setdefault(iface, _Iface(name=iface))
308
			data = self._all_interfaces.setdefault(iface, IfaceClass(name=iface))
291
			data[subkey] = value
309
			data[subkey] = value
292
			if ipv6_name:
310
			if ipv6_name:
293
				data.ipv6_names.add(ipv6_name)
311
				data.ipv6_names.add(ipv6_name)

Return to bug 51368