Browse Source

Automatically call MuranoPL initialize/destroy methods

Implements: blueprint muranopl-auto-call-init-destroy

Change-Id: I58f815e7b1ab8301aad101688daae673dd199141
changes/79/98579/3
Stan Lagun 8 years ago
parent
commit
e87d4d35dd
  1. 1
      meta/io.murano/Classes/Object.yaml
  2. 6
      murano/dsl/executor.py
  3. 18
      murano/dsl/murano_class.py
  4. 3
      murano/dsl/murano_method.py
  5. 1
      murano/dsl/object_store.py

1
meta/io.murano/Classes/Object.yaml

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

6
murano/dsl/executor.py

@ -83,6 +83,12 @@ class MuranoDslExecutor(object):
raise Exception('{0} is not an action'.format(method.name))
# 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)
this = this.real_this
arguments_scheme = method.arguments_scheme

18
murano/dsl/murano_class.py

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

3
murano/dsl/murano_method.py

@ -109,7 +109,8 @@ class MuranoMethod(object):
return macros.MethodBlock(body)
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):
return self.murano_class.invoke(self.name, executor, this, parameters)

1
murano/dsl/object_store.py

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

Loading…
Cancel
Save