
    Vh6#                         d dl mZmZmZ eZdZdZd dlZd dl	Z	dZ
	 d dlmZ d dlmZ dZd d	lmZmZ d d
lmZ d Zd Z G d d      Zedk(  r e        yy# e$ r  e	j"                         Z
dZY Fw xY w)    )absolute_importdivisionprint_functiona  
module: znode
short_description: Create, delete, retrieve, and update znodes using ZooKeeper
description:
  - Create, delete, retrieve, and update znodes using ZooKeeper.
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
extends_documentation_fragment:
  - community.general.attributes
options:
  hosts:
    description:
      - A list of ZooKeeper servers (format V([server]:[port])).
    required: true
    type: str
  name:
    description:
      - The path of the znode.
    required: true
    type: str
  value:
    description:
      - The value assigned to the znode.
    type: str
  op:
    description:
      - An operation to perform. Mutually exclusive with state.
    choices: [get, wait, list]
    type: str
  state:
    description:
      - The state to enforce. Mutually exclusive with op.
    choices: [present, absent]
    type: str
  timeout:
    description:
      - The amount of time to wait for a node to appear.
    default: 300
    type: int
  recursive:
    description:
      - Recursively delete node and all its children.
    type: bool
    default: false
  auth_scheme:
    description:
      - Authentication scheme.
    choices: [digest, sasl]
    type: str
    default: "digest"
    required: false
    version_added: 5.8.0
  auth_credential:
    description:
      - The authentication credential value. Depends on O(auth_scheme).
      - The format for O(auth_scheme=digest) is C(user:password), and the format for O(auth_scheme=sasl) is C(user:password).
    type: str
    required: false
    version_added: 5.8.0
  use_tls:
    description:
      - Using TLS/SSL or not.
    type: bool
    default: false
    required: false
    version_added: '6.5.0'
requirements:
  - kazoo >= 2.1
author: "Trey Perry (@treyperry)"
a  
- name: Creating or updating a znode with a given value
  community.general.znode:
    hosts: 'localhost:2181'
    name: /mypath
    value: myvalue
    state: present

- name: Getting the value and stat structure for a znode
  community.general.znode:
    hosts: 'localhost:2181'
    name: /mypath
    op: get

- name: Getting the value and stat structure for a znode using digest authentication
  community.general.znode:
    hosts: 'localhost:2181'
    auth_credential: 'user1:s3cr3t'
    name: /secretmypath
    op: get

- name: Listing a particular znode's children
  community.general.znode:
    hosts: 'localhost:2181'
    name: /zookeeper
    op: list

- name: Waiting 20 seconds for a znode to appear at path /mypath
  community.general.znode:
    hosts: 'localhost:2181'
    name: /mypath
    op: wait
    timeout: 20

- name: Deleting a znode at path /mypath
  community.general.znode:
    hosts: 'localhost:2181'
    name: /mypath
    state: absent

- name: Creating or updating a znode with a given value on a remote Zookeeper
  community.general.znode:
    hosts: 'my-zookeeper-node:2181'
    name: /mypath
    value: myvalue
    state: present
  delegate_to: 127.0.0.1
N)KazooClient)KazooTimeoutErrorTF)AnsibleModulemissing_required_lib)to_bytesc                     t        t        t        dd      t        dd      t        d      t        g d      t        ddg      t        d	d
      t        dd      t        dddg      t        dd      t        dd      
      d      } t        s | j                  t	        d      t
               t        | j                        }|d   s| j                  |d          t        |       }	 |j                          |j                  |j                  |j                  d|j                  |j                  dd}d| j                  v r| j                  d   dnd}| j                  |   } ||   |          \  }}|j!                          |r | j"                  di | y  | j                  di | y # t        $ r | j                  d       Y w xY w) NTstr)requiredtype)r   )getwaitlist)choicespresentabsenti,  int)defaultr   Fbooldigestsasl)r   r   )r   no_log)
hostsnamevalueopstatetimeout	recursiveauth_schemeauth_credentialuse_tls)argument_specsupports_check_modezkazoo >= 2.1)msg	exceptionsuccessr'   )r'   z3The connection to the ZooKeeper ensemble timed out.)r   r   r   )r   r   )r   r   r   r    )r   dictKAZOO_INSTALLED	fail_jsonr	   KAZOO_IMP_ERRcheck_paramsparamsKazooCommandProxystartr   r   r   r   r   r   shutdown	exit_json)modulecheckzoocommand_dictcommand_typemethodresultresult_dicts           k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/znode.pymainr>      s   51t%0E"34	845515v6X&7IJ eD9V4
 "F  1.A]['EU5\*
F
#CT		 77HHHH
 {{jj

L  6==0V]]45H5T4ZaL]]<(F<,|4V<>FKLLN';'';'/  TRSTs   3F9 9GGc                 F    | d   s
| d   sdddS | d   r
| d   rdddS ddiS )	Nr   r   Fz+Please define an operation (op) or a state.)r)   r'   z9Please choose an operation (op) or a state, but not both.r)   Tr*   )r0   s    r=   r/   r/      s?    '?6$< )VWWg6$< )deet    c                   \    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZddZy)r1   c                 j    || _         t        |j                  d   |j                  d         | _        y )Nr   r$   )use_ssl)r5   r   r0   zk)selfr5   s     r=   __init__zKazooCommandProxy.__init__   s)    fmmG4fmmI>VWr@   c                 R    | j                  | j                  j                  d         S Nr   )_absentr5   r0   rE   s    r=   r   zKazooCommandProxy.absent   s     ||DKK..v677r@   c                 8    | j                   j                  |      S N)rD   existsrE   znodes     r=   rM   zKazooCommandProxy.exists   s    ww~~e$$r@   c                     | j                   j                  | j                  j                  d         }dt	        |      |d| j                  j                  d   dfS )Nr   TzRetrieved znodes in path.)countitemsr'   rO   )rD   get_childrenr5   r0   len)rE   childrens     r=   r   zKazooCommandProxy.list   sT    77''(:(:6(BCs8}xHc#{{11&9; ; 	;r@   c                     | j                  | j                  j                  d   | j                  j                  d         S )Nr   r   )_presentr5   r0   rJ   s    r=   r   zKazooCommandProxy.present   s1    }}T[[//79K9KG9TUUr@   c                 R    | j                  | j                  j                  d         S rH   )_getr5   r0   rJ   s    r=   r   zKazooCommandProxy.get   s     yy++F344r@   c                 l    | j                   j                          | j                   j                          y rL   )rD   stopcloserJ   s    r=   r3   zKazooCommandProxy.shutdown   s    r@   c                     | j                   j                          | j                  j                  d   rK| j                   j	                  | j                  j                  d   | j                  j                  d          y y )Nr#   r"   )rD   r2   r5   r0   add_authrJ   s    r=   r2   zKazooCommandProxy.start   sZ    ;;/0GGT[[//>@R@RSd@ef 1r@   c                     | j                  | j                  j                  d   | j                  j                  d         S )Nr   r    )_waitr5   r0   rJ   s    r=   r   zKazooCommandProxy.wait   s1    zz$++,,V4dkk6H6H6STTr@   c                     | j                  |      r;| j                  j                  || j                  j                  d          ddddfS ddddfS )Nr!   )r!   TzThe znode was deleted.)changedr'   FzThe znode does not exist.)rM   rD   deleter5   r0   rN   s     r=   rI   zKazooCommandProxy._absent   sS    ;;uGGNN5DKK,>,>{,KNLT2JKKKU3NOOOr@   c                    | j                  |      ru| j                  j                  |      \  }}i }t        |      D ]<  }|j	                  d      rt        ||      }t        |t        t        f      s8|||<   > dd|||df}|S dddif}|S )N_TzThe node was retrieved.)r'   rO   r   statFr'   z"The requested node does not exist.)	rM   rD   r   dir
startswithgetattr
isinstancer   r   )rE   pathr   zstat	stat_dictiattrr;   s           r=   rY   zKazooCommandProxy._get   s    ;;t77;;t,LE5IZ ,||C("5!,D!$c
3'+	!	,
 #<tV[$-/ /F
  U$HIIFr@   c                 8   | j                  |      rZ| j                  j                  |      \  }}||k7  r.| j                  j                  |t	        |             ddd||dfS ddd||dfS | j                  j                  |t	        |      d       ddd||dfS )NTzUpdated the znode value.)rb   r'   rO   r   FzNo changes were necessary.)makepathzCreated a new znode.)rM   rD   r   setr
   create)rE   rk   r   current_valuerl   s        r=   rW   zKazooCommandProxy._present  s    ;;t%)WW[[%6"]E%D(5/26P[_',. . . 7S^bmrsssGGNN4%4N@T2HSWbghhhr@   c                     t        j                          |z   }t        j                          |k  rF| j                  |      rdd||dfS t        j                  |       t        j                          |k  rFdd||dfS )NTz0The node appeared before the configured timeout.)r'   rO   r    Fz7The node did not appear before the operation timed out.)r'   r    rO   )timerM   sleep)rE   rk   r    intervallims        r=   r`   zKazooCommandProxy._wait  s    iikG#iikC{{4 %W'+A A A 

8$ iikC Wdk $& & 	&r@   N)   )__name__
__module____qualname__rF   r   rM   r   r   r   r3   r2   r   rI   rY   rW   r`   r*   r@   r=   r1   r1      sI    X8%;
V5g
UP i&r@   r1   __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESrv   	tracebackr.   kazoo.clientr   kazoo.handlers.threadingr   r,   ImportError
format_excansible.module_utils.basicr   r	   +ansible.module_utils.common.text.convertersr
   r>   r/   r1   r{   r*   r@   r=   <module>r      s    A @HT/b  (:O
 K @2(jQ& Q&h zF w  (I((*MOs   A A10A1