From be0b435d307173598c30fcacc421b17112137099 Mon Sep 17 00:00:00 2001 From: Marcel Enguehard Date: Tue, 23 May 2017 10:50:17 +0200 Subject: Introduced groups + lxd profiles + diverted control network handling to lxd + misc bug fixes Change-Id: Iae26bc2994ac9704dde7dfa8fbe4be1b74cf9e6f Signed-off-by: Marcel Enguehard --- vicn/resource/ip_assignment.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'vicn/resource/ip_assignment.py') diff --git a/vicn/resource/ip_assignment.py b/vicn/resource/ip_assignment.py index 7553f4ff..62a32389 100644 --- a/vicn/resource/ip_assignment.py +++ b/vicn/resource/ip_assignment.py @@ -16,6 +16,8 @@ # limitations under the License. # +import math + from vicn.core.resource import Resource from netmodel.model.type import String from vicn.core.attribute import Attribute @@ -60,9 +62,42 @@ class IpAssignment(Resource): self._assigned_addresses[obj] = ret return ret + @inline_task + def __get__(self): + raise ResourceNotFound + + @inline_task + def __create__(self): + # XXX code from Channel.__create__, until Events are properly implemented. + # Iterate on channels for allocate IP addresses + for group in self.groups: + for channel in group.iter_by_type_str('channel'): + interfaces = sorted(channel.interfaces, key = lambda x : x.device_name) + if not interfaces: + continue + + min_prefix_size = math.ceil(math.log(len(channel.interfaces), 2)) + prefix_size = min(self.DEFAULT_PREFIX_SIZE, self.MAX_PREFIX_SIZE - min_prefix_size) + prefix = iter(self.get_prefix(channel, prefix_size)) + + for interface in interfaces: + ip = next(prefix) + print('attribute ip=', ip) + setattr(interface, self.ATTR_ADDRESS, ip) + setattr(interface, self.ATTR_PREFIX, prefix_size) + + __delete__ = None + class Ipv6Assignment(IpAssignment): PrefixClass = Inet6Prefix - + DEFAULT_PREFIX_SIZE = 64 + MAX_PREFIX_SIZE = 128 + ATTR_ADDRESS = 'ip6_address' + ATTR_PREFIX = 'ip6_prefix' class Ipv4Assignment(IpAssignment): PrefixClass = Inet4Prefix + DEFAULT_PREFIX_SIZE = 32 + MAX_PREFIX_SIZE = 32 + ATTR_ADDRESS = 'ip4_address' + ATTR_PREFIX = 'ip4_prefix' -- cgit 1.2.3-korg