U
    W+d                     @   sp   d dl Z d dlmZmZmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ G dd	 d	e
ZdS )
    N)StackStackSummary
StackEvent)StackResourceStackResourceSummary)Template)AWSQueryConnection)
RegionInfo)jsonc                       s  e Zd ZdZejdddZejdddZejdddZ	d	Z
d7 fdd	Zdd Zdd Zd8ddZdd Zd9ddZd:ddZdd Zd;dd Zd!d" Zd<d#d$Zd=d%d&Zd'd( Zd>d)d*Zd?d+d,Zd@d-d.ZdAd/d0ZdBd1d2Zd3d4 ZdCd5d6Z  ZS )DCloudFormationConnectionaL  
    AWS CloudFormation
    AWS CloudFormation enables you to create and manage AWS
    infrastructure deployments predictably and repeatedly. AWS
    CloudFormation helps you leverage AWS products such as Amazon EC2,
    EBS, Amazon SNS, ELB, and Auto Scaling to build highly-reliable,
    highly scalable, cost effective applications without worrying
    about creating and configuring the underlying AWS infrastructure.

    With AWS CloudFormation, you declare all of your resources and
    dependencies in a template file. The template defines a collection
    of resources as a single unit called a stack. AWS CloudFormation
    creates and deletes all member resources of the stack together and
    manages all dependencies between the resources for you.

    For more information about this product, go to the `CloudFormation
    Product Page`_.

    Amazon CloudFormation makes use of other AWS products. If you need
    additional technical information about a specific AWS product, you
    can find the product's technical documentation at
    `http://aws.amazon.com/documentation/`_.
    ZBotoZcfn_versionz
2010-05-15Zcfn_region_namez	us-east-1Zcfn_region_endpointz&cloudformation.us-east-1.amazonaws.com)ZCREATE_IN_PROGRESSZCREATE_FAILEDZCREATE_COMPLETEZROLLBACK_IN_PROGRESSZROLLBACK_FAILEDZROLLBACK_COMPLETEZDELETE_IN_PROGRESSZDELETE_FAILEDZDELETE_COMPLETEZUPDATE_IN_PROGRESSZ#UPDATE_COMPLETE_CLEANUP_IN_PROGRESSZUPDATE_COMPLETEZUPDATE_ROLLBACK_IN_PROGRESSZUPDATE_ROLLBACK_FAILEDZ,UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESSZUPDATE_ROLLBACK_COMPLETENTr   /c                    sR   |st | | j| jt}|| _tt| j||||||||| jj|	|
||||d d S )N)validate_certsprofile_name)r	   DefaultRegionNameDefaultRegionEndpointr   regionsuper__init__Zendpoint)selfZaws_access_key_idZaws_secret_access_keyZ	is_secureportproxyZ
proxy_portZ
proxy_userZ
proxy_passdebugZhttps_connection_factoryr   path	converterZsecurity_tokenr   r   	__class__ B/tmp/pip-unpacked-wheel-dlxw5sjy/boto/cloudformation/connection.pyr   G   s,           z!CloudFormationConnection.__init__c                 C   s   dgS )Nzhmac-v4r   )r   r   r   r   _required_auth_capability[   s    z2CloudFormationConnection._required_auth_capabilityc                 C   s   t |}ddd| S )Ntruefalse)TF)bool)r   vr   r   r   encode_bool^   s    z$CloudFormationConnection.encode_boolc                 C   s  d||  |d}|r||d< |r*||d< |dk	r@|  ||d< |rT|rTtjd |rt|dkrt|D ]l\}}|dd	 \}}t|d	kr|d	 nd
}||d|d  < |r|  ||d|d  < ql||d|d  < ql|rt|D ]\}}||d|d  < q|rDt| D ].\}\}}||d|d  < ||d|d  < q|rft|dkrf| ||d |rxt||d< |dk	rt	|
 |d< |	dk	r|	|d< |
dk	r|
|d< |dk	r||d< |dk	r||d< |dk	r||d< |S )a  
        Helper that creates JSON parameters needed by a Stack Create or
        Stack Update call.

        :type stack_name: string
        :param stack_name:
        The name associated with the stack. The name must be unique within your
            AWS account.

        Must contain only alphanumeric characters (case sensitive) and start
            with an alpha character. Maximum length of the name is 255
            characters.

        :type template_body: string
        :param template_body: Structure containing the template body. (For more
            information, go to `Template Anatomy`_ in the AWS CloudFormation
            User Guide.)
        Conditional: You must pass either `UsePreviousTemplate` or one of
            `TemplateBody` or `TemplateUrl`. If both `TemplateBody` and
            `TemplateUrl` are passed, only `TemplateBody` is used.
            `TemplateBody`.

        :type template_url: string
        :param template_url: Location of file containing the template body. The
            URL must point to a template (max size: 307,200 bytes) located in
            an S3 bucket in the same region as the stack. For more information,
            go to the `Template Anatomy`_ in the AWS CloudFormation User Guide.
        Conditional: You must pass either `UsePreviousTemplate` or one of
            `TemplateBody` or `TemplateUrl`. If both `TemplateBody` and
            `TemplateUrl` are passed, only `TemplateBody` is used.
            `TemplateBody`.

        :type parameters: list
        :param parameters: A list of key/value tuples that specify input
            parameters for the stack. A 3-tuple (key, value, bool) may be used to
            specify the `UsePreviousValue` option.

        :type disable_rollback: boolean
        :param disable_rollback: Set to `True` to disable rollback of the stack
            if stack creation failed. You can specify either `DisableRollback`
            or `OnFailure`, but not both.
        Default: `False`

        :type timeout_in_minutes: integer
        :param timeout_in_minutes: The amount of time that can pass before the
            stack status becomes CREATE_FAILED; if `DisableRollback` is not set
            or is set to `False`, the stack will be rolled back.

        :type notification_arns: list
        :param notification_arns: The Simple Notification Service (SNS) topic
            ARNs to publish stack related events. You can find your SNS topic
            ARNs using the `SNS console`_ or your Command Line Interface (CLI).

        :type capabilities: list
        :param capabilities: The list of capabilities that you want to allow in
            the stack. If your template contains certain resources, you must
            specify the CAPABILITY_IAM value for this parameter; otherwise,
            this action returns an InsufficientCapabilities error. The
            following resources require you to specify the capabilities
            parameter: `AWS::CloudFormation::Stack`_, `AWS::IAM::AccessKey`_,
            `AWS::IAM::Group`_, `AWS::IAM::InstanceProfile`_,
            `AWS::IAM::Policy`_, `AWS::IAM::Role`_, `AWS::IAM::User`_, and
            `AWS::IAM::UserToGroupAddition`_.

        :type on_failure: string
        :param on_failure: Determines what action will be taken if stack
            creation fails. This must be one of: DO_NOTHING, ROLLBACK, or
            DELETE. You can specify either `OnFailure` or `DisableRollback`,
            but not both.
        Default: `ROLLBACK`

        :type stack_policy_body: string
        :param stack_policy_body: Structure containing the stack policy body.
            (For more information, go to ` Prevent Updates to Stack Resources`_
            in the AWS CloudFormation User Guide.)
        If you pass `StackPolicyBody` and `StackPolicyURL`, only
            `StackPolicyBody` is used.

        :type stack_policy_url: string
        :param stack_policy_url: Location of a file containing the stack
            policy. The URL must point to a policy (max size: 16KB) located in
            an S3 bucket in the same region as the stack. If you pass
            `StackPolicyBody` and `StackPolicyURL`, only `StackPolicyBody` is
            used.

        :type tags: list
        :param tags: A set of user-defined `Tags` to associate with this stack,
            represented by key/value pairs. Tags defined for the stack are
            propagated to EC2 resources that are created as part of the stack.
            A maximum number of 10 tags can be specified.

        :type use_previous_template: boolean
        :param use_previous_template: Set to `True` to use the previous
            template instead of uploading a new one via `TemplateBody` or
            `TemplateURL`.
        Conditional: You must pass either `UsePreviousTemplate` or one of
            `TemplateBody` or `TemplateUrl`.

        :type stack_policy_during_update_body: string
        :param stack_policy_during_update_body: Structure containing the
            temporary overriding stack policy body. If you pass
            `StackPolicyDuringUpdateBody` and `StackPolicyDuringUpdateURL`,
            only `StackPolicyDuringUpdateBody` is used.
        If you want to update protected resources, specify a temporary
            overriding stack policy during this update. If you do not specify a
            stack policy, the current policy that associated with the stack
            will be used.

        :type stack_policy_during_update_url: string
        :param stack_policy_during_update_url: Location of a file containing
            the temporary overriding stack policy. The URL must point to a
            policy (max size: 16KB) located in an S3 bucket in the same region
            as the stack. If you pass `StackPolicyDuringUpdateBody` and
            `StackPolicyDuringUpdateURL`, only `StackPolicyDuringUpdateBody` is
            used.
        If you want to update protected resources, specify a temporary
            overriding stack policy during this update. If you do not specify a
            stack policy, the current policy that is associated with the stack
            will be used.

        :rtype: dict
        :return: JSON parameters represented as a Python dict.
        JSON)ContentType	StackNameDisableRollbackTemplateBodyTemplateURLNZUsePreviousTemplate`If both TemplateBody and TemplateURL are specified, only TemplateBody will be honored by the APIr      F!Parameters.member.%d.ParameterKey   z%Parameters.member.%d.UsePreviousValue#Parameters.member.%d.ParameterValuezCapabilities.member.%dzTags.member.%d.KeyzTags.member.%d.ValuezNotificationARNs.memberZTimeoutInMinutesr'   Z	OnFailureStackPolicyBodyStackPolicyURLZStackPolicyDuringUpdateBodyZStackPolicyDuringUpdateURL)r#   botologwarninglen	enumerateitemsbuild_list_paramsintstrlower)r   
stack_nametemplate_bodytemplate_url
parametersdisable_rollbacktimeout_in_minutesnotification_arnscapabilities
on_failurestack_policy_bodystack_policy_urltagsuse_previous_templatestack_policy_during_update_bodystack_policy_during_update_urlparamsiZparameter_tuplekeyvalueZuse_previousr   r   r   _build_create_or_update_paramsb   sl     







z7CloudFormationConnection._build_create_or_update_paramsc                 C   sv   |  ||||}| d}|jdkr6t|}|S tjd|j|j	f  tjd|  | j
|j|j	|ddS )a  
        Do a request via ``self.make_request`` and parse the JSON response.

        :type call: string
        :param call: Call name, e.g. ``CreateStack``

        :type params: dict
        :param params: Dictionary of call parameters

        :type path: string
        :param path: Server path

        :type method: string
        :param method: HTTP method to use

        :rtype: dict
        :return: Parsed JSON response data
        zutf-8   z%s %sz%s)bodyN)Zmake_requestreaddecodestatusr
   loadsr1   r2   errorreasonResponseError)r   callrJ   r   methodresponserP   r   r   r   _do_request  s    

z$CloudFormationConnection._do_requestc                 C   s@   |  |||||||||
|||	}| d|dd}|d d d S )aO  
        Creates a stack as specified in the template. After the call
        completes successfully, the stack creation starts. You can
        check the status of the stack via the DescribeStacks API.
        Currently, the limit for stacks is 20 stacks per account per
        region.

        :type stack_name: string
        :param stack_name:
        The name associated with the stack. The name must be unique within your
            AWS account.

        Must contain only alphanumeric characters (case sensitive) and start
            with an alpha character. Maximum length of the name is 255
            characters.

        :type template_body: string
        :param template_body: Structure containing the template body. (For more
            information, go to `Template Anatomy`_ in the AWS CloudFormation
            User Guide.)
        Conditional: You must pass `TemplateBody` or `TemplateURL`. If both are
            passed, only `TemplateBody` is used.

        :type template_url: string
        :param template_url: Location of file containing the template body. The
            URL must point to a template (max size: 307,200 bytes) located in
            an S3 bucket in the same region as the stack. For more information,
            go to the `Template Anatomy`_ in the AWS CloudFormation User Guide.
        Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
            passed, only `TemplateBody` is used.

        :type parameters: list
        :param parameters: A list of key/value tuples that specify input
            parameters for the stack.

        :type disable_rollback: boolean
        :param disable_rollback: Set to `True` to disable rollback of the stack
            if stack creation failed. You can specify either `DisableRollback`
            or `OnFailure`, but not both.
        Default: `False`

        :type timeout_in_minutes: integer
        :param timeout_in_minutes: The amount of time that can pass before the
            stack status becomes CREATE_FAILED; if `DisableRollback` is not set
            or is set to `False`, the stack will be rolled back.

        :type notification_arns: list
        :param notification_arns: The Simple Notification Service (SNS) topic
            ARNs to publish stack related events. You can find your SNS topic
            ARNs using the `SNS console`_ or your Command Line Interface (CLI).

        :type capabilities: list
        :param capabilities: The list of capabilities that you want to allow in
            the stack. If your template contains certain resources, you must
            specify the CAPABILITY_IAM value for this parameter; otherwise,
            this action returns an InsufficientCapabilities error. The
            following resources require you to specify the capabilities
            parameter: `AWS::CloudFormation::Stack`_, `AWS::IAM::AccessKey`_,
            `AWS::IAM::Group`_, `AWS::IAM::InstanceProfile`_,
            `AWS::IAM::Policy`_, `AWS::IAM::Role`_, `AWS::IAM::User`_, and
            `AWS::IAM::UserToGroupAddition`_.

        :type on_failure: string
        :param on_failure: Determines what action will be taken if stack
            creation fails. This must be one of: DO_NOTHING, ROLLBACK, or
            DELETE. You can specify either `OnFailure` or `DisableRollback`,
            but not both.
        Default: `ROLLBACK`

        :type stack_policy_body: string
        :param stack_policy_body: Structure containing the stack policy body.
            (For more information, go to ` Prevent Updates to Stack Resources`_
            in the AWS CloudFormation User Guide.)
        If you pass `StackPolicyBody` and `StackPolicyURL`, only
            `StackPolicyBody` is used.

        :type stack_policy_url: string
        :param stack_policy_url: Location of a file containing the stack
            policy. The URL must point to a policy (max size: 16KB) located in
            an S3 bucket in the same region as the stack. If you pass
            `StackPolicyBody` and `StackPolicyURL`, only `StackPolicyBody` is
            used.

        :type tags: dict
        :param tags: A set of user-defined `Tags` to associate with this stack,
            represented by key/value pairs. Tags defined for the stack are
            propagated to EC2 resources that are created as part of the stack.
            A maximum number of 10 tags can be specified.
        ZCreateStackr   POSTZCreateStackResponseZCreateStackResultStackIdrN   r[   )r   r;   r<   r=   r>   rA   r?   r@   rB   rF   rC   rD   rE   rJ   rP   r   r   r   create_stack2  s    ]       z%CloudFormationConnection.create_stackFc                 C   sF   |  ||||||||d|||	|
||}| d|dd}|d d d S )a  
        Updates a stack as specified in the template. After the call
        completes successfully, the stack update starts. You can check
        the status of the stack via the DescribeStacks action.



        **Note: **You cannot update `AWS::S3::Bucket`_ resources, for
        example, to add or modify tags.



        To get a copy of the template for an existing stack, you can
        use the GetTemplate action.

        Tags that were associated with this stack during creation time
        will still be associated with the stack after an `UpdateStack`
        operation.

        For more information about creating an update template,
        updating a stack, and monitoring the progress of the update,
        see `Updating a Stack`_.

        :type stack_name: string
        :param stack_name:
        The name or stack ID of the stack to update.

        Must contain only alphanumeric characters (case sensitive) and start
            with an alpha character. Maximum length of the name is 255
            characters.

        :type template_body: string
        :param template_body: Structure containing the template body. (For more
            information, go to `Template Anatomy`_ in the AWS CloudFormation
            User Guide.)
        Conditional: You must pass either `UsePreviousTemplate` or one of
            `TemplateBody` or `TemplateUrl`. If both `TemplateBody` and
            `TemplateUrl` are passed, only `TemplateBody` is used.

        :type template_url: string
        :param template_url: Location of file containing the template body. The
            URL must point to a template (max size: 307,200 bytes) located in
            an S3 bucket in the same region as the stack. For more information,
            go to the `Template Anatomy`_ in the AWS CloudFormation User Guide.
        Conditional: You must pass either `UsePreviousTemplate` or one of
            `TemplateBody` or `TemplateUrl`. If both `TemplateBody` and
            `TemplateUrl` are passed, only `TemplateBody` is used.
            `TemplateBody`.

        :type use_previous_template: boolean
        :param use_previous_template: Set to `True` to use the previous
            template instead of uploading a new one via `TemplateBody` or
            `TemplateURL`.
        Conditional: You must pass either `UsePreviousTemplate` or one of
            `TemplateBody` or `TemplateUrl`.

        :type parameters: list
        :param parameters: A list of key/value tuples that specify input
            parameters for the stack. A 3-tuple (key, value, bool) may be used to
            specify the `UsePreviousValue` option.

        :type notification_arns: list
        :param notification_arns: The Simple Notification Service (SNS) topic
            ARNs to publish stack related events. You can find your SNS topic
            ARNs using the `SNS console`_ or your Command Line Interface (CLI).

        :type disable_rollback: bool
        :param disable_rollback: Indicates whether or not to rollback on
            failure.

        :type timeout_in_minutes: integer
        :param timeout_in_minutes: The amount of time that can pass before the
            stack status becomes CREATE_FAILED; if `DisableRollback` is not set
            or is set to `False`, the stack will be rolled back.

        :type capabilities: list
        :param capabilities: The list of capabilities you want to allow in
            the stack.  Currently, the only valid capability is
            'CAPABILITY_IAM'.

        :type tags: dict
        :param tags: A set of user-defined `Tags` to associate with this stack,
            represented by key/value pairs. Tags defined for the stack are
            propagated to EC2 resources that are created as part of the stack.
            A maximum number of 10 tags can be specified.

        :type template_url: string
        :param template_url: Location of file containing the template body. The
            URL must point to a template located in an S3 bucket in the same
            region as the stack. For more information, go to `Template
            Anatomy`_ in the AWS CloudFormation User Guide.
        Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
            passed, only `TemplateBody` is used.

        :type stack_policy_during_update_body: string
        :param stack_policy_during_update_body: Structure containing the
            temporary overriding stack policy body. If you pass
            `StackPolicyDuringUpdateBody` and `StackPolicyDuringUpdateURL`,
            only `StackPolicyDuringUpdateBody` is used.
        If you want to update protected resources, specify a temporary
            overriding stack policy during this update. If you do not specify a
            stack policy, the current policy that associated with the stack
            will be used.

        :type stack_policy_during_update_url: string
        :param stack_policy_during_update_url: Location of a file containing
            the temporary overriding stack policy. The URL must point to a
            policy (max size: 16KB) located in an S3 bucket in the same region
            as the stack. If you pass `StackPolicyDuringUpdateBody` and
            `StackPolicyDuringUpdateURL`, only `StackPolicyDuringUpdateBody` is
            used.
        If you want to update protected resources, specify a temporary
            overriding stack policy during this update. If you do not specify a
            stack policy, the current policy that is associated with the stack
            will be used.

        :rtype: string
        :return: The unique Stack ID.
        NZUpdateStackr   r\   ZUpdateStackResponseZUpdateStackResultr]   r^   )r   r;   r<   r=   r>   rA   r?   r@   rB   rF   rG   rH   rI   rD   rE   rJ   rP   r   r   r   update_stack  s"    ~         z%CloudFormationConnection.update_stackc                 C   s   d|d}|  d|ddS )a}  
        Deletes a specified stack. Once the call completes
        successfully, stack deletion starts. Deleted stacks do not
        show up in the DescribeStacks API if the deletion has been
        completed successfully.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or the unique identifier associated
            with the stack.

        r$   r%   r&   ZDeleteStackr   GETr[   r   stack_name_or_idrJ   r   r   r   delete_stack  s    
z%CloudFormationConnection.delete_stackc                 C   s0   i }|r||d< |r||d< |  d|dtfgS )a  
        Returns all stack related events for a specified stack. For
        more information about a stack's event history, go to
        `Stacks`_ in the AWS CloudFormation User Guide.
        Events are returned, even if the stack never existed or has
        been successfully deleted.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or the unique identifier associated
            with the stack.
        Default: There is no default value.

        :type next_token: string
        :param next_token: String that identifies the start of the next list of
            events, if there is one.
        Default: There is no default value.

        r&   	NextTokenZDescribeStackEventsmember)get_listr   r   re   
next_tokenrJ   r   r   r   describe_stack_events+  s    
z.CloudFormationConnection.describe_stack_eventsc                 C   s   d||d}|  d|ddS )az  
        Returns a description of the specified resource in the
        specified stack.

        For deleted stacks, DescribeStackResource returns resource
        information for up to 90 days after the stack has been
        deleted.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or the unique identifier associated
            with the stack.
        Default: There is no default value.

        :type logical_resource_id: string
        :param logical_resource_id: The logical name of the resource as
            specified in the template.
        Default: There is no default value.

        r$   )r%   r&   LogicalResourceIdZDescribeStackResourcer   rb   rc   )r   re   logical_resource_idrJ   r   r   r   describe_stack_resourceF  s    z0CloudFormationConnection.describe_stack_resourcec                 C   s<   i }|r||d< |r||d< |r(||d< |  d|dtfgS )a	  
        Returns AWS resource descriptions for running and deleted
        stacks. If `StackName` is specified, all the associated
        resources that are part of the stack are returned. If
        `PhysicalResourceId` is specified, the associated resources of
        the stack that the resource belongs to are returned.
        Only the first 100 resources will be returned. If your stack
        has more resources than this, you should use
        `ListStackResources` instead.
        For deleted stacks, `DescribeStackResources` returns resource
        information for up to 90 days after the stack has been
        deleted.

        You must specify either `StackName` or `PhysicalResourceId`,
        but not both. In addition, you can specify `LogicalResourceId`
        to filter the returned result. For more information about
        resources, the `LogicalResourceId` and `PhysicalResourceId`,
        go to the `AWS CloudFormation User Guide`_.
        A `ValidationError` is returned if you specify both
        `StackName` and `PhysicalResourceId` in the same request.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or the unique identifier associated
            with the stack.
        Required: Conditional. If you do not specify `StackName`, you must
            specify `PhysicalResourceId`.

        Default: There is no default value.

        :type logical_resource_id: string
        :param logical_resource_id: The logical name of the resource as
            specified in the template.
        Default: There is no default value.

        :type physical_resource_id: string
        :param physical_resource_id: The name or unique identifier that
            corresponds to a physical instance ID of a resource supported by
            AWS CloudFormation.
        For example, for an Amazon Elastic Compute Cloud (EC2) instance,
            `PhysicalResourceId` corresponds to the `InstanceId`. You can pass
            the EC2 `InstanceId` to `DescribeStackResources` to find which
            stack the instance belongs to and what other resources are part of
            the stack.

        Required: Conditional. If you do not specify `PhysicalResourceId`, you
            must specify `StackName`.

        Default: There is no default value.

        r&   rm   ZPhysicalResourceIdZDescribeStackResourcesrh   )ri   r   )r   re   rn   Zphysical_resource_idrJ   r   r   r   describe_stack_resources^  s    5z1CloudFormationConnection.describe_stack_resourcesc                 C   s4   i }|r||d< |dk	r ||d< |  d|dtfgS )a  
        Returns the description for the specified stack; if no stack
        name was specified, then it returns the description for all
        the stacks created.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or the unique identifier associated
            with the stack.
        Default: There is no default value.

        :type next_token: string
        :param next_token: String that identifies the start of the next list of
            stacks, if there is one.

        r&   Nrg   ZDescribeStacksrh   )ri   r   rj   r   r   r   describe_stacks  s    z(CloudFormationConnection.describe_stacksc                 C   s   d|d}|  d|ddS )a  
        Returns the template body for a specified stack. You can get
        the template for running or deleted stacks.

        For deleted stacks, GetTemplate returns the template for up to
        90 days after the stack has been deleted.
        If the template does not exist, a `ValidationError` is
        returned.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or the unique identifier associated
            with the stack, which are not always interchangeable:

        + Running stacks: You can specify either the stack's name or its unique
              stack ID.
        + Deleted stacks: You must specify the unique stack ID.


        Default: There is no default value.

        r$   ra   ZGetTemplater   rb   rc   rd   r   r   r   get_template  s    
z%CloudFormationConnection.get_templatec                 C   s(   d|i}|r||d< |  d|dtfgS )aE  
        Returns descriptions of all resources of the specified stack.

        For deleted stacks, ListStackResources returns resource
        information for up to 90 days after the stack has been
        deleted.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or the unique identifier associated
            with the stack, which are not always interchangeable:

        + Running stacks: You can specify either the stack's name or its unique
              stack ID.
        + Deleted stacks: You must specify the unique stack ID.


        Default: There is no default value.

        :type next_token: string
        :param next_token: String that identifies the start of the next list of
            stack resource summaries, if there is one.
        Default: There is no default value.

        r&   rg   ZListStackResourcesrh   )ri   r   rj   r   r   r   list_stack_resources  s    z-CloudFormationConnection.list_stack_resourcesc                 C   sB   i }|r||d< |r.t |dkr.| ||d | d|dtfgS )a  
        Returns the summary information for stacks whose status
        matches the specified StackStatusFilter. Summary information
        for stacks that have been deleted is kept for 90 days after
        the stack is deleted. If no StackStatusFilter is specified,
        summary information for all stacks is returned (including
        existing stacks and stacks that have been deleted).

        :type next_token: string
        :param next_token: String that identifies the start of the next list of
            stacks, if there is one.
        Default: There is no default value.

        :type stack_status_filter: list
        :param stack_status_filter: Stack status to use as a filter. Specify
            one or more stack status codes to list only stacks with the
            specified status codes. For a complete list of stack status codes,
            see the `StackStatus` parameter of the Stack data type.

        rg   r   zStackStatusFilter.memberZ
ListStacksrh   )r4   r7   ri   r   )r   Zstack_status_filtersrk   rJ   r   r   r   list_stacks  s    z$CloudFormationConnection.list_stacksc                 C   sB   i }|r||d< |r||d< |r0|r0t jd | jd|tddS )aj  
        Validates a specified template.

        :type template_body: string
        :param template_body: String containing the template body. (For more
            information, go to `Template Anatomy`_ in the AWS CloudFormation
            User Guide.)
        Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
            passed, only `TemplateBody` is used.

        :type template_url: string
        :param template_url: Location of file containing the template body. The
            URL must point to a template (max size: 307,200 bytes) located in
            an S3 bucket in the same region as the stack. For more information,
            go to `Template Anatomy`_ in the AWS CloudFormation User Guide.
        Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
            passed, only `TemplateBody` is used.

        r(   r)   r*   ZValidateTemplater\   )Zverb)r1   r2   r3   Z
get_objectr   )r   r<   r=   rJ   r   r   r   validate_template  s    
z*CloudFormationConnection.validate_templatec                 C   s   i }|r||d< |  d|S )a  
        Cancels an update on the specified stack. If the call
        completes successfully, the stack will roll back the update
        and revert to the previous stack configuration.
        Only stacks that are in the UPDATE_IN_PROGRESS state can be
        canceled.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or the unique identifier associated with
            the stack.

        r&   ZCancelUpdateStack)Z
get_statusrd   r   r   r   cancel_update_stack*  s    z,CloudFormationConnection.cancel_update_stackc           	      C   s   ddi}|dk	r||d< |dk	r(||d< |rnt |dkrnt|D ],\}\}}||d|d  < ||d	|d  < q@| d
|dd}|d d d S )a  
        Returns the estimated monthly cost of a template. The return
        value is an AWS Simple Monthly Calculator URL with a query
        string that describes the resources required to run the
        template.

        :type template_body: string
        :param template_body: Structure containing the template body. (For more
            information, go to `Template Anatomy`_ in the AWS CloudFormation
            User Guide.)
        Conditional: You must pass `TemplateBody` or `TemplateURL`. If both are
            passed, only `TemplateBody` is used.

        :type template_url: string
        :param template_url: Location of file containing the template body. The
            URL must point to a template located in an S3 bucket in the same
            region as the stack. For more information, go to `Template
            Anatomy`_ in the AWS CloudFormation User Guide.
        Conditional: You must pass `TemplateURL` or `TemplateBody`. If both are
            passed, only `TemplateBody` is used.

        :type parameters: list
        :param parameters: A list of key/value tuples that specify input
            parameters for the template.

        :rtype: string
        :returns: URL to pre-filled cost calculator
        r%   r$   Nr(   r)   r   r,   r-   r.   ZEstimateTemplateCostr   r\   ZEstimateTemplateCostResponseZEstimateTemplateCostResultUrl)r4   r5   r[   )	r   r<   r=   r>   rJ   rK   rL   rM   rZ   r   r   r   estimate_template_cost<  s    z/CloudFormationConnection.estimate_template_costc                 C   s*   d|d}|  d|dd}|d d d S )	aq  
        Returns the stack policy for a specified stack. If a stack
        doesn't have a policy, a null value is returned.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or stack ID that is associated with
            the stack whose policy you want to get.

        :rtype: string
        :return: The policy JSON document
        r$   ra   ZGetStackPolicyr   r\   ZGetStackPolicyResponseZGetStackPolicyResultr/   rc   )r   re   rJ   rZ   r   r   r   get_stack_policyi  s    
z)CloudFormationConnection.get_stack_policyc                 C   sB   d|d}|dk	r||d< |dk	r*||d< |  d|dd}|d	 S )
a  
        Sets a stack policy for a specified stack.

        :type stack_name_or_id: string
        :param stack_name_or_id: The name or stack ID that you want to
            associate a policy with.

        :type stack_policy_body: string
        :param stack_policy_body: Structure containing the stack policy body.
            (For more information, go to ` Prevent Updates to Stack Resources`_
            in the AWS CloudFormation User Guide.)
        You must pass `StackPolicyBody` or `StackPolicyURL`. If both are
            passed, only `StackPolicyBody` is used.

        :type stack_policy_url: string
        :param stack_policy_url: Location of a file containing the stack
            policy. The URL must point to a policy (max size: 16KB) located in
            an S3 bucket in the same region as the stack. You must pass
            `StackPolicyBody` or `StackPolicyURL`. If both are passed, only
            `StackPolicyBody` is used.

        r$   ra   Nr/   r0   ZSetStackPolicyr   r\   ZSetStackPolicyResponserc   )r   re   rD   rE   rJ   rZ   r   r   r   set_stack_policy{  s    
z)CloudFormationConnection.set_stack_policy)NNTNNNNNr   NNr   NNTN)NNN)NNNNNNNNNNN)NNNNFNNNNNNNN)NN)NNN)NN)N)NN)NN)N)NNN)NN) __name__
__module____qualname____doc__r1   configgetZ
APIVersionr   r   Zvalid_statesr   r   r#   rN   r[   r_   r`   rf   rl   ro   rp   rq   rr   rs   rt   ru   rv   rx   ry   rz   __classcell__r   r   r   r   r       s   

                           
 4                
d                 
 
   
?




  
-  r   )r1   Zboto.cloudformation.stackr   r   r   r   r   Zboto.cloudformation.templater   Zboto.connectionr   Zboto.regioninfor	   Zboto.compatr
   r   r   r   r   r   <module>   s   