
    Vh                         d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d dlmZmZmZmZmZmZmZ d Zd	 Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functiona_  
---
module: mongodb_maintenance
short_description: Enables or disables maintenance mode for a secondary member.
description:
  - Enables or disables maintenance mode for a secondary member.
  - Wrapper around the replSetMaintenance command.
  - Performs no actions against a PRIMARY member.
  - When enabled SECONDARY members will not service reads.
author: Rhys Campbell (@rhysmeister)
version_added: "1.0.0"

extends_documentation_fragment:
  - community.mongodb.login_options
  - community.mongodb.ssl_options

options:
  maintenance:
    description: Enable or disable maintenance mode.
    type: bool
    default: false
notes:
  - Requires the pymongo Python package on the remote host, version 4+.. This
    can be installed using pip or the OS package manager.
    @see U(http://api.mongodb.org/python/current/installation.html)
requirements:
  - pymongo
z
- name: Enable maintenance mode
  community.mongodb.mongodb_maintenance:
    maintenance: true

- name: Disable maintenance mode
  community.mongodb.mongodb_maintenance:
    maintenance: false
a  
changed:
  description: Whether the member was placed into maintenance mode or not.
  returned: success
  type: bool
msg:
  description: A short description of what happened.
  returned: success
  type: str
failed:
  description: If something went wrong
  returned: failed
  type: bool
)AnsibleModule)	to_native)missing_required_libmongodb_common_argument_specmember_state
mongo_authPYMONGO_IMP_ERRpymongo_foundget_mongodb_clientc                 .    | d   j                  dd       y )NadminreplSetMaintenanceTcommandclients    y/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/mongodb/plugins/modules/mongodb_maintenance.pyput_in_maint_moder   M   s    
7O0$7    c                 .    | d   j                  dd       y )Nr   r   Fr   r   s    r   remove_maint_moder   Q   s    
7O0%8r   c                  `   t               } | j                  t        dd             t        | dddgg      }t        s |j                  t        d	      t        
       |j                  d   }t        d      }	 t        |d      }t        ||d      }	 t              }|dk(  rd|d<   n|dk(  r5|r-|j                  rd|d<   d|d<   njt        |       d|d<   d|d<   nTd|d<   nN|dk(  r5|rd|d<   nA|j                  rd|d<   d|d<   n*t!        |       d|d<   d|d<   ndj#                  |      |d<    |j$                  di | y # t        $ r(}|j                  dt        |      z         Y d }~d }~ww xY w# t        $ r(}|j                  dt        |      z         Y d }~sd }~ww xY w)NboolF)typedefault)maintenanceT
login_userlogin_password)argument_specsupports_check_moderequired_togetherpymongo)msg	exceptionr   )changed)directConnectionz Unable to connect to MongoDB: %s)r&   PRIMARYz+no action taken as member state was PRIMARYr&   	SECONDARYr(   z'member was placed into maintenance modezONo action taken as maintenance parameter is false and member state is SECONDARY
RECOVERINGz:no action taken as member is already in a RECOVERING statez,the member was removed from maintenance modez'no action taken as member state was {0}zmodule encountered an error: %s )r	   updatedictr   r   	fail_jsonr   r   paramsr   r   	Exceptionr   r
   
check_moder   r   format	exit_json)r"   moduler   resultr   excepstates          r   mainr:   U   s   02Mfe4   # (*:;<F 1)<#2 	 	4 --.KFT#FTBFFTBSV$IIF5Mk!$$(,F9%$MF5M%f-(,F9%$MF5M qul" \u$$(,F9%$RF5M%f-(,F9%$RF5MELLUSF5M FvE  T?)EBRRSST>  S>5AQQRRSs1   ;E BE< 	E9E44E9<	F-F((F-__main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   ansible.module_utils._textr   Iansible_collections.community.mongodb.plugins.module_utils.mongodb_commonr   r	   r
   r   r   r   r   r   r   r:   __name__r-   r   r   <module>rE      sc    A @:
 5 0  89:z zF r   