Source code for heat.engine.parent_rsrc
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
import weakref
from heat.objects import resource as resource_object
[docs]class ParentResourceProxy(object):
    """Proxy for the TemplateResource that owns a provider stack.
    This is an interface through which the Fn::ResourceFacade/resource_facade
    intrinsic functions in a stack can access data about the TemplateResource
    in the parent stack for which it was created.
    This API can be considered stable by third-party Function plugins, and no
    part of it should be changed or removed without an appropriate deprecation
    process.
    """
    def __new__(cls, context, parent_resource_name, parent_stack_id):
        if parent_resource_name is None:
            return None
        return super(ParentResourceProxy, cls).__new__(cls)
    def __init__(self, context, parent_resource_name, parent_stack_id):
        self._context = context
        self.name = parent_resource_name
        self._stack_id = parent_stack_id
        self._stack_ref = None
        self._parent_stack = None
    def _stack(self):
        if self._stack_ref is not None:
            stk = self._stack_ref()
            if stk is not None:
                return stk
        assert self._stack_id is not None, "Must provide parent stack or ID"
        from heat.engine import stack
        self._parent_stack = stack.Stack.load(self._context,
                                              stack_id=self._stack_id)
        self._stack_ref = weakref.ref(self._parent_stack)
        return self._parent_stack
    @property
    def t(self):
        """The resource definition."""
        stk = self._stack()
        return stk.t.resource_definitions(stk)[self.name] 
[docs]def use_parent_stack(parent_proxy, stack):
    parent_proxy._stack_ref = weakref.ref(stack)
    parent_proxy._parent_stack = None