
    Vhg                     r    d dl mZmZmZ eZdZdZd dlZd dl	Z	d dl
mZ d dlmZ d Zd Zed	k(  r e        yy)
    )absolute_importdivisionprint_functionaA  
module: riak
short_description: This module handles some common Riak operations
description:
  - This module can be used to join nodes to a cluster, check the status of the cluster.
author:
  - "James Martin (@jsmartin)"
  - "Drew Kerrigan (@drewkerrigan)"
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  command:
    description:
      - The command you would like to perform against the cluster.
    choices: ['ping', 'kv_test', 'join', 'plan', 'commit']
    type: str
  config_dir:
    description:
      - The path to the riak configuration directory.
    default: /etc/riak
    type: path
  http_conn:
    description:
      - The IP address and port that is listening for Riak HTTP queries.
    default: 127.0.0.1:8098
    type: str
  target_node:
    description:
      - The target node for certain operations (join, ping).
    default: riak@127.0.0.1
    type: str
  wait_for_handoffs:
    description:
      - Number of seconds to wait for handoffs to complete.
    type: int
    default: 0
  wait_for_ring:
    description:
      - Number of seconds to wait for all nodes to agree on the ring.
    type: int
    default: 0
  wait_for_service:
    description:
      - Waits for a riak service to come online before continuing.
    choices: ['kv']
    type: str
  validate_certs:
    description:
      - If V(false), SSL certificates will not be validated. This should only be used on personally controlled sites using
        self-signed certificates.
    type: bool
    default: true
aN  
- name: "Join's a Riak node to another node"
  community.general.riak:
    command: join
    target_node: riak@10.1.1.1

- name: Wait for handoffs to finish. Use with async and poll.
  community.general.riak:
    wait_for_handoffs: true

- name: Wait for riak_kv service to startup
  community.general.riak:
    wait_for_service: kv
N)AnsibleModule)	fetch_urlc                 N    |dgz   }| j                  |      \  }}}|dk(  rd|v ryy)N	ringreadyr   z TRUE All nodes agree on the ringTF)run_command)moduleriak_admin_bincmdrcouterrs         j/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/riak.py
ring_checkr   ]   s9    
K=
(C%%c*LBS	Qw5<    c                  	   t        t        t        dd g d      t        dd      t        dd      t        d	d
      t        dd      t        dd      t        dd dg      t        dd                  } | j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j	                  d      }| j	                  d      }||gn|dg}t        j
                         dz   }		 t        j
                         |	kD  r| j                  d       t        | d|z  dd       \  }
}|d!   d"k(  r|
j                         }nt        j                  d       m	 t        j                  |      }d$   }|d%   }|d&   }| j                  |d'g      \  }}}|j                         }t        ||||(      }|d)k(  r<|d*|}| j                  |      \  }}}|dk(  r||d)<   nK| j                  |       n7|d+k(  r:|d,gz   }| j                  |      \  }}}|dk(  r||d+<   n| j                  |       n|d-k(  rh|j                  |      d.k(  rt!        |      d.kD  rd/|d-<   n|d0d-|gz   }| j                  |      \  }}}|dk(  r||d-<   d|d1<   n| j                  |       n|d2k(  rC|d0d2gz   }| j                  |      \  }}}|dk(  r||d2<   d3|v r\d|d1<   nV| j                  |       nC|d4k(  r>|d0d4gz   }| j                  |      \  }}}|dk(  r||d4<   d|d1<   n| j                  |       |r|t        j
                         |z   }		 |d5gz   }| j                  |      \  }}}d6|v rd7|d8<   n?t        j                  d9       t        j
                         |	kD  r| j                  d:       d|r%|dd;|z  |gz   }| j                  |      \  }}}||d<<   |rdt        j
                         |z   }		 t#        | |      rnt        j                  d9       #t        j
                         |	kD  r| j                  d=       t#        | |      |d><    | j$                  d?i | y # t        $ r | j                  d#       Y w xY w)@NF)pingkv_testjoinplancommit)requireddefaultchoicesz	/etc/riakpath)r   typez127.0.0.1:8098)r   r   zriak@127.0.0.1)r   r   r   intkvTbool)command
config_dir	http_conntarget_nodewait_for_handoffswait_for_ringwait_for_servicevalidate_certs)argument_specr"   r$   r%   r&   r'   r(   riakz
riak-adminadminx   z$Timeout, could not fetch Riak stats.)msgzhttp://%s/stats   )forcetimeoutstatus   zCould not parse Riak stats.nodenamering_membersring_creation_sizeversion)	node_namenodes	ring_sizer7   r   z ping r   testr      z6Node is already in cluster or staged to be in cluster.clusterchangedr   zStaged Changesr   	transferszNo transfers activezNo transfers active.handoffs
   zTimeout waiting for handoffs.zriak_%sservicez+Timeout waiting for nodes to agree on ring.
ring_ready )r   dictparamsgetget_bin_pathtime	fail_jsonr   readsleepjsonloads	Exceptionr
   stripcountlenr   	exit_json)r   r"   r$   r%   r&   r'   r(   riak_binr   r1   responseinfo	stats_rawstatsr8   r9   r:   r   r   r   r7   resultr   s                          r   mainrZ   f   s<   % @= >Kf=E3CD%5F"159qu5!tf>6:
<F mm	*G!!+.I--##M2K))*=>MM%%o6M}}(();< ""6*H((6N)7)Cn%(T[I\NiikCG
99; !GH$V->)-LTXbcd4>S  I

1 <

9% j!I.!E*+I%%x&;<LBSiikGI%!#F
 &&4))#.C7 F6N%	I	x'))#.C7 #F9%	F	;;y!Q&3u:>UF6N Iv{#CCC!--c2LBSQw!$v$(y!  S )	F		622))#.C7 F6N3&$(y!%	H		844))#.C7"F8 $F9% ))+ 11 K=0C!--c2LBS$+%;z"JJrNyy{W$  %D E   2I@P4PR[\\))#.Cy))+-&.1JJrN  99; !NO%fn=F<Fvu  <:;<s   S S,+S,__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESrM   rI   ansible.module_utils.basicr   ansible.module_utils.urlsr   r   rZ   __name__rD   r   r   <module>rc      sP    A @9v   4 /CL zF r   