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/core/sa_collections.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/core/sa_collections.py')
-rw-r--r-- | vicn/core/sa_collections.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/vicn/core/sa_collections.py b/vicn/core/sa_collections.py index e627caa5..a4a24f85 100644 --- a/vicn/core/sa_collections.py +++ b/vicn/core/sa_collections.py @@ -12,8 +12,9 @@ import logging -from vicn.core.sa_compat import py2k from vicn.core.exception import VICNListException +from vicn.core.sa_compat import py2k +from vicn.core.state import UUID log = logging.getLogger(__name__) @@ -29,7 +30,7 @@ def _list_decorators(): try: item = self._attribute.do_list_add(self._instance, item) fn(self, item) - except VICNListException as e: + except VICNListException as e: pass _tidy(append) return append @@ -121,7 +122,7 @@ def _list_decorators(): try: self._attribute.do_list_remove(self._instance, item) except : has_except = True - if not has_except: + if not has_except: fn(self, index) _tidy(__delitem__) return __delitem__ @@ -180,7 +181,7 @@ def _list_decorators(): self._attribute.do_list_remove(self._instance, item) item = fn(self, index) return item - except : return None + except : return None _tidy(pop) return pop @@ -230,13 +231,27 @@ def _instrument_list(cls): # inspired by sqlalchemy for method, decorator in _list_decorators().items(): fn = getattr(cls, method, None) - if fn: + if fn: #if (fn and method not in methods and # not hasattr(fn, '_sa_instrumented')): setattr(cls, method, decorator(fn)) class InstrumentedList(list): + @classmethod + def from_list(cls, value, instance, attribute): + lst = list() + if value: + for x in value: + if isinstance(x, UUID): + x = instance.from_uuid(x) + lst.append(x) + # Having a class method is important for inheritance + value = cls(lst) + value._attribute = attribute + value._instance = instance + return value + def __contains__(self, key): from vicn.core.resource import Resource if isinstance(key, Resource): |