
    Vh                      R    d Z dZdZddlmZ  G d de      Zd Zedk(  r e        y	y	)
a#  
---
module: dns_zone
short_description: Manage a OpenStack DNS zone.
author: OpenStack Ansible SIG
description:
    - Create, delete or update a OpenStack DNS zone.
options:
  description:
    description:
      - Zone description.
    type: str
  email:
    description:
      - Email of the zone owner.
      - Only applies if I(type) is C(primary).
    type: str
  masters:
    description:
      - Master nameservers
      - Only applies if I(type) is C(secondary).
    type: list
    elements: str
  name:
    description:
      - Name of the DNS zone.
    required: true
    type: str
  state:
    description:
      - Whether the zone should be C(present) or C(absent).
    choices: ['present', 'absent']
    default: present
    type: str
  ttl:
    description:
      -  TTL (Time To Live) value in seconds.
    type: int
  type:
    description:
      - Zone type.
      - This attribute cannot be updated.
    choices: ['primary', 'secondary']
    type: str
    aliases: ['zone_type']
extends_documentation_fragment:
  - openstack.cloud.openstack
a  
- name: Create DNS zone example.net.
  openstack.cloud.dns_zone:
    cloud: mycloud
    state: present
    name: example.net.
    type: primary
    email: test@example.net
    description: Test zone
    ttl: 3600

- name: Set TTL on DNS zone example.net.
  openstack.cloud.dns_zone:
    cloud: mycloud
    state: present
    name: example.net.
    ttl: 7200

- name: Delete zone example.net.
  openstack.cloud.dns_zone:
    cloud: mycloud
    state: absent
    name: example.net.
aH
  
zone:
  description: Dictionary describing the zone.
  returned: On success when I(state) is C(present).
  type: dict
  contains:
    action:
      description: Current action in progress on the resource.
      type: str
      sample: "CREATE"
    attributes:
      description: Key value pairs of information about this zone, and the
                   pool the user would like to place the zone in. This
                   information can be used by the scheduler to place zones on
                   the correct pool.
      type: dict
      sample: {"tier": "gold", "ha": "true"}
    created_at:
      description: Date / Time when resource was created.
      type: str
      sample: "2014-07-07T18:25:31.275934"
    description:
      description: Description for this zone.
      type: str
      sample: "This is an example zone."
    email:
      description: E-mail for the zone. Used in SOA records for the zone.
      type: str
      sample: "test@example.org"
    id:
      description: ID for the resource.
      type: int
      sample: "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
    links:
      description: Links to the resource, and other related resources. When a
                   response has been broken into pages, we will include a next
                   link that should be followed to retrieve all results.
      type: dict
      sample: {"self": "https://127.0.0.1:9001/v2/zones/a86dba...d5e86f3ca3"}
    masters:
      description: The servers to slave from to get DNS information.
                   Mandatory for secondary zones.
      type: list
      sample: "[]"
    name:
      description: DNS Name for the zone.
      type: str
      sample: "test.test."
    pool_id:
      description: ID for the pool hosting this zone.
      type: str
      sample: "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3"
    project_id:
      description: ID for the project that owns the resource.
      type: str
      sample: "4335d1f0-f793-11e2-b778-0800200c9a66"
    serial:
      description: Current serial number for the zone.
      type: int
      sample: 1404757531
    status:
      description: Status of the resource.
      type: str
      sample: "ACTIVE"
    ttl:
      description: TTL (Time to Live) for the zone.
      type: int
      sample: 7200
    type:
      description: Type of zone. PRIMARY is controlled by Designate,
                   SECONDARY zones are slaved from another DNS Server.
                   Defaults to PRIMARY.
      type: str
      sample: "PRIMARY"
    updated_at:
      description: Date / Time when resource last updated.
      type: str
      sample: "2014-07-07T18:25:31.275934"
    )OpenStackModulec                       e Zd Z e e        e        edd       ed       edddg       ed	
       eddgdg            Zd Zd Zd Zd Zd Z	d Z
y)DnsZoneModuleliststr)typeelementsT)requiredpresentabsent)defaultchoicesint)r   primary	secondary	zone_type)r   aliases)descriptionemailmastersnamestatettlr   c                    | j                   d   }| j                   d   }| j                  j                  j                  |      }| j                  j
                  r"| j                  | j                  ||             |dk(  r6|s4| j                         }| j                  d|j                  d      	       y |dk(  rT|rR| j                  |      }|r| j                  ||      }| j                  t        |      |j                  d      	       y |d
k(  r&|r$| j                  |       | j                  d       y |d
k(  r|s| j                  d       y y y )Nr   r   )
name_or_id)changedr   TF)computed)r   zoner   )paramsconndns	find_zoneansible
check_mode	exit_json_will_change_createto_dict_build_update_updatebool_delete)selfr   r   r   updates        l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/dns_zone.pyrunzDnsZoneModule.run   s1   G$[[(
yy}}&&*&=<<""NN4#4#4UD#ANBId<<>DNN4 $e <  > iD''-F||D&1NN4< $e <  > h4LLNN4N(htNN5N) (,    c                 F     i }t         fddD              }|r||d<   |S )Nc              3      K   | ]9  }j                   |   (j                   |   |   k7  r|j                   |   f ; y wNr   ).0kr-   r   s     r/   	<genexpr>z.DnsZoneModule._build_update.<locals>.<genexpr>   sH      9![[^7"kk!nQ7 dkk!n- 9s   ?A)r   r   r   r   
attributes)dictr-   r   r.   r9   s   ``  r/   r)   zDnsZoneModule._build_update   s3     9#M9 9

 #-F< r1   c                 f    t         fddD              }d|v r|d   j                         |d<     j                  j                  j                  d	i |} j
                  d   rL j                  j                  j                   j                  j                  |ddg j
                  d          |S )
Nc              3   ^   K   | ]$  }j                   |   |j                   |   f & y wr4   r5   )r6   r7   r-   s     r/   r8   z(DnsZoneModule._create.<locals>.<genexpr>   s4      5Q3 $++a.) 5s   *-)r   r   r   r   r   r   r   waitactiveerrortimeoutstatusfailuresr>    )	r:   upperr    r!   create_zoner   sdkresourcewait_for_status)r-   kwargsr   s   `  r/   r'   zDnsZoneModule._create   s     5 /5 5
 V#F^113F6N(tyy}}((262;;vHH--		t![[+	 . - r1   c                 6   | j                   j                  j                  |j                         | j                  j
                  j                  | j                  d   d      D ]3  }| j                   j                  j                  |j                        3 y  y )NrA   z%Timeout waiting for zone to be absent)rA   message)	r    r!   delete_zoneidrH   utilsiterate_timeoutr   r"   )r-   r   counts      r/   r,   zDnsZoneModule._delete   st    		!!$''*XX^^33KK	*; 4 
 	E yy}}&&tww/7	r1   c                 D   |j                  d      }|r1 | j                  j                  j                  |j                  fi |}| j
                  d   rL| j                  j                  j                  | j                  j                  |ddg| j
                  d          |S )Nr9   r>   r?   r@   rA   rB   )	getr    r!   update_zonerO   r   rH   rI   rJ   r;   s       r/   r*   zDnsZoneModule._update   s    ZZ-
,499==,,TWWC
CD;;vHH--		t![[+	 . - r1   c                 f    |dk(  r|sy|dk(  r|rt        | j                  |            S |dk(  r|ryy)Nr   Tr   F)r+   r)   )r-   r   r   s      r/   r&   zDnsZoneModule._will_change  sA    IdiD**4011h4 r1   N)__name__
__module____qualname__r:   argument_specr0   r)   r'   r,   r*   r&   rE   r1   r/   r   r      so    Ff&514 9x.CDe9k2[MJM*B*	r1   r   c                  &    t               }  |         y r4   )r   )modules    r/   mainr]     s    _F
Hr1   __main__N)DOCUMENTATIONEXAMPLESRETURNBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   r]   rW   rE   r1   r/   <module>rc      sK   /b2N
` _pO pf
 zF r1   