
    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: project
short_description: Manage OpenStack Identity (Keystone) projects
author: OpenStack Ansible SIG
description:
  - Create, update or delete a OpenStack Identity (Keystone) project.
options:
  name:
    description:
      - Name for the project.
      - This attribute cannot be updated.
    required: true
    type: str
  description:
    description:
      - Description for the project.
    type: str
  domain:
    description:
      - Domain name or id to create the project in if the cloud supports
        domains.
    aliases: ['domain_id']
    type: str
  extra_specs:
    description:
      - Additional properties to be associated with this project.
    type: dict
    aliases: ['properties']
  is_enabled:
    description:
      - Whether this project is enabled or not.
    aliases: ['enabled']
    type: bool
  state:
    description:
      - Should the resource be present or absent.
    choices: [present, absent]
    default: present
    type: str
extends_documentation_fragment:
  - openstack.cloud.openstack
aw  
- name: Create a project
  openstack.cloud.project:
    cloud: mycloud
    description: demodescription
    domain: demoid
    is_enabled: True
    name: demoproject
    extra_specs:
      internal_alias: demo_project
    state: present

- name: Delete a project
  openstack.cloud.project:
    cloud: mycloud
    endpoint_type: admin
    name: demoproject
    state: absent
a  
project:
  description: Dictionary describing the project.
  returned: On success when I(state) is C(present).
  type: dict
  contains:
    description:
      description: Project description
      type: str
      sample: "demodescription"
    domain_id:
      description: Domain ID to which the project belongs
      type: str
      sample: "default"
    id:
      description: Project ID
      type: str
      sample: "f59382db809c43139982ca4189404650"
    is_domain:
      description: Indicates whether the project also acts as a domain.
      type: bool
    is_enabled:
      description: Indicates whether the project is enabled
      type: bool
    name:
      description: Project name
      type: str
      sample: "demoproject"
    options:
      description: The resource options for the project
      type: dict
    parent_id:
      description: The ID of the parent of the project
      type: str
    tags:
      description: A list of associated tags
      type: list
      elements: str
    )OpenStackModulec                       e Zd Z e e        edg       eddg       eddg       ed	       ed
dd
g            Z ed      Zd Zd Zd Zd Z	d Z
d Zd Zy)IdentityProjectModule	domain_id)aliasesdict
properties)typer   boolenabledT)requiredpresentabsent)defaultchoices)descriptiondomainextra_specs
is_enablednamestate)supports_check_modec                 f   | j                   d   }| j                         }| j                  j                  r"| j	                  | j                  ||             |dk(  r6|s4| j                         }| j	                  d|j                  d             y |dk(  rT|rR| j                  |      }|r| j                  ||      }| j	                  t        |      |j                  d             y |dk(  r&|r$| j                  |       | j	                  d       y |dk(  r|s| j	                  d       y y y )	Nr   )changedr   TF)computed)r   projectr   )params_findansible
check_mode	exit_json_will_change_createto_dict_build_update_updater   _delete)selfr   r   updates       k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/project.pyrunzIdentityProjectModule.run   s   G$**,<<""NN4#4#4UG#DNEIgllnGNN4#*??E?#B  D iG''0F,,w7NN4<#*??E?#B  D h7LL!NN4N(hwNN5N) (/    c           	      8    i }dD cg c](  } j                   |    j                   |   |   k7  r|* }}|r! j                  dj                  |             t         fddD              } j                   d   }|rt	        |j                               t	        |j                               z  }|r2t        dj                  dj                  t        |                        |j                         D ]  \  }}||   k7  s|||<    |r||d	<   |S c c}w )
N zCannot update parameters {0})msgc              3      K   | ]9  }j                   |   (j                   |   |   k7  r|j                   |   f ; y wNr   ).0kr   r(   s     r*   	<genexpr>z6IdentityProjectModule._build_update.<locals>.<genexpr>   sH      <![[^7"kk!n
: dkk!n- <s   ?A)r   r   r   $Duplicate key(s) in extra_specs: {0}, 
attributes)
r   	fail_jsonformatr   setkeys
ValueErrorjoinlistitems)	r(   r   r)   r4   non_updateable_keysr8   r   duplicate_keysvs	   ``       r*   r%   z#IdentityProjectModule._build_update   s7    +- AQ"&++a."<#';;q>WQZ#?  ! A A NN= &': ;  =  <#@< <

 kk-0 !23c+:J:J:L6MMN !G"(&43G)H"IK K#))+ &1
?$%JqM& #-F< 5As   -Dc           	          t         fddD              } j                  d   }|6 j                  j                  j	                  |d      }|j
                  |d<    j                  d   }|rst        |j                               t        |j                               z  }|r2t        dj                  d	j                  t        |                        t        |fi |}  j                  j                  j                  d
i |S )Nc              3   ^   K   | ]$  }j                   |   |j                   |   f & y wr1   r2   )r3   r4   r(   s     r*   r5   z0IdentityProjectModule._create.<locals>.<genexpr>   s4      5Q3 $++a.) 5s   *-)r   r   r   r   Fignore_missingr   r   r6   r7   r.   )r   r   connidentityfind_domainidr;   r<   r=   r:   r>   r?   create_project)r(   kwargsdomain_name_or_idr   r   rB   s   `     r*   r#   zIdentityProjectModule._create   s     5D5 5 !KK1(YY''334ECH 4 JF"())F;kk-0 /#k6F6F6H2IIN !G"(&43G)H"IK K&0K0F0tyy!!00:6::r,   c                 b    | j                   j                  j                  |j                         y r1   )rH   rI   delete_projectrK   )r(   r   s     r*   r'   zIdentityProjectModule._delete   s    		))'**5r,   c                    | j                   d   }i }| j                   d   }|6| j                  j                  j                  |d      }|j                  |d<    | j                  j                  j
                  dd|i|S )Nr   r   FrF   r   
name_or_idr.   )r   rH   rI   rJ   rK   find_project)r(   r   rM   rN   r   s        r*   r   zIdentityProjectModule._find   s    {{6" KK1(YY''334ECH 4 JF"())F;.tyy!!.. 9$ 9179 	9r,   c                     |j                  d      }|r1 | j                  j                  j                  |j                  fi |}|S )Nr8   )getrH   rI   update_projectrK   )r(   r   r)   r8   s       r*   r&   zIdentityProjectModule._update   sF    ZZ-
7dii((77

 F:DFG r,   c                 f    |dk(  r|sy|dk(  r|rt        | j                  |            S |dk(  r|ryy)Nr   Tr   F)r   r%   )r(   r   r   s      r*   r"   z"IdentityProjectModule._will_change   sA    IgiG**7344h7 r,   N)__name__
__module____qualname__r   argument_specmodule_kwargsr+   r%   r#   r'   r   r&   r"   r.   r,   r*   r   r   r   s~    F[M*f|n=Vi[94 9x.CDM  M*@B;*69	r,   r   c                  &    t               }  |         y r1   )r   )modules    r*   mainr_      s    "$F
Hr,   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   r_   rX   r.   r,   r*   <module>re      sJ   *X(&
P _DO DN
 zF r,   