
    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: server_group
short_description: Manage OpenStack server groups
author: OpenStack Ansible SIG
description:
   - Add or remove server groups from OpenStack.
options:
   state:
     description:
        - Indicate desired state of the resource. When I(state) is C(present),
          then I(policy) is required.
     choices: ['present', 'absent']
     default: present
     type: str
   name:
     description:
        - Server group name.
     required: true
     type: str
   policy:
     description:
        - Represents the current name of the policy.
     choices: ['anti-affinity', 'affinity', 'soft-anti-affinity', 'soft-affinity']
     type: str
   rules:
     description:
        - Rules to be applied to the policy. Currently, only the
          C(max_server_per_host) rule is supported for the C(anti-affinity)
          policy.
     type: dict
extends_documentation_fragment:
- openstack.cloud.openstack
aG  
- name: Create a server group with 'affinity' policy.
  openstack.cloud.server_group:
    cloud: "{{ cloud }}"
    state: present
    name: my_server_group
    policy: affinity

- name: Delete 'my_server_group' server group.
  openstack.cloud.server_group:
    cloud: "{{ cloud }}"
    state: absent
    name: my_server_group
a,  
server_group:
    description: Object representing the server group
    returned: On success when I(state) is present
    type: dict
    contains:
        id:
            description: Unique UUID.
            returned: always
            type: str
        name:
            description: The name of the server group.
            returned: always
            type: str
        policies:
            description: |
                A list of exactly one policy name to associate with the group.
                Available until microversion 2.63
            returned: always
            type: list
        policy:
            description: |
                Represents the name of the policy. Available from version 2.64 on.
            returned: always
            type: str
        member_ids:
            description: The list of members in the server group
            returned: always
            type: list
        metadata:
            description: Metadata key and value pairs.
            returned: always
            type: dict
        project_id:
            description: The project ID who owns the server group.
            returned: always
            type: str
        rules:
            description: |
                The rules field, applied to the policy. Currently, only the
                C(max_server_per_host) rule is supported for the
                C(anti-affinity) policy.
            returned: always
            type: dict
        user_id:
            description: The user ID who owns the server group.
            returned: always
            type: str
    )OpenStackModulec            	           e Zd Z e ed       eg d       edddg       ed	      
      Z eddddgfg      Zd Zd Zy)ServerGroupModuleT)required)zanti-affinityaffinityzsoft-anti-affinityzsoft-affinity)choicespresentabsent)defaultr   dict)type)namepolicystaterulesr   r   )supports_check_moderequired_ifc                 $    |dk(  r|sy|dk(  r|ryy)Nr	   Tr
   F )selfr   server_groups      p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/server_group.py_system_state_changez&ServerGroupModule._system_state_change~   s    IlH    c                    | j                   d   }| j                   d   }| j                  j                  j                  |      }| j                  j
                  r"| j                  | j                  ||             d}|dk(  ry|sTdD ci c]!  }| j                   |   || j                   |   # }} | j                  j                  j                  di |}d}| j                  ||j                  d      	       |d
k(  r<|r'| j                  j                  j                  |       d}| j                  |       y y c c}w )Nr   r   )changedFr	   )r   r   r   T)computed)r   r   r
   r   )paramsconncomputefind_server_groupansible
check_mode	exit_jsonr   create_server_groupto_dictdelete_server_group)r   r   r   r   r   kkwargss          r   runzServerGroupModule.run   s>   {{6"G$yy((::4@<<""NN11%F   I#>9![[^7 T[[^+ 9 9  Etyy00DDNvNNN)1151A   H		!!55lCNN7N+	 9s   	&D>N)__name__
__module____qualname__r   argument_specmodule_kwargsr   r*   r   r   r   r   r   n   sb    4  . /9x.CDM  i(,
M,r   r   c                  &    t               }  |         y )N)r   )modules    r   mainr2      s     F
Hr   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   r2   r+   r   r   r   <module>r8      sH   !F0
d _4, 4,n
 zF r   