
    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 dlmZ  G d d	e      Zd
 Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona]  
module: ipa_dnszone
author: Fran Fitzpatrick (@fxfitz)
short_description: Manage FreeIPA DNS Zones
description:
  - Add and delete an IPA DNS Zones using IPA API.
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  zone_name:
    description:
      - The DNS zone name to which needs to be managed.
    required: true
    type: str
  state:
    description: State to ensure.
    required: false
    default: present
    choices: ["absent", "present"]
    type: str
  dynamicupdate:
    description: Apply dynamic update to zone.
    default: false
    type: bool
  allowsyncptr:
    description: Allow synchronization of forward and reverse records in the zone.
    default: false
    type: bool
    version_added: 4.3.0
extends_documentation_fragment:
  - community.general.ipa.documentation
  - community.general.attributes
a  
- name: Ensure dns zone is present
  community.general.ipa_dnszone:
    ipa_host: spider.example.com
    ipa_pass: Passw0rd!
    state: present
    zone_name: example.com

- name: Ensure dns zone is present and is dynamic update
  community.general.ipa_dnszone:
    ipa_host: spider.example.com
    ipa_pass: Passw0rd!
    state: present
    zone_name: example.com
    dynamicupdate: true

- name: Ensure that dns zone is removed
  community.general.ipa_dnszone:
    zone_name: example.com
    ipa_host: localhost
    ipa_user: admin
    ipa_pass: topsecret
    state: absent

- name: Ensure dns zone is present and is allowing sync
  community.general.ipa_dnszone:
    ipa_host: spider.example.com
    ipa_pass: Passw0rd!
    state: present
    zone_name: example.com
    allowsyncptr: true
zW
zone:
  description: DNS zone as returned by IPA API.
  returned: always
  type: dict
)AnsibleModule)	IPAClientipa_argument_spec)	to_nativec                   >     e Zd Z fdZddZddZddZddZ xZS )	DNSZoneIPAClientc                 2    t         t        |   ||||       y N)superr   __init__)selfmodulehostportprotocol	__class__s        q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ipa_dnszone.pyr   zDNSZoneIPAClient.__init__^   s    .vtT8L    c                 Z    d|d}||j                  |       | j                  d||      S )Ntrue)allidnsnamednszone_findmethodnameitemupdate
_post_jsonr   	zone_namedetailsitemss       r   r   zDNSZoneIPAClient.dnszone_finda   s@    &*LL!!  
 	
r   c                 T    i }||j                  |       | j                  d||      S )Ndnszone_addr   r!   r$   s       r   r)   zDNSZoneIPAClient.dnszone_addm   8    LL!   
 	
r   c                 T    i }||j                  |       | j                  d||      S )Ndnszone_modr   r!   r$   s       r   r,   zDNSZoneIPAClient.dnszone_modx   r*   r   c                 *    | j                  d|i       S )Ndnszone_delr   )r#   )r   r%   record_namer&   s       r   r.   zDNSZoneIPAClient.dnszone_del   s     yr  ; 	;r   r   )NN)NNN)	__name__
__module____qualname__r   r   r)   r,   r.   __classcell__)r   s   @r   r   r   ]   s    M

	
	
;r   r   c                 \   | j                   d   }| j                   d   }| j                   d   }| j                   d   }d}|j                  |      }|dk(  r|s%d}| j                  s|j                  |||d	       n|d
   d   t	        |      j                         k7  s3|j                  d      rG|d   d   t	        |      j                         k7  r%d}| j                  s<|j                  |||d	       n%d}n"|r d}| j                  s|j                  |       ||j                  |      fS )Nr%   statedynamicupdateallowsyncptrFpresentT)idnsallowdynupdateidnsallowsyncptr)r%   r&   r9   r   r:   )r%   )	paramsr   
check_moder)   struppergetr,   r.   )r   clientr%   r5   r6   r7   changedipa_dnszones           r   ensurerC      sR   k*IMM'"EMM/2M==0LG %%i0K	G$$""YWd  {G  AH"  I-.q1S5G5M5M5OO 23DV8WXY8Z^abn^o^u^u^w8wG$$""YWd  {G  AH"  IG
 G$$""Y"7F''	222r   c            
      ,   t               } | j                  t        dd      t        ddddg      t        ddd	      t        ddd	      
       t        | d      }t	        ||j
                  d   |j
                  d   |j
                  d         }	 |j                  |j
                  d   |j
                  d          t        ||      \  }}|j                  ||       y # t        $ r%}|j                  t        |             Y d }~y d }~ww xY w)Nr=   T)typerequiredr8   absent)rE   defaultchoicesboolF)rE   rF   rH   )r%   r5   r6   r7   )argument_specsupports_check_modeipa_hostipa_portipa_prot)r   r   r   r   ipa_useripa_pass)usernamepassword)rA   zone)msg)r   r"   dictr   r   r;   loginrC   	exit_json	Exception	fail_jsonr	   )rK   r   r@   rA   rT   es         r   mainr\      s   %'M4UT#B#	IW_K`a'+%QV'W&*PU&V   /3F ]]:&]]:&z*	F+]]:.]]:. 	 	
 vv.t4 +Yq\**+s   AC% %	D.DD__main__N)
__future__r   r   r   rE   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   >ansible_collections.community.general.plugins.module_utils.ipar   r   +ansible.module_utils.common.text.convertersr	   r   rC   r\   r0    r   r   <module>rg      sa    A @#JB
 5 g A(;y (;V!3H+< zF r   