
    VhZ!                         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ZdZd dlmZmZ d dlmZ d d	lmZ d
 Zedk(  r e        yy# e$ r  e	j                         Z
dZY ?w xY w)    )absolute_importdivisionprint_functiona  
---
module: rabbitmq_exchange
author: Manuel Sousa (@manuel-sousa)

short_description: Manage rabbitMQ exchange
description:
  - This module uses rabbitMQ Rest API to create/delete exchanges
requirements: [ "requests >= 1.0.0" ]
options:
    name:
        description:
            - Name of the exchange to create.
        type: str
        required: true
    state:
        description:
            - Whether the exchange should be present or absent.
        type: str
        choices: [ "present", "absent" ]
        required: false
        default: present
    durable:
        description:
            - Whether exchange is durable or not.
        type: bool
        required: false
        default: true
    exchange_type:
        description:
            - Type for the exchange.
            - If using I(x-delayed-message), I(x-random), I(x-consistent-hash) or I(x-recent-history) the respective plugin on
            - the RabbitMQ server must be enabled.
        type: str
        required: false
        choices: [ "fanout", "direct", "headers", "topic", "x-delayed-message", "x-random", "x-consistent-hash", "x-recent-history" ]
        aliases: [ "type" ]
        default: direct
    auto_delete:
        description:
            - If the exchange should delete itself after all queues/exchanges unbound from it.
        type: bool
        required: false
        default: false
    internal:
        description:
            - Exchange is available only for other exchanges.
        type: bool
        required: false
        default: false
    arguments:
        description:
            - Extra arguments for exchange. If defined this argument is a key/value dictionary.
        type: dict
        required: false
        default: {}
extends_documentation_fragment:
  - community.rabbitmq.rabbitmq

z
- name: Create direct exchange
  community.rabbitmq.rabbitmq_exchange:
    name: directExchange

- name: Create topic exchange on vhost
  community.rabbitmq.rabbitmq_exchange:
    name: topicExchange
    type: topic
    vhost: myVhost
NTF)AnsibleModulemissing_required_lib)parse)rabbitmq_argument_specc                  
   t               } | j                  t        t        dddgd      t        dd      t        dd      t        d	d      t        d	d      t        d
dgg dd      t        t               d                   t        | d      }|j                  d   d|j                  d   d|j                  d   dt        j                  |j                  d   d      dt        j                  |j                  d   d      	}t        s |j                  t        d      t               dddd d!}t        d	|j                  d   "      }t        j                  ||j                  d#   |j                  d$   f|j                  d%   |j                  d&   |j                  d'   f(      }|j                  d)k(  rd}|j                         }n;|j                  d*k(  rd	}|j                  }n|j                  d+|j                  ,       |j                  d-   dk(  r }n}|s|j                  d)k(  rx|j                  d-   dk(  rfd.   |j                  d.   k(  r?|d/   |j                  d/   k(  r*|d0   |j                  d0   k(  r|d   |j                  d1   k(  s|j                  d23       |j                   r.||d4<   |d5<   |j                  d6   |d6<    |j"                  dDi | |r|j                  d-   dk(  rt        j$                  ||j                  d#   |j                  d$   fd7d8it        j&                  |j                  d.   |j                  d/   |j                  d0   |j                  d1   |j                  d6   d9      |j                  d%   |j                  d&   |j                  d'   f:      }np|j                  d-   dk(  r^t        j(                  ||j                  d#   |j                  d$   f|j                  d%   |j                  d&   |j                  d'   f(      }|j                  d;k(  s|j                  d<k(  rd|d4<    |j"                  dDi | y |j                         }	|	d=   j+                  d>      rM	 |j                  d?||j                  d1      d@|j                  d1   |j                  |j                  A       y |j                  dC|j                  |j                  A       y |j#                  d	|j                  d   "       y # t,        $ r; |j                  dB|j                  d1   z  |j                  |j                  A       Y y w xY w)ENpresentabsentstr)defaultchoicestypeT)requiredr   bool)r   r   Fdirectr   )fanoutr   headerstopicx-delayed-messagex-randomx-consistent-hashx-recent-history)r   aliasesr   r   dict)statenamedurableauto_deleteinternalexchange_type	arguments)argument_specsupports_check_modelogin_protocolz://
login_host:
login_portz/api/exchanges/vhost /r   requests)msg	exception!rabbitmq_consistent_hash_exchangerabbitmq_random_exchange!rabbitmq_delayed_message_exchange rabbitmq_recent_history_exchange)r   r   r   r   )changedr   
login_userlogin_passwordca_certclient_cert
client_key)authverifycert   i  zEInvalid response from RESTAPI when trying to check if exchange exists)r.   detailsr   r   r    r!   r"   zIRabbitMQ RESTAPI doesn't support attribute changes for existing exchanges)r.   r4   r>   r#   zcontent-typezapplication/json)r   r    r!   r   r#   )r:   r   datar;   r<         reasonzunknown exchange typez5Error creating exchange. You may need to enable the 'z' plugin for exchange type )r.   statusr>   zMError creating exchange. You may need to enable a plugin for exchange type %szError creating exchange )r	   updater   r   paramsurllib_parsequoteHAS_REQUESTS	fail_jsonr   REQUESTS_IMP_ERRr-   getstatus_codejsontext
check_mode	exit_jsonputdumpsdelete
startswithKeyError)
r$   moduleurlexchange_pluginsresultrexchange_existsresponsechange_requiredrjsons
             x/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/rabbitmq/plugins/modules/rabbitmq_exchange.pymainra   d   s9   *,My9h2GeTt%0F3U8%f5x&(]$)+ 467	
 DQF 	&'l#l#6==1266==0"5C 1*=IYZ .Q$>-P,NP %fmmF&;<F 	Sl ;V]]K[=\]"MM)4FMM-<XZ`ZgZghtZu;v	xA 	}}668	
#	66WFF 	 	

 }}W*--) q}}3g8NR[8[Y6==#;;]#v}}]'CCZ FMM*$==Vo >>_  
 +y$y$mmK8{"6" ==!Y.mmL16==AQ3RS');<ZZ%}}Y7#)==#? &j 9"MM/:!'{!;!  }}Y/mmM2FMM,4OPA ]]7#x/6==+FVfHg*h'-}}Y'?v}}UbGcekerers  fA  GBCA ==C1==C#7 $F9F&v&FFHEh**+BC$$.v}}_/MNPVP]P]^mPnp }} !	 %    1==FF !  	v& 	 	
   $$l#]]?;< }} !	 % s   	AT AU#"U#__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESrN   	tracebackrK   r-   rI   ImportError
format_excansible.module_utils.basicr   r   %ansible.module_utils.six.moves.urllibr   rG   Dansible_collections.community.rabbitmq.plugins.module_utils.rabbitmqr	   ra   __name__rD       r`   <module>ro      s    A @;z
   L
 K G gB
J zF ]  +y++-Ls   A A"!A"