
    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 d dlmZ d d	lmZ  G d
 de      Zd Zedk(  r e        yy# e$ r Y ?w xY w)    )absolute_importdivisionprint_functiona  
---
module: vmware_maintenancemode
deprecated:
  removed_in: 7.0.0
  why: This module has been moved to the L(new vmware.vmware collection,https://forum.ansible.com/t/5880)
  alternative: Use M(vmware.vmware.esxi_maintenance_mode) instead.
short_description: Place a host into maintenance mode
description:
    - This module can be used for placing a ESXi host into maintenance mode.
    - Support for VSAN compliant maintenance mode when selected.
author:
- Jay Jahns (@jjahns) <jjahns@vmware.com>
- Abhijeet Kasurde (@Akasurde)
options:
    esxi_hostname:
        description:
            - Name of the host as defined in vCenter.
        required: true
        type: str
    vsan:
        description:
            - Specify which VSAN compliant mode to enter.
        choices:
            - 'ensureObjectAccessibility'
            - 'evacuateAllData'
            - 'noAction'
        required: false
        aliases: [ 'vsan_mode' ]
        type: str
    evacuate:
        description:
            - If set to V(true), evacuate all powered off VMs.
        default: false
        required: false
        type: bool
    timeout:
        description:
            - Specify a timeout for the operation.
        required: false
        default: 0
        type: int
    state:
        description:
            - Enter or exit maintenance mode.
        choices:
            - present
            - absent
        default: present
        required: false
        type: str
extends_documentation_fragment:
- community.vmware.vmware.documentation

am  
- name: Enter VSAN-Compliant Maintenance Mode
  community.vmware.vmware_maintenancemode:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    esxi_hostname: "{{ esxi_hostname }}"
    vsan: ensureObjectAccessibility
    evacuate: true
    timeout: 3600
    state: present
  delegate_to: localhost
aR  
hostsystem:
    description: Name of vim reference
    returned: always
    type: str
    sample: "'vim.HostSystem:host-236'"
hostname:
    description: Name of host in vCenter
    returned: always
    type: str
    sample: "esxi.local.domain"
status:
    description: Action taken
    returned: always
    type: str
    sample: "ENTER"
)vim)AnsibleModule)PyVmomi	TaskErrorwait_for_task)base_argument_spec)	to_nativec                   *     e Zd Z fdZd Zd Z xZS )VmwareMaintenanceMgrc                    t         t        |   |       | j                  j                  j                  d      | _        | j                  j                  j                  dd       | _        | j                  | j                        | _	        | j                  s*| j                  j                  d| j                  z         y y )Nesxi_hostnamevsan)	host_namezHost %s not found in vCentermsg)superr   __init__moduleparamsgetr   r   find_hostsystem_by_namehost	fail_json)selfr   	__class__s     {/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/vmware/plugins/modules/vmware_maintenancemode.pyr   zVmwareMaintenanceMgr.__init__q   s    "D26:![[//33ODKK&&**648	004;M;M0N	yyKK!!&DtGYGY&Y!Z     c           	         | j                   j                  j                  rJ| j                  j	                  dt        | j                         | j                  dd| j                  z         t        j                   j                         }| j                  rHt        j                  j                   j                         |_        | j                  |j                  _        	 | j                  j                  sZ| j                   j                  | j                  j                  d   | j                  j                  d   |      }t!        |      \  }}nd}| j                  j	                  |t        | j                         | j                  dd	| j                  z         y # t"        $ r?}| j                  j%                  d
| j                  dt'        |             Y d }~y d }~ww xY w)NF	NO_ACTIONz#Host %s already in maintenance modechanged
hostsystemhostnamestatusr   timeoutevacuateTENTERz Host %s entered maintenance modeHost z) failed to enter maintenance mode due to r   )r   runtimeinMaintenanceModer   	exit_jsonstrr   r   MaintenanceSpecr   DecommissionModevsanModeobjectAction
check_modeEnterMaintenanceMode_Taskr   r
   r	   r   r   )r   spectasksuccessresultes         r   EnterMaintenanceModez)VmwareMaintenanceMgr.EnterMaintenanceModey   s~   99..KK!!%-0^+/+=+=)4&KdN`N`&`	 " b xx'')99HHMM::<DM)-DMM&	A;;))yy::4;;;M;Mi;X;?;;;M;Mj;Y;?A #0"5KK!!'-0^+/+=+=)0&H4K]K]&]	 " _  	AKK!!^b^p^pr{|}r~&!  A  A	As   B<F 	G#$5GG#c           	         | j                   j                  j                  sJ| j                  j	                  dt        | j                         | j                  dd| j                  z         	 | j                  j                  sA| j                   j                  | j                  j                  d         }t        |      \  }}nd}| j                  j	                  |t        | j                         | j                  dd| j                  z         y # t        $ r?}| j                  j                  d	| j                  d
t        |             Y d }~y d }~ww xY w)NFr"   zHost %s not in maintenance moder#   r(   TEXITzHost %s exited maintenance moder+   z( failed to exit maintenance mode due to r   )r   r,   r-   r   r.   r/   r   r4   ExitMaintenanceMode_Taskr   r
   r	   r   r   )r   r7   r8   r9   r:   s        r   ExitMaintenanceModez(VmwareMaintenanceMgr.ExitMaintenanceMode   s   yy  22KK!!%-0^+/+=+=)4&G$J\J\&\	 " ^	@;;))yy99$++:L:LY:WX"/"5KK!!'-0^+/+=+=)/&G$J\J\&\	 " ^
  	@KK!!]a]o]oqz{|q}&~!	@s   ,B#D 	E5EE)__name__
__module____qualname__r   r;   r?   __classcell__)r   s   @r   r   r   p   s    [AB@r    r   c                     t               } | j                  t        t        dd      t        dg ddg      t        dd	      t        d
d      t        ddddg                   t        | d      }t	        |      }|j
                  d   dk(  r|j                          y |j
                  d   dk(  r|j                          y y )Nr/   T)typerequired)ensureObjectAccessibilityevacuateAllDatanoAction	vsan_mode)rE   choicesaliasesboolF)rE   defaultr   int)rN   rE   presentabsent)rF   rN   rK   )r   r   r)   r(   state)argument_specsupports_check_mode)r   rR   )r   updatedictr   r   r   r;   r?   )r6   r   host_maintenance_mgrs      r   mainrX      s    DKK4UT#BE(4 )4}	! #>!!%8	IW_K`a
  /35F 0v>}}W*113	w	8	+002 
,r    __main__N)
__future__r   r   r   rE   __metaclass__DOCUMENTATIONEXAMPLESRETURNpyVmomir   ImportErroransible.module_utils.basicr   @ansible_collections.community.vmware.plugins.module_utils.vmwarer   r	   r
   Hansible_collections.community.vmware.plugins.module_utils._argument_specr   ansible.module_utils._textr   r   rX   r@    r    r   <module>rf      s    A @6p
$	 5 n n g 0@@7 @@F34 zF M  		s   A AA