
    Vh                     z    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ dZd Zdd	Zd
 Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: pacemaker_cluster
short_description: Manage pacemaker clusters
author:
  - Mathieu Bultel (@matbu)
description:
  - This module can manage a pacemaker cluster and nodes from Ansible using the pacemaker CLI.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  state:
    description:
      - Indicate desired state of the cluster.
    choices: [cleanup, offline, online, restart]
    type: str
  node:
    description:
      - Specify which node of the cluster you want to manage. V(null) == the cluster status itself, V(all) == check the status
        of all nodes.
    type: str
  timeout:
    description:
      - Timeout when the module should considered that the action has failed.
    default: 300
    type: int
  force:
    description:
      - Force the change of the cluster state.
    type: bool
    default: true
z
- name: Set cluster Online
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Get cluster state
      community.general.pacemaker_cluster:
        state: online
z
out:
  description: The output of the current state of the cluster. It returns a list of the nodes state.
  type: str
  sample: 'out: [["  overcloud-controller-0", " Online"]]}'
  returned: always
N)AnsibleModulez4Error: cluster is not currently running on this nodec                 H    g d}| j                  |      \  }}}|t        v ryy)N)pcsclusterstatusofflineonline)run_command_PCS_CLUSTER_DOWN)modulecmdrcouterrs        w/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/pacemaker_cluster.pyget_cluster_statusr   J   s,    
&C%%c*LBS
    c                     |dk(  rdgng }g d|z   }| j                  |      \  }}}|dk(  r| j                  d|d|       g }|j                         D ]"  }|j                  |j	                  d             $ |S )Nall)r   r	   zpcsd-status   $Command execution failed.
Command: `	`
Error: msg:)r   	fail_json
splitlinesappendsplit)	r   nodenode_lr   r   r   r   r
   os	            r   get_node_statusr&   S   s    eW2F
+f
4C%%c*LBS	QwVY[^_`F^^ $aggcl#$Mr   c                 r    g d}| j                  |      \  }}}|dk(  r| j                  d|d|       y y )N)r   resourcecleanupr   r   r   r   )r   r   )r   timeoutr   r   r   r   s         r   clean_clusterr+   _   sA    
(C%%c*LBS	QwVY[^_` r   c                    |dk(  rg d}|dk(  rg d}|r|dgz   }| j                        \  }}}|dk(  r| j                  d|d|	       t        j                         }d
}	t        j                         ||z   k  r.t        |       }
|
|k(  rd}	nt        j                         ||z   k  r.|	s| j                  d|z  	       y y )Nr   )r   r	   startr   )r   r	   stopz--forcer   r   r   r   FTz,Failed to set the state `%s` on the cluster
)r   r   timer   )r   stater*   forcer   r   r   r   treadycluster_states              r   set_clusterr5   f   s    )	(#C%%c*LBS	QwVY[^_`		AE
))+G
#*62E!E	 ))+G
#
 LPUVW r   c            	      0   t        t        dg d      t        d      t        dd      t        dd	      
      } t        | d	      }d}|j                  d   }|j                  d   }|j                  d   }|j                  d   }|dv r#|t        |      }||k(  r|j	                  ||       y |j
                  r|j	                  d	       t        ||||       t        |      }||k(  r|j	                  d	|       y |j                  d|z         y t        ||      }|D ]  }|d   j                         j                         |k(  r|j	                  ||       ;|j
                  r|j	                  d	       t        ||||       t        ||      }|j	                  d	|        y |dk(  r|j
                  r|j	                  d	       t        |d||       t        |      }|dk(  rEt        |d||       t        |      }|dk(  r|j	                  d	|       y |j                  d       y |j                  d       y |dk(  rI|j
                  r|j	                  d	       t        ||       t        |      }|j	                  d	|       y y )Nstr)r   r   restartr)   )typechoices)r9   inti,  )r9   defaultboolT)r0   r#   r*   r1   )supports_check_modeFr0   r#   r1   r*   )r   r   )changedr   )r?   zFail to bring the cluster %sr   r   r8   r   r   zGFailed during the restart of the cluster, the cluster cannot be startedzGFailed during the restart of the cluster, the cluster cannot be stoppedr)   )dictr   paramsr   	exit_json
check_moder5   r   r&   striplowerr+   )	argument_specr   r?   r0   r#   r1   r*   r4   
node_states	            r   mainrH   |   s   'RSu%--	M  F GMM'"E== DMM'"EmmI&G%%<.v6M%  m D$$$$T$2FE7E: 26 : E)$$T}$E$$)G%)O$P+FD9M+ 	F
a=&&(..0E9$$W-$H(((((6w>$3FD$AM$$T}$E	F 
)	T*FIw6*62I%'59.v6M(  = A  %n o!jk	)	T*fg&*62=9 
r   __main__)r   )
__future__r   r   r   r9   __metaclass__DOCUMENTATIONEXAMPLESRETURNr/   ansible.module_utils.basicr   r   r   r&   r+   r5   rH   __name__ r   r   <module>rR      sk    A @#J
  4 K 	aX,C:L zF r   