
    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: host_aggregate
short_description: Manage OpenStack host aggregates
author: OpenStack Ansible SIG
description:
    - Create, update, or delete OpenStack host aggregates. If a aggregate
      with the supplied name already exists, it will be updated with the
      new name, new availability zone, new metadata and new list of hosts.
options:
  name:
    description: Name of the aggregate.
    required: true
    type: str
  metadata:
    description: Metadata dict.
    type: dict
  availability_zone:
    description: Availability zone to create aggregate into.
    type: str
  hosts:
    description: List of hosts to set for an aggregate.
    type: list
    elements: str
  purge_hosts:
    description: Whether hosts not in I(hosts) should be removed from the aggregate
    type: bool
    default: true
  state:
    description: Should the resource be present or absent.
    choices: [present, absent]
    default: present
    type: str
extends_documentation_fragment:
- openstack.cloud.openstack
a  
# Create a host aggregate
- openstack.cloud.host_aggregate:
    cloud: mycloud
    state: present
    name: db_aggregate
    hosts:
      - host1
      - host2
    metadata:
      type: dbcluster

# Add an additional host to the aggregate
- openstack.cloud.host_aggregate:
    cloud: mycloud
    state: present
    name: db_aggregate
    hosts:
      - host3
    purge_hosts: false
    metadata:
      type: dbcluster

# Delete an aggregate
- openstack.cloud.host_aggregate:
    cloud: mycloud
    state: absent
    name: db_aggregate
a  
aggregate:
    description: A host aggregate resource.
    type: dict
    returned: On success, when I(state) is present
    contains:
        availability_zone:
            description: Availability zone of the aggregate
            type: str
            returned: always
        created_at:
            description: The date and time when the resource was created
            type: str
            returned: always
        deleted_at:
            description:
                - The date and time when the resource was deleted
                - Null unless I(is_deleted) is true
            type: str
            returned: always
        hosts:
            description: Hosts belonging to the aggregate
            type: str
            returned: always
        id:
            description: The UUID of the aggregate.
            type: str
            returned: always
        is_deleted:
            description: Whether or not the resource is deleted
            type: bool
            returned: always
        metadata:
            description: Metadata attached to the aggregate
            type: str
            returned: always
        name:
            description: Name of the aggregate
            type: str
            returned: always
        updated_at:
            description: The date and time when the resource was updated
            type: str
            returned: always
        uuid:
            description: UUID of the aggregate
            type: str
            returned: always
    )OpenStackModulec                       e Zd Z e ed       ed       e        edd       edd	       ed
dd
g            Z ed      Zd Zd Zd Zd Z	y)ComputeHostAggregateModuleT)requireddict)typeliststr)r   elementsbool)defaultr   presentabsent)r   choices)namemetadataavailability_zonehostspurge_hostsstate)supports_check_modec                    | j                   d   xs i }| j                   d   | j                   d   |d<   | j                   d   | j                   d   r/t        | j                   d         t        |j                        k7  rWyt        | j                   d         j                  t        |j                              }t        | j                   d         |k7  rydD ])  }| j                   |   | j                   |   ||   k7  s) y y)Nr   r   r   r   T)r   r   F)paramssetr   intersection)self	aggregatenew_metadatar   params        r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/host_aggregate.py_needs_updatez(ComputeHostAggregateModule._needs_update   s    {{:.4";;*+704<O0PL,-;;w+{{=)t{{7+,IOO0DD"4;;w#78EEc)//FZ[t{{7+,<6 	E{{5!-KK&)E*::	
     c                 d    | j                   d   }|dk(  r|ry|dk(  r|y| j                  |      S y)Nr   r   Tr   F)r   r!   )r   r   r   s      r    _system_state_changez/ComputeHostAggregateModule._system_state_change   sB    G$HI %%i00r"   c                 d   |y t        |      t        |d   xs g       z
  }|D ]2  }| j                  j                  j                  |j                  |       4 |sy t        |d   xs g       t        |      z
  }|D ]2  }| j                  j                  j                  |j                  |       4 y )Nr   )r   conncomputeadd_host_to_aggregateidremove_host_from_aggregate)r   r   r   r   hosts_to_addhosthosts_to_removes          r    _update_hostsz(ComputeHostAggregateModule._update_hosts   s    =5zC	'(:(@b$AA  	HDII33ILL$G	H i06B7#e*D# 	MDII88tL	Mr"   c                 X   | j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }||j                  dd        | j                  j                  j	                  |      }| j
                  j                  r!| j                  | j                  |             d}|d	k(  r{|e| j                  j                  j                  ||
      }| j                  ||d       |r&| j                  j                  j                  ||       d}n| j                  |      r|(| j                  j                  j                  |||
      }|u|}	t        |j                  j!                         t        |j!                               z
        D ]  }
|
dk7  s	d |	|
<    | j                  j                  j                  ||	       | j                  |||       d}| j                  j                  j	                  |      }|r|j#                  d      }| j                  ||       nK|dk(  rF|D| j                  |g d       | j                  j                  j%                  |j&                         d}| j                  |       y )Nr   r   r   r   r   r   )changedFr   )r   r   T)computed)r0   r   r   )r   popr&   r'   find_aggregateansible
check_mode	exit_jsonr$   create_aggregater.   set_aggregate_metadatar!   update_aggregater   r   keysto_dictdelete_aggregater)   )r   r   r   r   r   r   r   r   r0   metasis              r    runzComputeHostAggregateModule.run   si   {{6";;z* KK(;<G$kk-0G$LL,d3II%%44T:	<<""NN4#<#<Y#GNHI  II-->>1B ? D	""9eU;II%%<<YQ##I.$0 $		 1 1 B B!*; !C !=I '$E !3!3!8!8!:S=Q!QR , 33'+E!H, II%%<<YN""9e[A		))88>I%--u-=	NN7iN@h9#8y"d3II..y||<Gw'r"   N)
__name__
__module____qualname__r   argument_specmodule_kwargsr!   r$   r.   r?    r"   r    r   r      sh    4 6"&/F39x.CDM  M,
M/(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   r@   rE   r"   r    <module>rN      sJ   #J<0
d _n( n(b
 zF r"   