
    Vh                     v    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  G d de
      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona  
module: pacemaker_resource
short_description: Manage pacemaker resources
author:
  - Dexter Le (@munchtoast)
version_added: 10.5.0
description:
  - This module can manage resources in a Pacemaker cluster 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 for cluster resource.
    choices: [present, absent, enabled, disabled]
    default: present
    type: str
  name:
    description:
      - Specify the resource name to create.
    required: true
    type: str
  resource_type:
    description:
      - Resource type to create.
    type: dict
    suboptions:
      resource_name:
        description:
          - Specify the resource type name.
        type: str
      resource_standard:
        description:
          - Specify the resource type standard.
        type: str
      resource_provider:
        description:
          - Specify the resource type providers.
        type: str
  resource_option:
    description:
      - Specify the resource option to create.
    type: list
    elements: str
    default: []
  resource_operation:
    description:
      - List of operations to associate with resource.
    type: list
    elements: dict
    default: []
    suboptions:
      operation_action:
        description:
          - Operation action to associate with resource.
        type: str
      operation_option:
        description:
          - Operation option to associate with action.
        type: list
        elements: str
  resource_meta:
    description:
      - List of meta to associate with resource.
    type: list
    elements: str
  resource_argument:
    description:
      - Action to associate with resource.
    type: dict
    suboptions:
      argument_action:
        description:
          - Action to apply to resource.
        type: str
        choices: [clone, master, group, promotable]
      argument_option:
        description:
          - Options to associate with resource action.
        type: list
        elements: str
  wait:
    description:
      - Timeout period for polling the resource creation.
    type: int
    default: 300
a4  
---
- name: Create pacemaker resource
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Create virtual-ip resource
      community.general.pacemaker_resource:
        state: present
        name: virtual-ip
        resource_type:
          resource_name: IPaddr2
        resource_option:
          - "ip=[192.168.2.1]"
        resource_argument:
          argument_action: group
          argument_option:
            - master
        resource_operation:
          - operation_action: monitor
            operation_option:
              - interval=20
z
cluster_resources:
  description: The cluster resource output message.
  type: str
  sample: "Assumed agent name ocf:heartbeat:IPaddr2 (deduced from IPaddr2)"
  returned: always
)StateModuleHelper)pacemaker_runnerc                      e Zd Z e e eddg d       edd       ed e ed       ed       ed      	      
       edd e              edd e        e ed       edd                   edd       ed e edg d       edd            
       edd            ddddgfgd      ZdZdZd Zd$dZ	d Z
d Zd  Zd! Zd" Zy#)%PacemakerResourcestrpresent)r   absentenableddisabled)typedefaultchoicesT)r   requireddict)r   )resource_nameresource_standardresource_provider)r   optionslist)r   elementsr   )r   r   )operation_actionoperation_option)r   r   r   r   )clonemastergroup
promotable)r   r   )argument_actionargument_optioninti,  )r   r   )statenameresource_typeresource_optionresource_operationresource_metaresource_argumentwaitr#   r%   r&   )argument_specrequired_ifsupports_check_modeFc                     t        | j                  d      | _        | j                  j	                  d| j                                | j                  j	                  d| j                  j                  dd       y )Nresource)
cli_actionprevious_valuevalueT)changediff)r   modulerunnervarsset_getr1   )selfs    x/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/pacemaker_resource.py__init_module__z!PacemakerResource.__init_module__   sO    &t{{zJ		&		4		gtyy774P    c                       fd}|S )Nc                     r,| dk7  r'|r%|vr!j                  dj                  | |             |j                         }|dk(  rd S |S )Nr   z#pcs failed with error (rc={0}): {1} )do_raiseformatrstrip)rcouterrfail_on_errignore_err_msgr:   s      r;   processz:PacemakerResource._process_command_output.<locals>.process   sK    rQw3>3LCJJ2sST**,C"94-#-r=    )r:   rG   rH   rI   s   ``` r;   _process_command_outputz)PacemakerResource._process_command_output   s    	.
 r=   c                     | j                  d| j                  d            5 }|j                  d      cd d d        S # 1 sw Y   y xY w)N
state nameF)output_processstatus)r#   )r6   rK   runr:   ctxs     r;   r9   zPacemakerResource._get   sD    [[d6R6RSX6Y[Z 	+^a777*	+ 	+ 	+s	   ?Ac                    | j                  d| j                  dd      d      5 }|j                          | j                  j	                  d| j                                |j                  | j                  _        |j                  | j                  _	        |j                  | j                  _
        d d d        y # 1 sw Y   y xY w)NrM   Tzdoes not existrN   check_mode_skipr2   r6   rK   rP   r7   r8   r9   results_outstdoutresults_errstderrcmdrQ   s     r;   state_absentzPacemakerResource.state_absent   s    [[d6R6RSWYi6j  }A[  B 	$  FIGGIIIMM'499;/"DII"DIIGGDIIM	$ 	$ 	$   BB::Cc                    | j                  d| j                  dd      d      5 }|j                          | j                  j	                  d| j                                |j                  | j                  _        |j                  | j                  _	        |j                  | j                  _
        d d d        y # 1 sw Y   y xY w)Nz`state name resource_type resource_option resource_operation resource_meta resource_argument waitTzalready existsrT   r2   rV   rQ   s     r;   state_presentzPacemakerResource.state_present   s    [[r#;;DBRS $  & 	$ *-GGIIIMM'499;/"DII"DIIGGDIIM	$ 	$ 	$r]   c                    | j                  d| j                  dd      d      5 }|j                          | j                  j	                  d| j                                |j                  | j                  _        |j                  | j                  _	        |j                  | j                  _
        d d d        y # 1 sw Y   y xY w)NrM   TStartingrT   r2   rV   rQ   s     r;   state_enabledzPacemakerResource.state_enabled   s    [[d6R6RSWYc6dvz[{ 	$  @CGGIIIMM'499;/"DII"DIIGGDIIM	$ 	$ 	$r]   c                    | j                  d| j                  dd      d      5 }|j                          | j                  j	                  d| j                                |j                  | j                  _        |j                  | j                  _	        |j                  | j                  _
        d d d        y # 1 sw Y   y xY w)NrM   TStoppedrT   r2   rV   rQ   s     r;   state_disabledz PacemakerResource.state_disabled   s    [[d6R6RSWYb6cuy[z 	$  BGGIIIMM'499;/"DII"DIIGGDIIM	$ 	$ 	$r]   N)r@   )__name__
__module____qualname__r   r   r5   use_old_vardictdefault_stater<   rK   r9   r\   r_   rb   re   rJ   r=   r;   r	   r	      s   E9 ?< =540FD"."&E"2"&E"25 
 !fudfM#&$&Z^!%5!1!%6E!B[   FU;" $%9c d $&5 A9  5#.'
* y?<M*NOP /F2 OMQ
+$	$$$r=   r	   c                  ,    t         j                          y )N)r	   executerJ   r=   r;   mainrm      s    r=   __main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNHansible_collections.community.general.plugins.module_utils.module_helperr   Dansible_collections.community.general.plugins.module_utils.pacemakerr   r	   rm   rf   rJ   r=   r;   <module>rv      s\    A @[z0
 g aO$) O$d  zF r=   