
    Vh*                     R    d Z dZdZddlmZ  G d de      Zd Zedk(  r e        y	y	)
a  
---
module: stack
short_description: Add/Remove Heat Stack
author: OpenStack Ansible SIG
description:
   - Add or Remove a Stack to an OpenStack Heat
options:
    environment:
      description:
        - List of environment files that should be used for the stack creation
      type: list
      elements: str
    name:
      description:
        - A name for the stack.
        - The value must be unique within a project.
        - The name must start with an ASCII letter and can contain ASCII
          letters, digits, underscores, periods, and hyphens. Specifically,
          the name must match the C(^[a-zA-Z][a-zA-Z0-9_.-]{0,254}$) regular
          expression.
        - When you delete or abandon a stack, its name will not become
          available for reuse until the deletion completes successfully.
      required: true
      type: str
    parameters:
      description:
        - Dictionary of parameters for the stack creation
      type: dict
      default: {}
    rollback:
      description:
        - Rollback stack creation
      type: bool
      default: false
    state:
      description:
        - Indicate desired state of the resource
      choices: ['present', 'absent']
      default: present
      type: str
    tags:
      description:
        - One or more simple string tags to associate with the stack.
        - To associate multiple tags with a stack, separate the tags with
          commas. For example, C(tag1,tag2).
      type: str
      aliases: ['tag']
    template:
      description:
        - Path of the template file to use for the stack creation
      type: str
    timeout:
      description:
        - Maximum number of seconds to wait for the stack creation
      default: 3600
      type: int
extends_documentation_fragment:
- openstack.cloud.openstack
a  
- name: create stack
  openstack.cloud.stack:
    name: "teststack"
    tag: "tag1,tag2"
    state: present
    template: "/path/to/my_stack.yaml"
    environment:
    - /path/to/resource-registry.yaml
    - /path/to/environment.yaml
    parameters:
        bmc_flavor: m1.medium
        bmc_image: CentOS
        key_name: default
        node_count: 2
        name: undercloud
        image: CentOS
        my_flavor: m1.large
a  
stack:
    description: stack info
    type: dict
    returned: always
    contains:
        added:
            description: List of resource objects that will be added.
            type: list
        capabilities:
            description: AWS compatible template listing capabilities.
            type: list
        created_at:
            description: Time when created.
            type: str
            sample: "2016-07-05T17:38:12Z"
        deleted:
            description: A list of resource objects that will be deleted.
            type: list
        deleted_at:
            description: Time when the deleted.
            type: str
            sample: "2016-07-05T17:38:12Z"
        description:
            description: >
              Description of the Stack provided in the heat
              template.
            type: str
            sample: "HOT template to create a new instance and networks"
        environment:
            description: A JSON environment for the stack.
            type: dict
        environment_files:
            description: >
              An ordered list of names for environment files found
              in the files dict.
            type: list
        files:
            description: >
              Additional files referenced in the template or
              the environment
            type: dict
        files_container:
            description: >
              Name of swift container with child templates and
              files.
            type: str
        id:
            description: Stack ID.
            type: str
            sample: "97a3f543-8136-4570-920e-fd7605c989d6"
        is_rollback_disabled:
            description: Whether the stack will support a rollback.
            type: bool
        links:
            description: Links to the current Stack.
            type: list
            elements: dict
            sample: "[{'href': 'http://foo:8004/v1/7f6a/stacks/test-stack/
                     97a3f543-8136-4570-920e-fd7605c989d6']"
        name:
            description: Name of the Stack
            type: str
            sample: "test-stack"
        notification_topics:
            description: Stack related events.
            type: str
            sample: "HOT template to create a new instance and networks"
        outputs:
            description: Output returned by the Stack.
            type: list
            elements: dict
            sample: "[{'description': 'IP of server1 in private network',
                        'output_key': 'server1_private_ip',
                        'output_value': '10.1.10.103'}]"
        owner_id:
            description: The ID of the owner stack if any.
            type: str
        parameters:
            description: Parameters of the current Stack
            type: dict
            sample: "{'OS::project_id': '7f6a3a3e01164a4eb4eecb2ab7742101',
                        'OS::stack_id': '97a3f543-8136-4570-920e-fd7605c989d6',
                        'OS::stack_name': 'test-stack',
                        'stack_status': 'CREATE_COMPLETE',
                        'stack_status_reason':
                            'Stack CREATE completed successfully',
                        'status': 'COMPLETE',
                        'template_description':
                            'HOT template to create a new instance and nets',
                        'timeout_mins': 60,
                        'updated_time': null}"
        parent_id:
            description: The ID of the parent stack if any.
            type: str
        replaced:
            description: A list of resource objects that will be replaced.
            type: str
        status:
            description: stack status.
            type: str
        status_reason:
            description: >
              Explaining how the stack transits to its current
              status.
            type: str
        tags:
            description: A list of strings used as tags on the stack
            type: list
        template:
            description: A dict containing the template use for stack creation.
            type: dict
        template_description:
            description: Stack template description text.
            type: str
        template_url:
            description: The URL where a stack template can be found.
            type: str
        timeout_mins:
            description: Stack operation timeout in minutes.
            type: str
        unchanged:
            description: >
              A list of resource objects that will remain unchanged
              if a stack.
            type: list
        updated:
            description: >
              A list of resource objects that will have their
              properties updated.
            type: list
        updated_at:
            description: Timestamp of last update on the stack.
            type: str
        user_project_id:
            description: The ID of the user project created for this stack.
            type: str
    )OpenStackModulec                       e Zd Z e edd       ed       ei d       edd	       ed
dd
g       edg       e        edd            Z eddg      Zd Zd Zy)StackModuleliststr)typeelementsT)requireddict)defaultr   Fboolpresentabsent)r   choicestag)aliasesi  int)environmentname
parametersrollbackstatetagstemplatetimeout)r   r   )r   T)supports_check_moderequired_ifc                      |dk(  ry|dk(  r|ryy)Nr   Tr   F )selfstackr   s      i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/stack.py_system_state_changez StackModule._system_state_change   s    I H    c                 h   | j                   d   }| j                   d   }| j                  j                  |      }| j                  j                  r"| j                  | j                  ||             |dk(  rat        |      }t        | j                   d   | j                   d   | j                   d   | j                   d   d	
      }| j                   d   }|||d<   | j                   d   }t        |j                               t        |j                               z  }|r#t        dj                  t        |                  t        |fi |}|s | j                  j                  |fi |}n | j                  j                  |fi |}| j                  j                   j                  |d         }| j                  d	|j#                  d             y |dk(  rU|s| j                  d       y | j                  j%                  |d   | j                   d          | j                  d	       y y )Nr   r   )changedr   r   r   r   r   T)template_fileenvironment_filesr   r   waitr   r   z"Duplicate key(s) {0} in parametersidF)computed)r&   r!   r   r)   )
name_or_idr)   )paramsconn	get_stackansible
check_mode	exit_jsonr#   r   r   setkeys
ValueErrorformatr   create_stackupdate_stackorchestrationto_dictdelete_stack)	r    r   r   r!   	is_updatekwargsr   extra_kwargs
dup_kwargss	            r"   runzStackModule.run  s   G${{6" 		##D)<<""NN4#<#<UE#JNKI UI"kk*5"&++m"<I.Z0 	F ;;v&D!%v;;|4LV[[]+c,2C2C2E.FFJ !E"(&j)9":< <&1L1F.		..t>v>.		..t>v>II++55eDkBENN4u}}e}/LNMhu-		&&%+,0KK,? ' At, r$   N)__name__
__module____qualname__r   argument_specmodule_kwargsr#   r@   r   r$   r"   r   r      s{    fu54 0e&19x.CD5'"T.	M  57M5-r$   r   c                  &    t               }  |         y )N)r   )modules    r"   mainrH   ;  s    ]F
Hr$   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   rH   rA   r   r$   r"   <module>rN      sK   ;z(I
V _Q-/ Q-h
 zF r$   