
    Vhh*                     p    d dl mZmZmZ eZdZdZd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_functiona5
  
module: ipwcli_dns

short_description: Manage DNS Records for Ericsson IPWorks using C(ipwcli)

version_added: '0.2.0'

description:
  - Manage DNS records for the Ericsson IPWorks DNS server. The module will use the C(ipwcli) to deploy the DNS records.
requirements:
  - ipwcli (installed on Ericsson IPWorks)

notes:
  - To make the DNS record changes effective, you need to run C(update dnsserver) on the ipwcli.
extends_documentation_fragment:
  - community.general.attributes

attributes:
  check_mode:
    support: full
  diff_mode:
    support: none

options:
  dnsname:
    description:
      - Name of the record.
    required: true
    type: str
  type:
    description:
      - Type of the record.
    required: true
    type: str
    choices: [NAPTR, SRV, A, AAAA]
  container:
    description:
      - Sets the container zone for the record.
    required: true
    type: str
  address:
    description:
      - The IP address for the A or AAAA record.
      - Required for O(type=A) or O(type=AAAA).
    type: str
  ttl:
    description:
      - Sets the TTL of the record.
    type: int
    default: 3600
  state:
    description:
      - Whether the record should exist or not.
    type: str
    choices: [absent, present]
    default: present
  priority:
    description:
      - Sets the priority of the SRV record.
    type: int
    default: 10
  weight:
    description:
      - Sets the weight of the SRV record.
    type: int
    default: 10
  port:
    description:
      - Sets the port of the SRV record.
      - Required for O(type=SRV).
    type: int
  target:
    description:
      - Sets the target of the SRV record.
      - Required for O(type=SRV).
    type: str
  order:
    description:
      - Sets the order of the NAPTR record.
      - Required for O(type=NAPTR).
    type: int
  preference:
    description:
      - Sets the preference of the NAPTR record.
      - Required for O(type=NAPTR).
    type: int
  flags:
    description:
      - Sets one of the possible flags of NAPTR record.
      - Required for O(type=NAPTR).
    type: str
    choices: ['S', 'A', 'U', 'P']
  service:
    description:
      - Sets the service of the NAPTR record.
      - Required for O(type=NAPTR).
    type: str
  replacement:
    description:
      - Sets the replacement of the NAPTR record.
      - Required for O(type=NAPTR).
    type: str
  username:
    description:
      - Username to login on ipwcli.
    type: str
    required: true
  password:
    description:
      - Password to login on ipwcli.
    type: str
    required: true

author:
  - Christian Wollinger (@cwollinger)
ag  
- name: Create A record
  community.general.ipwcli_dns:
    dnsname: example.com
    type: A
    container: ZoneOne
    address: 127.0.0.1

- name: Remove SRV record if exists
  community.general.ipwcli_dns:
    dnsname: _sip._tcp.test.example.com
    type: SRV
    container: ZoneOne
    ttl: 100
    state: absent
    target: example.com
    port: 5060

- name: Create NAPTR record
  community.general.ipwcli_dns:
    dnsname: test.example.com
    type: NAPTR
    preference: 10
    container: ZoneOne
    ttl: 100
    order: 10
    service: 'SIP+D2T'
    replacement: '_sip._tcp.test.example.com.'
    flags: S
za
record:
  description: The created record from the input params.
  type: str
  returned: always
)AnsibleModulec                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	ResourceRecordc                    || _         |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _	        |j                  d	   | _
        |j                  d
   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        y )Ndnsnametype	containeraddressttlstatepriorityweightporttargetorder
preferenceflagsservicereplacementusernamepassword)moduleparamsr
   dnstyper   r   r   r   r   r   r   r   r   r   r   r   r   userr   )selfr   s     p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/ipwcli_dns.py__init__zResourceRecord.__init__   s   }}Y/}}V,{3}}Y/==']]7+
j1mmH-MM&)	mmH-]]7+
 --5]]7+
}}Y/!==7MM*-	j1    c                     d| j                   d| j                  d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  d	}|S )
Nznaptrrecord 
 -set ttl=;container=z;order=z;preference=z;flags="z";service="z";replacement="")r
   r   r   r   r   r   r   r   r   records     r    create_naptrrecordz!ResourceRecord.create_naptrrecord   sS     \\488T^^TZZZ^ZdZdfjfrfrtx  uE  uEFr"   c                     d| j                   d| j                  d| j                  d| j                  d| j                  d| j
                  d| j                  }|S )Nz
srvrecord r$   r%   z
;priority=z;weight=z;port=z;target=)r
   r   r   r   r   r   r   r'   s     r    create_srvrecordzResourceRecord.create_srvrecord   sB     \\488T^^T]]DKKY]YbYbdhdodoqr"   c                     | j                   dk(  r8d| j                  d| j                  d| j                  d| j                  }|S d| j                  d| j                  d| j                  d| j                  }|S )NAAAAzaaaarecord  r$   r%   zarecord )r   r
   r   r   r   r'   s     r    create_arecordzResourceRecord.create_arecord   sn    <<6!DHLLRVR^R^`d`h`hjnjxjxyF  " BFt||]a]e]egkguguvFr"   c                    d|j                  dd      j                  dd      z  }| j                  j                  dd      d| j                  z  d	| j                  z  g}| j                  j                  ||
      \  }}}d|v r| j                  j                  d       d| j                  z  |v r|dk(  s,d| j                  z  |v r|dk(  sd| j                  z  |v r|dk(  rd|||fS d|||fS )Nzlist %s;&&setwhereipwcliT-user=%s-password=%sdataInvalid username or password;access denied at ipwcli login: Invalid username or passwordmsgz
ARecord %sr   zSRVRecord %szNAPTRRecord %sF)replacer   get_bin_pathr   r   run_command	fail_jsonr
   )r   r(   searchcmdrcouterrs          r    list_recordzResourceRecord.list_record   s    fnnS$7??wOPKK$$Xt4"T]]*

 {{..s.@C)S0KK!!&c!dDLL(C/B!GRVR^R^A^beAejlpqjq!DLL0C7B!GS#%%b#s""r"   c                 N   d|z  }| j                   j                  dd      d| j                  z  d| j                  z  g}| j                   j	                  ||      \  }}}d|v r| j                   j                  d	       d
|v r|||fS | j                   j                  d|       y )Nz	create %sr5   Tr6   r7   r8   r:   r;   r<   z1 object(s) created.zrecord creation failedr=   stderr)r   r?   r   r   r@   rA   r   r(   stdinrC   rD   rE   rF   s          r    deploy_recordzResourceRecord.deploy_record   s    v&KK$$Xt4"T]]*

 {{..s.?C)S0KK!!&c!d!S(sC<KK!!&>s!Kr"   c                    d|j                  dd      j                  dd      z  }| j                  j                  dd      d| j                  z  d	| j                  z  g}| j                  j                  ||
      \  }}}d|v r| j                  j                  d       d|v r|||fS | j                  j                  d|       y )Nz	delete %sr1   r2   r3   r4   r5   Tr6   r7   r8   r:   r;   r<   z1 object(s) were updated.zrecord deletion failedrI   )r>   r   r?   r   r   r@   rA   rK   s          r    delete_recordzResourceRecord.delete_record   s    v~~c48@@PQKK$$Xt4"T]]*

 {{..s.?C)S0KK!!&c!d&#-sC<KK!!&>s!Kr"   N)
__name__
__module____qualname__r!   r)   r+   r/   rG   rM   rO    r"   r    r   r      s'    2(#&L$Lr"   r   c                  `   t        d0i dt        dd      dt        ddg d      dt        dd      d	t        dd
      dt        dd
d      dt        ddddg      dt        dd
d      dt        dd
d      dt        dd
      dt        dd
      dt        dd
      dt        dd
      dt        dd
g d      dt        dd
      dt        dd
      dt        dd      dt        ddd       } t        d
d!d!d"d!#      }t        | dd$d	ggdd%d	ggdd&ddggdd'g d(ggd)      }t        |      }|j                  d'k(  r|j	                         }nN|j                  d&k(  r|j                         }n.|j                  d$k(  s|j                  d%k(  r|j                         }|j                        \  }}}}|r\|j                  dk(  rM|j                  r|j                  d*       |j                  |      \  }}}d|d+<   ||d,<   ||d-<   ||d.<   ||d/<   nw|s\|j                  dk(  rM|j                  r|j                  d*       |j                  |      \  }}}d|d+<   ||d,<   ||d-<   ||d.<   ||d/<   nd
|d+<   ||d,<   ||d-<   ||d.<   ||d/<    |j                  d0i | y )1Nr
   strT)r   requiredr   )Ar-   SRVNAPTR)r   rV   choicesr   r   Fr   inti  )r   rV   defaultr   presentabsent)r   r\   rZ   r   
   r   r   r   r   r   r   )SrW   UPr   r   r   r   )r   rV   no_log r   )changedstdoutrJ   rD   r(   rW   r-   rX   rY   )r   r   r   r   )argument_specrequired_ifsupports_check_mode)re   re   r(   rD   rf   rJ   rS   )dictr   r   r   r)   r+   r/   rG   r   
check_mode	exit_jsonrO   rM   )	module_argsresultr   r   r(   foundrD   rE   rF   s	            r    
run_modulerp     sD    %$/ut5RS ED1 %%0	
 eeT: y8Y:OP 55"= ; uu- / . UU3 7KL %%0 ee4  540!" 54=#K* F !S9+&Vi[)UVX./WOP	
 !	F &!D||w((*		&&(		 6$$&**62E2sCx'T*))&1C y!xtxxtzzY.T*))&1C y!xtxx!y!xtxxFvr"   c                      t                y )N)rp   rS   r"   r    mainrr   ^  s    Lr"   __main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   objectr   rp   rr   rP   rS   r"   r    <module>r{      s`    C Bsj>
 5`LV `LFOd zF r"   