summaryrefslogtreecommitdiff
path: root/heat/engine/resources/aws/cfn/wait_condition_handle.py
blob: 6d665dad2e6f998b83701bcc2f2d62920c420472 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#
#    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.

from heat.engine.resources import signal_responder
from heat.engine.resources import wait_condition as wc_base
from heat.engine import support


class WaitConditionHandle(wc_base.BaseWaitConditionHandle):
    """AWS WaitConditionHandle resource.

    the main point of this class is to :
    have no dependencies (so the instance can reference it)
    generate a unique url (to be returned in the reference)
    then the cfn-signal will use this url to post to and
    WaitCondition will poll it to see if has been written to.
    """

    support_status = support.SupportStatus(version='2014.1')

    METADATA_KEYS = (
        DATA, REASON, STATUS, UNIQUE_ID
    ) = (
        'Data', 'Reason', 'Status', 'UniqueId'
    )

    def get_reference_id(self):
        if self.resource_id:
            wc = signal_responder.WAITCONDITION
            return str(self._get_ec2_signed_url(signal_type=wc))
        else:
            return str(self.name)

    def metadata_update(self, new_metadata=None):
        """DEPRECATED. Should use handle_signal instead."""
        self.handle_signal(details=new_metadata)

    def handle_signal(self, details=None):
        """Validate and update the resource metadata.

        metadata must use the following format::

            {
                "Status" : "Status (must be SUCCESS or FAILURE)",
                "UniqueId" : "Some ID, should be unique for Count>1",
                "Data" : "Arbitrary Data",
                "Reason" : "Reason String"
            }
        """
        if details is None:
            return
        return super(WaitConditionHandle, self).handle_signal(details)


def resource_mapping():
    return {
        'AWS::CloudFormation::WaitConditionHandle': WaitConditionHandle,
    }