Merge "Automatically call MuranoPL initialize/destroy methods"

This commit is contained in:
Jenkins 2014-06-11 19:19:48 +00:00 committed by Gerrit Code Review
commit 894f4595cc
5 changed files with 20 additions and 9 deletions

View File

@ -4,3 +4,4 @@ Name: Object
Methods: Methods:
initialize: initialize:
destroy:

View File

@ -83,6 +83,12 @@ class MuranoDslExecutor(object):
raise Exception('{0} is not an action'.format(method.name)) raise Exception('{0} is not an action'.format(method.name))
# TODO (slagun): check method accessibility from murano_class # TODO (slagun): check method accessibility from murano_class
if not external_call and is_special_method:
LOG.deprecated('initialize/destroy methods are called '
'automatically by engine. This call is no-op '
'and will become exception in the future')
return None
# restore this from upcast object (no change if there was no upcast) # restore this from upcast object (no change if there was no upcast)
this = this.real_this this = this.real_this
arguments_scheme = method.arguments_scheme arguments_scheme = method.arguments_scheme

View File

@ -130,14 +130,16 @@ class MuranoClass(object):
return result[0] return result[0]
def find_all_methods(self, name): def find_all_methods(self, name):
#resolved_name = self._namespace_resolver.resolve_name(name, self.name) result = []
if name in self._methods: queue = collections.deque([self])
return [self.methods[name]] while queue:
if not self._parents: c = queue.popleft()
return [] if name in c.methods:
return list(reduce( method = c.methods[name]
lambda x, y: x + [t for t in y if t not in x], if method not in result:
[p.find_all_methods(name) for p in self._parents])) result.append(method)
queue.extend(c.parents)
return result
def find_property(self, name): def find_property(self, name):
types = collections.deque([self]) types = collections.deque([self])

View File

@ -109,7 +109,8 @@ class MuranoMethod(object):
return macros.MethodBlock(body) return macros.MethodBlock(body)
def __repr__(self): def __repr__(self):
return 'MuranoMethod({0})'.format(self.name) return 'MuranoMethod({0}::{1})'.format(
self.murano_class.name, self.name)
def invoke(self, executor, this, parameters): def invoke(self, executor, this, parameters):
return self.murano_class.invoke(self.name, executor, this, parameters) return self.murano_class.invoke(self.name, executor, this, parameters)

View File

@ -88,6 +88,7 @@ class ObjectStore(object):
if not self.initializing: if not self.initializing:
executor = helpers.get_executor(context) executor = helpers.get_executor(context)
methods = obj.type.find_all_methods('initialize') methods = obj.type.find_all_methods('initialize')
methods.reverse()
for method in methods: for method in methods:
method.invoke(executor, obj, {}) method.invoke(executor, obj, {})
return obj return obj