
    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: lb_pool
short_description: Manage load-balancer pool in a OpenStack cloud.
author: OpenStack Ansible SIG
description:
  - Add, update or remove load-balancer pool from OpenStack cloud.
options:
  description:
    description:
      - A human-readable description for the load-balancer pool.
    type: str
  lb_algorithm:
    description:
      - The load balancing algorithm for the pool.
      - For example, I(lb_algorithm) could be C(LEAST_CONNECTIONS),
        C(ROUND_ROBIN), C(SOURCE_IP) or C(SOURCE_IP_PORT).
    default: ROUND_ROBIN
    type: str
  listener:
    description:
      - The name or id of the listener that this pool belongs to.
      - Either I(listener) or I(loadbalancer) must be specified for pool
        creation.
      - This attribute cannot be updated.
    type: str
  loadbalancer:
    description:
      - The name or id of the load balancer that this pool belongs to.
      - Either I(listener) or I(loadbalancer) must be specified for pool
        creation.
      - This attribute cannot be updated.
    type: str
  name:
    description:
      - Name that has to be given to the pool.
      - This attribute cannot be updated.
    required: true
    type: str
  protocol:
    description:
      - The protocol for the pool.
      - For example, I(protocol) could be C(HTTP), C(HTTPS), C(PROXY),
        C(PROXYV2), C(SCTP), C(TCP) and C(UDP).
      - This attribute cannot be updated.
    default: HTTP
    type: str
  state:
    description:
      - Should the resource be present or absent.
    choices: [present, absent]
    default: present
    type: str
extends_documentation_fragment:
  - openstack.cloud.openstack
a  
pool:
  description: Dictionary describing the load-balancer pool.
  returned: On success when I(state) is C(present).
  type: dict
  contains:
    alpn_protocols:
      description: List of ALPN protocols.
      type: list
    created_at:
      description: Timestamp when the pool was created.
      type: str
    description:
      description: The pool description.
      type: str
    health_monitor_id:
      description: Health Monitor ID.
      type: str
    id:
      description: Unique UUID.
      type: str
    is_admin_state_up:
      description: The administrative state of the pool.
      type: bool
    lb_algorithm:
      description: The load balancing algorithm for the pool.
      type: str
    listener_id:
      description: The listener ID the pool belongs to.
      type: str
    listeners:
      description: A list of listener IDs.
      type: list
    loadbalancer_id:
      description: The load balancer ID the pool belongs to. This field is set
                   when the pool does not belong to any listener in the load
                   balancer.
      type: str
    loadbalancers:
      description: A list of load balancer IDs.
      type: list
    members:
      description: A list of member IDs.
      type: list
    name:
      description: Name given to the pool.
      type: str
    operating_status:
      description: The operating status of the pool.
      type: str
    project_id:
      description: The ID of the project.
      type: str
    protocol:
      description: The protocol for the pool.
      type: str
    provisioning_status:
      description: The provisioning status of the pool.
      type: str
    session_persistence:
      description: A JSON object specifying the session persistence for the
                   pool.
      type: dict
    tags:
      description: A list of associated tags.
      type: list
    tls_ciphers:
      description: Stores a string of cipher strings in OpenSSL format.
      type: str
    tls_enabled:
      description: Use TLS for connections to backend member servers.
      type: bool
    tls_versions:
      description: A list of TLS protocol versions to be used in by the pool.
      type: list
    updated_at:
      description: Timestamp when the pool was updated.
      type: str
aH  
- name: Create a load-balancer pool
  openstack.cloud.lb_pool:
    cloud: mycloud
    lb_algorithm: ROUND_ROBIN
    loadbalancer: test-loadbalancer
    name: test-pool
    protocol: HTTP
    state: present

- name: Delete a load-balancer pool
  openstack.cloud.lb_pool:
    cloud: mycloud
    name: test-pool
    state: absent
    )OpenStackModulec                       e Zd Z e e        ed       e        e        ed       ed       edddg      	      Z ed
gdgd      Zd Zd Zd Zd Z	d Z
d Zd Zy)LoadBalancerPoolModuleROUND_ROBIN)defaultT)requiredHTTPpresentabsent)r   choices)descriptionlb_algorithmlistenerloadbalancernameprotocolstate)r   r
   r   r   Tr   )required_ifmutually_exclusive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   poolr   )params_findansible
check_mode	exit_json_will_change_createto_dict_build_update_updatebool_delete)selfr   r   updates       k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/lb_pool.pyrunzLoadBalancerPoolModule.run   s   G$zz|<<""NN4#4#4UD#ANBId<<>DNN4 $e <  > iD''-F||D&1NN4< $e <  > h4LLNN4N(htNN5N) (,    c                     i }dD cg c](  } j                   |    j                   |   |   k7  r|* }} j                   d   }|rU j                  j                  j                  |d      }d   t	        |j
                        gk7  r|j                  d        j                   d   }|rU j                  j                  j                  |d      }d	   t	        |j
                        gk7  r|j                  d
       |r! j                  dj                  |             t	         fddD              }	|	r|	|d<   |S c c}w )N)r   r   Fignore_missing	listeners)idlistener_idr   load_balancersloadbalancer_idzCannot update parameters {0})msgc              3      K   | ]9  }j                   |   (j                   |   |   k7  r|j                   |   f ; y wNr   ).0kr   r(   s     r*   	<genexpr>z7LoadBalancerPoolModule._build_update.<locals>.<genexpr>   sH      9![[^7"kk!nQ7 dkk!n- 9s   ?A)r   r   
attributes)
r   connload_balancerfind_listenerdictr1   appendfind_load_balancer	fail_jsonformat)
r(   r   r)   r:   non_updateable_keyslistener_name_or_idr   loadbalancer_name_or_idr   r<   s
   ``        r*   r$   z$LoadBalancerPoolModule._build_update   s_   *6 >Q"&++a."<#';;q>T!W#<  ! > > #kk*5yy..<<#E = ;H K TX[[%9$::#**=9"&++n"="9922EE' F ?L ()dloo.F-GG#**+<=NN= &': ;  =  9#B9 9

 #-F< E>s   -Ec                 P    t         fddD              } j                  d   }|r6 j                  j                  j	                  |d      }|j
                  |d<    j                  d   }|r6 j                  j                  j                  |d      }|j
                  |d<     j                  j                  j                  di |} j                  d	   rM j                  j                  j                   j                  j                  |d
dg j                  d   d      }|S )Nc              3   ^   K   | ]$  }j                   |   |j                   |   f & y wr7   r8   )r9   r:   r(   s     r*   r;   z1LoadBalancerPoolModule._create.<locals>.<genexpr>   s4      5Q3 $++a.) 5s   *-)r   r   r   r   r   Fr.   r2   r   r4   waitactiveerrortimeoutprovisioning_statusstatusfailuresrJ   	attribute )r@   r   r=   r>   r?   r1   rB   create_poolsdkresourcewait_for_status)r(   kwargsrF   r   rG   r   r   s   `      r*   r"   zLoadBalancerPoolModule._create   s    5 05 5
 #kk*5yy..<<#E = ;H$,KKF=!"&++n"="9922EE' F ?L(4F$%2tyy&&22<V<;;v88$$44		''![[+/ 5 1D r,   c                 V   | j                   j                  j                  |j                         | j                  d   rk| j
                  j                  j                  | j                  d   d      D ]3  }| j                   j                  j                  |j                        3 y  y y )NrJ   rM   z3Timeout waiting for load-balancer pool to be absent)rM   message)	r=   r>   delete_poolr1   r   rU   utilsiterate_timeout	find_pool)r(   r   counts      r*   r'   zLoadBalancerPoolModule._delete  s    		++DGG4;;v77I.M 8   99**9TWW%. r,   c                 l    | j                   d   }| j                  j                  j                  |      S )Nr   )
name_or_id)r   r=   r>   r^   )r(   r   s     r*   r   zLoadBalancerPoolModule._find)  s.    {{6"yy&&00D0AAr,   c                 F   |j                  d      }|r1 | j                  j                  j                  |j                  fi |}| j
                  d   rM| j                  j                  j                  | j                  j                  |ddg| j
                  d   d      }|S )Nr<   rJ   rK   rL   rM   rN   rO   )	getr=   r>   update_poolr1   r   rU   rV   rW   )r(   r   r)   r<   s       r*   r%   zLoadBalancerPoolModule._update-  s    ZZ-
6499**66twwM*MD;;v88$$44		''![[+/ 5 1D 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#LoadBalancerPoolModule._will_change<  sA    IdiD**4011h4 r,   N)__name__
__module____qualname__r@   argument_specmodule_kwargsr+   r$   r"   r'   r   r%   r!   rS   r,   r*   r   r      s    F-0V4 f%9x.CDM D
 )
 !M*@%N<
B	r,   r   c                  &    t               }  |         y r7   )r   )modules    r*   mainrm   H  s    #%F
Hr,   __main__N)DOCUMENTATIONRETURNEXAMPLESBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   rm   rf   rS   r,   r*   <module>rs      sK   7rN
`" _a_ aH
 zF r,   