
    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mZ d Zd Zd	 Zd
 Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: nxos_gir
extends_documentation_fragment:
- cisco.nxos.nxos
short_description: Trigger a graceful removal or insertion (GIR) of the switch.
description:
- Trigger a graceful removal or insertion (GIR) of the switch.
- GIR processing may take more than 2 minutes. Timeout settings are automatically
  extended to 200s when user timeout settings are insufficient.
version_added: 1.0.0
author:
- Gabriele Gerbino (@GGabriele)
notes:
- Tested against NXOSv 7.3.(0)D1(1) on VIRL
- Unsupported for Cisco MDS
- C(state) has effect only in combination with C(system_mode_maintenance_timeout)
  or C(system_mode_maintenance_on_reload_reset_reason).
- Using C(system_mode_maintenance) and C(system_mode_maintenance_dont_generate_profile)
  would make the module fail, but the system mode will be triggered anyway.
options:
  system_mode_maintenance:
    description:
    - When C(system_mode_maintenance=true) it puts all enabled protocols in maintenance
      mode (using the isolate command). When C(system_mode_maintenance=false) it puts
      all enabled protocols in normal mode (using the no isolate command).
    type: bool
  system_mode_maintenance_dont_generate_profile:
    description:
    - When C(system_mode_maintenance_dont_generate_profile=true) it prevents the dynamic
      searching of enabled protocols and executes commands configured in a maintenance-mode
      profile. Use this option if you want the system to use a maintenance-mode profile
      that you have created. When C(system_mode_maintenance_dont_generate_profile=false)
      it prevents the dynamic searching of enabled protocols and executes commands
      configured in a normal-mode profile. Use this option if you want the system
      to use a normal-mode profile that you have created.
    type: bool
  system_mode_maintenance_timeout:
    description:
    - Keeps the switch in maintenance mode for a specified number of minutes. Range
      is 5-65535.
    type: str
  system_mode_maintenance_shutdown:
    description:
    - Shuts down all protocols, vPC domains, and interfaces except the management
      interface (using the shutdown command). This option is disruptive while C(system_mode_maintenance)
      (which uses the isolate command) is not.
    type: bool
  system_mode_maintenance_on_reload_reset_reason:
    description:
    - Boots the switch into maintenance mode automatically in the event of a specified
      system crash. Note that not all reset reasons are applicable for all platforms.
      Also if reset reason is set to match_any, it is not idempotent as it turns on
      all reset reasons. If reset reason is match_any and state is absent, it turns
      off all the reset reasons.
    choices:
    - hw_error
    - svc_failure
    - kern_failure
    - wdog_timeout
    - fatal_error
    - lc_failure
    - match_any
    - manual_reload
    - any_other
    - maintenance
    type: str
  state:
    description:
    - Specify desired state of the resource.
    default: present
    choices:
    - present
    - absent
    type: str
a  
# Trigger system maintenance mode
- cisco.nxos.nxos_gir:
    system_mode_maintenance: true
    host: '{{ inventory_hostname }}'
    username: '{{ un }}'
    password: '{{ pwd }}'
# Trigger system normal mode
- cisco.nxos.nxos_gir:
    system_mode_maintenance: false
    host: '{{ inventory_hostname }}'
    username: '{{ un }}'
    password: '{{ pwd }}'
# Configure on-reload reset-reason for maintenance mode
- cisco.nxos.nxos_gir:
    system_mode_maintenance_on_reload_reset_reason: manual_reload
    state: present
    host: '{{ inventory_hostname }}'
    username: '{{ un }}'
    password: '{{ pwd }}'
# Add on-reload reset-reason for maintenance mode
- cisco.nxos.nxos_gir:
    system_mode_maintenance_on_reload_reset_reason: hw_error
    state: present
    host: '{{ inventory_hostname }}'
    username: '{{ un }}'
    password: '{{ pwd }}'
# Remove on-reload reset-reason for maintenance mode
- cisco.nxos.nxos_gir:
    system_mode_maintenance_on_reload_reset_reason: manual_reload
    state: absent
    host: '{{ inventory_hostname }}'
    username: '{{ un }}'
    password: '{{ pwd }}'
# Set timeout for maintenance mode
- cisco.nxos.nxos_gir:
    system_mode_maintenance_timeout: 30
    state: present
    host: '{{ inventory_hostname }}'
    username: '{{ un }}'
    password: '{{ pwd }}'
# Remove timeout for maintenance mode
- cisco.nxos.nxos_gir:
    system_mode_maintenance_timeout: 30
    state: absent
    host: '{{ inventory_hostname }}'
    username: '{{ un }}'
    password: '{{ pwd }}'
a  
final_system_mode:
    description: describe the last system mode
    returned: verbose mode
    type: str
    sample: normal
updates:
    description: commands sent to the device
    returned: verbose mode
    type: list
    sample: ["terminal dont-ask", "system mode maintenance timeout 10"]
changed:
    description: check to see if a change was made on the device
    returned: always
    type: bool
    sample: true
)AnsibleModule)load_configrun_commandsc                 d    ddd}t        | |g      d   }|rd|j                         v rd}|S d}|S )Nzshow system modetextcommandoutputr   normalmaintenance)r   lower)moduler   bodymodes       g/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/nxos/plugins/modules/nxos_gir.pyget_system_moder      sG    ,?G	*1-DDJJL( K K    c                 V    ddd}t        | |g      d   }|j                         d   }|S )Nzshow maintenance timeoutr
   r   r      )r   split)r   r   r   timeouts       r   get_maintenance_timeoutr      s3    4GG	*1-Djjl1oGNr   c                 0    ddd}t        | |g      d   }|S )Nz(show maintenance on-reload reset-reasonsr
   r   r   )r   )r   r   r   s      r   get_reset_reasonsr      s)    =G 	*1-DKr   c                 *   t               }| j                  d   du r|dk(  r|j                  d       nK| j                  d   du r|dk(  r|j                  d       n"| j                  d   du r|dk(  r|j                  d	       n| j                  d   du r|dk(  r|j                  d
       n| j                  d   rt        |       }|dk(  rA|| j                  d   k7  r/|j                  dj	                  | j                  d                np|dk(  rj|| j                  d   k(  rW|j                  dj	                  | j                  d                n(| j                  d   r|dk(  r|j                  d       n| j                  d   du r|dk(  r|j                  d       n| j                  d   rt        |       }|dk(  r[| j                  d   j                         |j                         vr.|j                  dj	                  | j                  d                n_|dk(  rZ| j                  d   j                         |j                         v r-|j                  dj	                  | j                  d                |r|j                  dd       |S )Nsystem_mode_maintenanceTr   zsystem mode maintenanceFr   zno system mode maintenance-system_mode_maintenance_dont_generate_profilez-system mode maintenance dont-generate-profilez0no system mode maintenance dont-generate-profilesystem_mode_maintenance_timeoutpresentz#system mode maintenance timeout {0}absentz&no system mode maintenance timeout {0} system_mode_maintenance_shutdownz system mode maintenance shutdown.system_mode_maintenance_on_reload_reset_reasonz2system mode maintenance on-reload reset-reason {0}z5no system mode maintenance on-reload reset-reason {0}r   zterminal dont-ask)listparamsappendr   formatr   r   insert)r   stater   commandsr   reset_reasonss         r   get_commandsr.      sm   vH}}./47DH<L12	0	1U	:t}?T45 	EF$NSW[cScGHEF%OM!JK	8	9)&1I'V]];\-]"]OO5<<MM"CD
 h7fmm<].^#^OO8??MM"CD 
9	:tx?O:;	9	:e	CP]H]45	G	H)&1YNOUUW &&() OO##)6MM"RS$ XNOUUW""$% OO##)6MM"RS$ ./Or   c                  (   t        t        dd      t        dd      t        dd      t        dd      t        dg d      t        ddgdd	      
      } t        | g dgg dgd      }t               }|j                  d   }t	        |      }t        |||      }d}|r.|j                  r|j                  d|       nt        ||       d}i }||d<   |j                  dkD  rt	        |      }||d<   ||d<   ||d<    |j                  di | y )NFbool)requiredtypestr)
hw_errorsvc_failurekern_failurewdog_timeoutfatal_error
lc_failure	match_anymanual_reload	any_otherr   )r1   choicesr#   r"   )r=   defaultr1   )r   r    r!   r$   r%   r+   )r   r    r!   r$   r%   T)argument_specmutually_exclusiverequired_one_ofsupports_check_moder+   )changedr,   rC   r   final_system_modeupdateswarnings )
dictr   r&   r'   r   r.   
check_mode	exit_jsonr   
_verbosity)	r?   r   rF   r+   r   r,   rC   resultrD   s	            r   mainrM     s<    $e& A6:EPV6W(,e%(H)-u6)J7;8
 Hi0)eT)M. #

 !)F. vHMM'"E6"DFE40HGTH=)GFF91+F3&7"#$y!F:Fvr   __main__N)
__future__r   r   r   r2   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Eansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxosr   r   r   r   r   r.   rM   __name__rG   r   r   <module>rW      sh   $ A @ JX0d
$ 5@FEP zF r   