
    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	)
am  
---
module: lb_member
short_description: Manage members in a OpenStack load-balancer pool
author: OpenStack Ansible SIG
description:
   - Add, update or remove member from OpenStack load-balancer pool.
options:
  address:
    description:
      - The IP address of the member.
      - Required when I(state) is C(present).
      - This attribute cannot be updated.
    type: str
  monitor_address:
    description:
      - IP address used to monitor this member.
    type: str
  monitor_port:
    description:
      - Port used to monitor this member.
    type: int
  name:
    description:
      - Name that has to be given to the member.
    required: true
    type: str
  pool:
    description:
      - The name or id of the pool that this member belongs to.
      - This attribute cannot be updated.
    required: true
    type: str
  protocol_port:
    description:
      - The protocol port number for the member.
      - Required when I(state) is C(present).
      - This attribute cannot be updated.
    type: int
  state:
    description:
      - Should the resource be C(present) or C(absent).
    choices: [present, absent]
    default: present
    type: str
  subnet_id:
    description:
      - The subnet ID the member service is accessible from.
      - This attribute cannot be updated.
    type: str
  weight:
    description:
      - The weight of a member determines the portion of requests or
        connections it services compared to the other members of the pool.
      - For example, a member with a weight of 10 receives five times as many
        requests as a member with a weight of 2. A value of 0 means the member
        does not receive new connections but continues to service existing
        connections. A valid value is from 0 to 256.
      - "Octavia's default for I(weight) is C(1)."
    type: int
extends_documentation_fragment:
  - openstack.cloud.openstack
a  
member:
  description: Dictionary describing the load-balancer pool member.
  returned: On success when I(state) is C(present).
  type: dict
  contains:
    address:
      description: The IP address of the backend member server.
      type: str
    backup:
      description: A bool value that indicates whether the member is a backup
                    or not. Backup members only receive traffic when all
                    non-backup members are down.
      type: bool
    created_at:
      description: Timestamp when the member was created.
      type: str
    id:
      description: Unique UUID.
      type: str
    is_admin_state_up:
      description: The administrative state of the member.
      type: bool
    monitor_address:
      description: IP address used to monitor this member.
      type: str
    monitor_port:
      description: Port used to monitor this member.
      type: int
    name:
      description: Name given to the member.
      type: str
    operating_status:
      description: Operating status of the member.
      type: str
    project_id:
      description: The ID of the project this member is associated with.
      type: str
    protocol_port:
      description: The protocol port number for the member.
      type: int
    provisioning_status:
      description: The provisioning status of the member.
      type: str
    subnet_id:
      description: The subnet ID the member service is accessible from.
      type: str
    tags:
      description: A list of associated tags.
      type: list
    updated_at:
      description: Timestamp when the member was last updated.
      type: str
    weight:
      description: A positive integer value that indicates the relative portion
                   of traffic that this member should receive from the pool.
                   For example, a member with a weight of 10 receives five
                   times as much traffic as a member with weight of 2.
      type: int
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
ak  
- name: Create member in a load-balancer pool
  openstack.cloud.lb_member:
    address: 192.168.10.3
    cloud: mycloud
    name: test-member
    pool: test-pool
    protocol_port: 8080
    state: present

- name: Delete member from a load-balancer pool
  openstack.cloud.lb_member:
    cloud: mycloud
    name: test-member
    pool: test-pool
    state: absent
    )OpenStackModulec                       e Zd Z e e        e        ed       ed       ed       ed       edddg       e        ed      	      Z ed	gd
      Zd Zd Zd Zd Z	d Z
d Zd Zy)LoadBalancerMemberModuleint)typeT)requiredpresentabsent)defaultchoices)	addressmonitor_addressmonitor_portnamepoolprotocol_portstate	subnet_idweight)r   r	   )r   r   )required_ifsupports_check_modec                    | j                   d   }| j                         \  }}| j                  j                  r#| j	                  | j                  |||             |dk(  rH|sF| j                  |      }| j	                  d|j                  d      |j                  d             y |dk(  rg|re| j                  ||      }|r| j                  |||      }| j	                  t        |      |j                  d      |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   memberr   r
   )params_findansible
check_mode	exit_json_will_change_createto_dict_build_update_updatebool_delete)selfr   r   r   updates        m/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/lb_member.pyrunzLoadBalancerMemberModule.run   s>   G$zz|<<""NN4#4#4UFD#INJIf\\$'FNN4"(..%."@ $e <  > iF''5FfdF;NN4<"(..%."@ $e <  > h6LL&NN4N(hvNN5N) (.    c                      i }dD cg c](  } j                   |    j                   |   |   k7  r|* }}|r! j                  dj                  |             t         fddD              }|r||d<   |S c c}w )N)r   r   r   r   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>z9LoadBalancerMemberModule._build_update.<locals>.<genexpr>'  sH      ;![[^7"kk!nq	9	 dkk!n- ;s   ?A)r   r   r   
attributes)r   	fail_jsonformatdict)r(   r   r   r)   r3   non_updateable_keysr5   s   ``     r*   r$   z&LoadBalancerMemberModule._build_update  s    +8 @Q"&++a."<#';;q>VAY#>  ! @ @
 NN= &': ;  =  ;$.; ;
 #-F< %@s   -A9c                 J    t         fddD              }  j                  j                  j                  |j                  fi |} j
                  d   rM j                  j                  j                   j                  j                  |ddg j
                  d   d      }|S )	Nc              3   ^   K   | ]$  }j                   |   |j                   |   f & y wr0   r1   )r2   r3   r(   s     r*   r4   z3LoadBalancerMemberModule._create.<locals>.<genexpr>3  s4      5Q3 $++a.) 5s   *-)r   r   r   r   r   r   r   waitactiveerrortimeoutprovisioning_statusstatusfailuresr<   	attribute)	r8   connload_balancercreate_memberidr   sdkresourcewait_for_status)r(   r   kwargsr   s   `   r*   r"   z LoadBalancerMemberModule._create2  s     5 P5 5
 7((66twwI&I;;vXX&&66		''![[+/ 7 1F r,   c                    | j                   j                  j                  |j                  |j                         | j                  d   rv| j
                  j                  j                  | j                  d   d      D ]>  }| j                   j                  j                  |j                  |j                        > y  y y )Nr<   r?   z5Timeout waiting for load-balancer member to be absent)r?   message)	rE   rF   delete_memberrH   r   rI   utilsiterate_timeoutfind_member)r(   r   r   counts       r*   r'   z LoadBalancerMemberModule._deleteD  s    		--fiiA;;v77I.O 8   99**;vyy$''2; r,   c                     | j                   d   }| j                   d   }| j                  j                  j                  |d      }| j                  j                  j	                  ||j
                        }||fS )Nr   r   F)
name_or_idignore_missing)r   rE   rF   	find_poolrR   rH   )r(   r   pool_name_or_idr   r   s        r*   r   zLoadBalancerMemberModule._findP  sm    {{6"++f-yy&&00O@E 1 G((44T477Ct|r,   c                 \   |j                  d      }|r< | j                  j                  j                  |j                  |j                  fi |}| j
                  d   rM| j                  j                  j                  | j                  j                  |ddg| j
                  d   d      }|S )Nr5   r<   r=   r>   r?   r@   rA   )	getrE   rF   update_memberrH   r   rI   rJ   rK   )r(   r   r   r)   r5   s        r*   r%   z LoadBalancerMemberModule._updateZ  s    ZZ-
:TYY,,::699dgg I=GIF;;vXX&&66		''![[+/ 7 1F r,   c                 h    |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   r   s       r*   r!   z%LoadBalancerMemberModule._will_changei  sC    IfiF**64899h6 r,   N)__name__
__module____qualname__r8   argument_specmodule_kwargsr+   r$   r"   r'   r   r%   r!    r,   r*   r   r      s    u%4 4 &9x.CD&
M ?
 !	M *D.$
	r,   r   c                  &    t               }  |         y r0   )r   )modules    r*   mainre   u  s    %'F
Hr,   __main__N)DOCUMENTATIONRETURNEXAMPLESBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   re   r]   rb   r,   r*   <module>rk      sK   >@H
T$ _L L^
 zF r,   