summaryrefslogtreecommitdiffstats
path: root/ansible_collections/ngine_io/exoscale/plugins
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:35 +0000
commit7fec0b69a082aaeec72fee0612766aa42f6b1b4d (patch)
treeefb569b86ca4da888717f5433e757145fa322e08 /ansible_collections/ngine_io/exoscale/plugins
parentReleasing progress-linux version 7.7.0+dfsg-3~progress7.99u1. (diff)
downloadansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.tar.xz
ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.zip
Merging upstream version 9.4.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/ngine_io/exoscale/plugins')
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py3
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py7
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py5
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py6
-rw-r--r--ansible_collections/ngine_io/exoscale/plugins/modules/instance_rdns_record.py186
5 files changed, 200 insertions, 7 deletions
diff --git a/ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py b/ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py
index 52ea2cd49..28081074f 100644
--- a/ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py
+++ b/ansible_collections/ngine_io/exoscale/plugins/doc_fragments/exoscale.py
@@ -4,6 +4,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
+
__metaclass__ = type
@@ -38,7 +39,7 @@ options:
description:
- Validate SSL certs of the Exoscale DNS API.
type: bool
- default: yes
+ default: true
requirements:
- python >= 2.6
notes:
diff --git a/ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py b/ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py
index 44933b1b0..9e1d32fc7 100644
--- a/ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py
+++ b/ansible_collections/ngine_io/exoscale/plugins/module_utils/exoscale.py
@@ -2,13 +2,14 @@
# Copyright (c) 2016, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
+
__metaclass__ = type
import os
-from ansible.module_utils.six.moves import configparser
-from ansible.module_utils.six import integer_types, string_types
from ansible.module_utils._text import to_native, to_text
+from ansible.module_utils.six import integer_types, string_types
+from ansible.module_utils.six.moves import configparser
from ansible.module_utils.urls import fetch_url
EXO_DNS_BASEURL = "https://api.exoscale.ch/dns/v1"
@@ -80,7 +81,7 @@ class ExoDns(object):
# Look at CLOUDSTACK_CONFIG first if present
if 'CLOUDSTACK_CONFIG' in os.environ:
paths += (os.path.expanduser(os.environ['CLOUDSTACK_CONFIG']),)
- if not any([os.path.exists(c) for c in paths]):
+ if not any([os.path.exists(c) for c in paths]): # pylint: disable=use-a-generator
self.module.fail_json(msg="Config file not found. Tried : %s" % ", ".join(paths))
conf = configparser.ConfigParser()
diff --git a/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py b/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py
index 334c5c02b..a8573b51f 100644
--- a/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py
+++ b/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_domain.py
@@ -5,6 +5,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
+
__metaclass__ = type
@@ -132,7 +133,9 @@ exo_dns_domain:
'''
from ansible.module_utils.basic import AnsibleModule
-from ..module_utils.exoscale import ExoDns, exo_dns_argument_spec, exo_dns_required_together
+
+from ..module_utils.exoscale import (ExoDns, exo_dns_argument_spec,
+ exo_dns_required_together)
class ExoDnsDomain(ExoDns):
diff --git a/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py b/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py
index 8da3491eb..8153ff849 100644
--- a/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py
+++ b/ansible_collections/ngine_io/exoscale/plugins/modules/exo_dns_record.py
@@ -5,6 +5,7 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
+
__metaclass__ = type
@@ -56,7 +57,7 @@ options:
- Only allowed for a few record types, e.g. C(record_type=A), C(record_type=NS) or C(record_type=MX).
- I(content) will not be updated, instead it is used as a key to find existing records.
type: bool
- default: no
+ default: false
state:
description:
- State of the record.
@@ -186,8 +187,9 @@ exo_dns_record:
'''
from ansible.module_utils.basic import AnsibleModule
-from ..module_utils.exoscale import ExoDns, exo_dns_argument_spec, exo_dns_required_together
+from ..module_utils.exoscale import (ExoDns, exo_dns_argument_spec,
+ exo_dns_required_together)
EXO_RECORD_TYPES = [
'A',
diff --git a/ansible_collections/ngine_io/exoscale/plugins/modules/instance_rdns_record.py b/ansible_collections/ngine_io/exoscale/plugins/modules/instance_rdns_record.py
new file mode 100644
index 000000000..863370d17
--- /dev/null
+++ b/ansible_collections/ngine_io/exoscale/plugins/modules/instance_rdns_record.py
@@ -0,0 +1,186 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# (c) 2019, Lorenz Schori <lo@znerol.ch>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+
+DOCUMENTATION = '''
+---
+module: instance_rdns_record
+short_description: Manages reverse DNS records for Exoscale compute instances.
+description:
+ - Set and unset reverse DNS record on Exoscale instance.
+version_added: "1.1.0"
+author: "Lorenz Schori (@znerol)"
+options:
+ name:
+ description:
+ - Name of the compute instance
+ required: true
+ type: str
+ content:
+ aliases: [ 'value' ]
+ description:
+ - Reverse DSN name of the compute instance. Required if state=present.
+ type: str
+ state:
+ description:
+ - State of the record.
+ default: present
+ choices: [ 'present', 'absent' ]
+ type: str
+extends_documentation_fragment: ngine_io.cloudstack.cloudstack
+'''
+
+EXAMPLES = '''
+- name: Set the reverse DNS for a compute instance
+ ngine_io.exoscale.instance_rdns_record:
+ name: web-vm-1
+ content: www.example.com
+
+- name: Delete the reverse DNS for a compute instance
+ ngine_io.exoscale.instance_rdns_record:
+ name: web-vm-1
+ state: absent
+'''
+
+RETURN = '''
+---
+instance_rdns_domain:
+ description: Reverse DSN name of the compute instance
+ returned: success
+ type: str
+'''
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible_collections.ngine_io.cloudstack.plugins.module_utils.cloudstack import (
+ AnsibleCloudStack, cs_argument_spec, cs_required_together)
+
+
+class InstanceRdnsRecord(AnsibleCloudStack):
+
+ def __init__(self, module):
+ super(InstanceRdnsRecord, self).__init__(module)
+
+ self.name = self.module.params.get('name')
+ self.content = self.module.params.get('content')
+
+ self.returns = {
+ 'domain': 'domain'
+ }
+
+ self.instance = None
+
+ def get_instance(self):
+ instance = self.instance
+ if not instance:
+ args = {
+ 'fetch_list': True,
+ }
+ # Do not pass zoneid, as the instance name must be unique across
+ # zones.
+ instances = self.query_api('listVirtualMachines', **args)
+ if instances:
+ for v in instances:
+ if self.name.lower() in [v['name'].lower(), v['displayname'].lower(), v['id']]:
+ self.instance = v
+ break
+
+ return self.instance
+
+ def get_record(self, instance):
+ result = {}
+
+ res = self.query_api('queryReverseDnsForVirtualMachine',
+ id=instance['id'])
+ nics = res['virtualmachine'].get('nic', [])
+
+ defaultnics = [nic for nic in nics if nic.get('isdefault', False)]
+
+ if len(defaultnics) > 0:
+ domains = [record['domainname'] for record
+ in defaultnics[0].get('reversedns', [])
+ if 'domainname' in record]
+
+ if len(domains) > 0:
+ result = {
+ 'domainname': domains[0],
+ }
+
+ return result
+
+ def present_record(self):
+ instance = self.get_instance()
+
+ if not instance:
+ self.module.fail_json(
+ msg="No compute instance with name=%s found. " % self.name)
+
+ data = {
+ 'domainname': self.content,
+ }
+ record = self.get_record(instance)
+ if self.has_changed(data, record):
+ self.result['changed'] = True
+ self.result['diff']['before'] = record
+ self.result['diff']['after'] = data
+ if not self.module.check_mode:
+ self.query_api('updateReverseDnsForVirtualMachine',
+ id=instance['id'],
+ domainname=data['domainname'])
+
+ return data
+
+ def absent_record(self):
+ instance = self.get_instance()
+
+ if instance:
+ record = self.get_record(instance)
+ if record:
+ self.result['diff']['before'] = record
+ self.result['changed'] = True
+ if not self.module.check_mode:
+ self.query_api('deleteReverseDnsFromVirtualMachine',
+ id=instance['id'])
+
+ return record
+
+ def get_result(self, resource):
+ self.result['instance_rdns_domain'] = resource
+ return self.result
+
+
+def main():
+ argument_spec = cs_argument_spec()
+ argument_spec.update(dict(
+ name=dict(required=True),
+ content=dict(aliases=['value']),
+ state=dict(choices=['present', 'absent'], default='present'),
+ ))
+
+ module = AnsibleModule(
+ argument_spec=argument_spec,
+ required_together=cs_required_together(),
+ required_if=[
+ ('state', 'present', ['content']),
+ ],
+ supports_check_mode=True,
+ )
+
+ instance_rdns_record = InstanceRdnsRecord(module)
+ if module.params.get('state') == "present":
+ record = instance_rdns_record.present_record()
+ else:
+ record = instance_rdns_record.absent_record()
+
+ result = instance_rdns_record.get_result(record)
+ module.exit_json(**result)
+
+
+if __name__ == '__main__':
+ main()