diff options
author | Marcel Enguehard <mengueha+fdio@cisco.com> | 2017-05-23 10:50:17 +0200 |
---|---|---|
committer | Marcel Enguehard <mengueha+fdio@cisco.com> | 2017-05-23 08:57:12 +0000 |
commit | be0b435d307173598c30fcacc421b17112137099 (patch) | |
tree | ed8aae7eef796eb7381d21937b095a036733789a /vicn/resource/ip_assignment.py | |
parent | 895a6328d6e64948ed213e8fbbb3ab15aca0df43 (diff) |
Introduced groups + lxd profiles + diverted control network handling to lxd + misc bug fixes
Change-Id: Iae26bc2994ac9704dde7dfa8fbe4be1b74cf9e6f
Signed-off-by: Marcel Enguehard <mengueha+fdio@cisco.com>
Diffstat (limited to 'vicn/resource/ip_assignment.py')
-rw-r--r-- | vicn/resource/ip_assignment.py | 37 |
1 files changed, 36 insertions, 1 deletions
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' |