1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-29 06:58:55 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -114,95 +114,74 @@ from ansible_collections.community.general.plugins.module_utils.univention_umc i
def convert_time(time):
"""Convert a time in seconds into the biggest unit"""
units = [
(24 * 60 * 60, 'days'),
(60 * 60, 'hours'),
(60, 'minutes'),
(1, 'seconds'),
(24 * 60 * 60, "days"),
(60 * 60, "hours"),
(60, "minutes"),
(1, "seconds"),
]
if time == 0:
return ('0', 'seconds')
return ("0", "seconds")
for unit in units:
if time >= unit[0]:
return (f'{time // unit[0]}', unit[1])
return (f"{time // unit[0]}", unit[1])
def main():
module = AnsibleModule(
argument_spec=dict(
type=dict(required=True,
type='str'),
zone=dict(required=True,
aliases=['name'],
type='str'),
nameserver=dict(default=[],
type='list',
elements='str'),
interfaces=dict(default=[],
type='list',
elements='str'),
refresh=dict(default=3600,
type='int'),
retry=dict(default=1800,
type='int'),
expire=dict(default=604800,
type='int'),
ttl=dict(default=600,
type='int'),
contact=dict(default='',
type='str'),
mx=dict(default=[],
type='list',
elements='str'),
state=dict(default='present',
choices=['present', 'absent'],
type='str')
type=dict(required=True, type="str"),
zone=dict(required=True, aliases=["name"], type="str"),
nameserver=dict(default=[], type="list", elements="str"),
interfaces=dict(default=[], type="list", elements="str"),
refresh=dict(default=3600, type="int"),
retry=dict(default=1800, type="int"),
expire=dict(default=604800, type="int"),
ttl=dict(default=600, type="int"),
contact=dict(default="", type="str"),
mx=dict(default=[], type="list", elements="str"),
state=dict(default="present", choices=["present", "absent"], type="str"),
),
supports_check_mode=True,
required_if=([
('state', 'present', ['nameserver', 'interfaces'])
])
required_if=([("state", "present", ["nameserver", "interfaces"])]),
)
type = module.params['type']
zone = module.params['zone']
nameserver = module.params['nameserver']
interfaces = module.params['interfaces']
refresh = module.params['refresh']
retry = module.params['retry']
expire = module.params['expire']
ttl = module.params['ttl']
contact = module.params['contact']
mx = module.params['mx']
state = module.params['state']
type = module.params["type"]
zone = module.params["zone"]
nameserver = module.params["nameserver"]
interfaces = module.params["interfaces"]
refresh = module.params["refresh"]
retry = module.params["retry"]
expire = module.params["expire"]
ttl = module.params["ttl"]
contact = module.params["contact"]
mx = module.params["mx"]
state = module.params["state"]
changed = False
diff = None
obj = list(ldap_search(
f'(&(objectClass=dNSZone)(zoneName={zone}))',
attr=['dNSZone']
))
obj = list(ldap_search(f"(&(objectClass=dNSZone)(zoneName={zone}))", attr=["dNSZone"]))
exists = bool(len(obj))
container = f'cn=dns,{base_dn()}'
dn = f'zoneName={zone},{container}'
if contact == '':
contact = f'root@{zone}.'
container = f"cn=dns,{base_dn()}"
dn = f"zoneName={zone},{container}"
if contact == "":
contact = f"root@{zone}."
if state == 'present':
if state == "present":
try:
if not exists:
obj = umc_module_for_add(f'dns/{type}', container)
obj = umc_module_for_add(f"dns/{type}", container)
else:
obj = umc_module_for_edit(f'dns/{type}', dn)
obj['zone'] = zone
obj['nameserver'] = nameserver
obj['a'] = interfaces
obj['refresh'] = convert_time(refresh)
obj['retry'] = convert_time(retry)
obj['expire'] = convert_time(expire)
obj['ttl'] = convert_time(ttl)
obj['contact'] = contact
obj['mx'] = mx
obj = umc_module_for_edit(f"dns/{type}", dn)
obj["zone"] = zone
obj["nameserver"] = nameserver
obj["a"] = interfaces
obj["refresh"] = convert_time(refresh)
obj["retry"] = convert_time(retry)
obj["expire"] = convert_time(expire)
obj["ttl"] = convert_time(ttl)
obj["contact"] = contact
obj["mx"] = mx
diff = obj.diff()
if exists:
for k in obj.keys():
@ -216,27 +195,19 @@ def main():
elif changed:
obj.modify()
except Exception as e:
module.fail_json(
msg=f'Creating/editing dns zone {zone} failed: {e}'
)
module.fail_json(msg=f"Creating/editing dns zone {zone} failed: {e}")
if state == 'absent' and exists:
if state == "absent" and exists:
try:
obj = umc_module_for_edit(f'dns/{type}', dn)
obj = umc_module_for_edit(f"dns/{type}", dn)
if not module.check_mode:
obj.remove()
changed = True
except Exception as e:
module.fail_json(
msg=f'Removing dns zone {zone} failed: {e}'
)
module.fail_json(msg=f"Removing dns zone {zone} failed: {e}")
module.exit_json(
changed=changed,
diff=diff,
zone=zone
)
module.exit_json(changed=changed, diff=diff, zone=zone)
if __name__ == '__main__':
if __name__ == "__main__":
main()