From 172cce0b040f1686df04d73df9a350ddeb42739e Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Thu, 20 Apr 2023 22:09:58 +0200 Subject: [PATCH] renamed the modules --- CHANGELOG.rst | 18 +++++++- changelogs/changelog.yaml | 4 ++ plugins/module_utils/module.py | 22 +++++++--- plugins/modules/{systemd_link.py => link.py} | 14 ++++--- .../modules/{systemd_mount.py => mount.py} | 12 +++--- .../{systemd_network.py => network.py} | 41 +++++++++++++------ update_doc | 9 ++-- 7 files changed, 88 insertions(+), 32 deletions(-) rename plugins/modules/{systemd_link.py => link.py} (96%) rename plugins/modules/{systemd_mount.py => mount.py} (95%) rename plugins/modules/{systemd_network.py => network.py} (78%) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9aeaada..a2f725d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,10 +1,26 @@ ===================================== -sebastian.systemd 0.1.1 Release Notes +sebastian.systemd 0.1.3 Release Notes ===================================== .. contents:: Topics +v0.1.3 +====== + +Changelog +--------- + +renamed all modules to names without systemd_ prefix + +v0.1.2 +====== + +Changelog +--------- + +Pfad der auflösung für Tests und autodoc geändert, weil Mitogen sonst blockiert + v0.1.1 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index c2d125c..7e36226 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -25,3 +25,7 @@ releases: changes: release_date: '2023-04-15' release_summary: Pfad der auflösung für Tests und autodoc geändert, weil Mitogen sonst blockiert + 0.1.3: + changes: + release_date: "2023-04-20" + release_summary: "renamed all modules to names without systemd_ prefix" \ No newline at end of file diff --git a/plugins/module_utils/module.py b/plugins/module_utils/module.py index c3e03d5..4db5ace 100644 --- a/plugins/module_utils/module.py +++ b/plugins/module_utils/module.py @@ -1,9 +1,12 @@ import pathlib -from typing import Any, Callable, ClassVar, Dict, Optional, TypeVar, NoReturn, overload +from typing import (Any, Callable, ClassVar, Dict, NoReturn, Optional, TypeVar, + overload) import ansible.module_utils.basic as basic + try: - from ansible_collections.sebastian.systemd.plugins.module_utils.generic import _sdict + from ansible_collections.sebastian.systemd.plugins.module_utils.generic import \ + _sdict except ImportError: from plugins.module_utils.generic import _sdict @@ -52,7 +55,9 @@ class AnsibleModule(object): pass def diff( - self,diff: Optional[Dict[str, str]] = None,*, + self, + diff: Optional[Dict[str, str]] = None, + *, before: Optional[str] = None, after: Optional[str] = None, before_header: Optional[str] = None, @@ -73,7 +78,9 @@ class AnsibleModule(object): if after_header is not None: diff["after_header"] = after_header else: - raise TypeError("only diff or before and after can be set, not both of them") + raise TypeError( + "only diff or before and after can be set, not both of them" + ) self.result["diff"].append(diff) def get(self, key: str, default: T = None) -> T: @@ -106,7 +113,8 @@ class AnsibleModule(object): def __call__(self) -> NoReturn: """This calls the module. first prepare is called and then check or run, depending on the check mode. - If an exception is raised this is catched and the module automatically fails with an traceback""" + If an exception is raised this is catched and the module automatically fails with an traceback + """ self.prepare() print(self.changed) try: @@ -218,7 +226,9 @@ class SystemdUnitModule(AnsibleModule): def check(self): self.unitfile_gen() if not self.unitfile.exists(): - self.diff(before="", after=self.unit(), before_header=self.unitfile.as_posix()) + self.diff( + before="", after=self.unit(), before_header=self.unitfile.as_posix() + ) self.changed = True else: if self.module.sha256(self.unitfile.as_posix()) != self.module.sha256( diff --git a/plugins/modules/systemd_link.py b/plugins/modules/link.py similarity index 96% rename from plugins/modules/systemd_link.py rename to plugins/modules/link.py index 4386521..993e1a5 100644 --- a/plugins/modules/systemd_link.py +++ b/plugins/modules/link.py @@ -3,8 +3,10 @@ import pathlib from typing import List try: - from ansible_collections.sebastian.systemd.plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types - from ansible_collections.sebastian.systemd.plugins.module_utils.module import SystemdUnitModule + from ansible_collections.sebastian.systemd.plugins.module_utils.generic import ( + SYSTEMD_NETWORK_CONFIG, Types) + from ansible_collections.sebastian.systemd.plugins.module_utils.module import \ + SystemdUnitModule except ImportError: from plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types from plugins.module_utils.module import SystemdUnitModule @@ -13,7 +15,7 @@ except ImportError: class Module(SystemdUnitModule): """generates an systemd-networkd link""" - name = "systemd_link" + name = "link" module_spec = dict( argument_spec=dict( mac=Types.str(help="The Mac address of the device"), @@ -48,7 +50,9 @@ class Module(SystemdUnitModule): self.get("name", "") or self.get("mac", "") or self.get("permanentmac", "") ) newname = newname.replace(":", "").replace("/", "-").lower() - self.unitfile = SYSTEMD_NETWORK_CONFIG.joinpath("50-" + newname).with_suffix(".link") + self.unitfile = SYSTEMD_NETWORK_CONFIG.joinpath("50-" + newname).with_suffix( + ".link" + ) def unit(self) -> str: if self.__unit is None: @@ -104,7 +108,7 @@ class Module(SystemdUnitModule): DOCUMENTATION = """--- description: - generates an systemd-networkd link -module: systemd_link +module: link options: description: description: diff --git a/plugins/modules/systemd_mount.py b/plugins/modules/mount.py similarity index 95% rename from plugins/modules/systemd_mount.py rename to plugins/modules/mount.py index 61bda2e..18baacc 100644 --- a/plugins/modules/systemd_mount.py +++ b/plugins/modules/mount.py @@ -3,10 +3,12 @@ import pathlib from typing import List, Optional try: - from ansible_collections.sebastian.systemd.plugins.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types - from ansible_collections.sebastian.systemd.plugins.module_utils.module import SystemdUnitModule + from ansible_collections.sebastian.systemd.plugins.module_utils.generic import ( + SYSTEMD_SERVICE_CONFIG, Types) + from ansible_collections.sebastian.systemd.plugins.module_utils.module import \ + SystemdUnitModule except ImportError: - from plugins.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types + from plugins.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types from plugins.module_utils.module import SystemdUnitModule SYSTEMD_SERVICE_CONFIG = pathlib.Path("/etc/systemd/system") @@ -20,7 +22,7 @@ OPTION_MAPPING = dict( class Module(SystemdUnitModule): """Creates an systemd mount""" - name = "systemd_mount" + name = "mount" module_spec = dict( argument_spec=dict( fs=Types.str( @@ -108,7 +110,7 @@ class Module(SystemdUnitModule): DOCUMENTATION = """--- description: - Creates an systemd mount -module: systemd_mount +module: mount options: description: description: diff --git a/plugins/modules/systemd_network.py b/plugins/modules/network.py similarity index 78% rename from plugins/modules/systemd_network.py rename to plugins/modules/network.py index 95e6541..c1166b0 100644 --- a/plugins/modules/systemd_network.py +++ b/plugins/modules/network.py @@ -3,10 +3,12 @@ import pathlib from typing import List, Union try: - from ansible_collections.sebastian.systemd.plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types - from ansible_collections.sebastian.systemd.plugins.module_utils.module import SystemdUnitModule + from ansible_collections.sebastian.systemd.plugins.module_utils.generic import ( + SYSTEMD_NETWORK_CONFIG, Types) + from ansible_collections.sebastian.systemd.plugins.module_utils.module import \ + SystemdUnitModule except ImportError: - from plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types + from plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types from plugins.module_utils.module import SystemdUnitModule @@ -21,27 +23,42 @@ def boolconvert(b: Union[bool, str]) -> str: class Module(SystemdUnitModule): """Sets up the systemd network unit""" - name = "systemd_network" + name = "network" module_spec = dict( argument_spec=dict( mac=Types.str(help="The MAC-Address of the device"), device=Types.str(help="The name of the network device"), name=Types.str(required=True, help="name of the unit"), description=Types.str(help="An optional description"), - dot=Types.bool(help="if DNS-over-TLS should be required or disabled. If it is unset, it will used if the server supports it"), - dnssec=Types.bool("if the Domainqueries should require DNSSEC or not. If its missing, domains that have DNSSEC enabled will be validated, all others it will be assumed to be okay."), + dot=Types.bool( + help="if DNS-over-TLS should be required or disabled. If it is unset, it will used if the server supports it" + ), + dnssec=Types.bool( + "if the Domainqueries should require DNSSEC or not. If its missing, domains that have DNSSEC enabled will be validated, all others it will be assumed to be okay." + ), dns=Types.list(elements=str, help="List of DNS-Servers"), - domain=Types.list(elements=str, help="List of domains that are on this device"), - defaultdns=Types.bool(help="If the DNS-Server(s) on this device should be used for all domains that are not set on other devices"), - address=Types.list(elements=str, required=True, help="IP-Addresses of this networkdevice"), - route=Types.list(elements=str, help="Routes of networks that can be reached with this device"), + domain=Types.list( + elements=str, help="List of domains that are on this device" + ), + defaultdns=Types.bool( + help="If the DNS-Server(s) on this device should be used for all domains that are not set on other devices" + ), + address=Types.list( + elements=str, required=True, help="IP-Addresses of this networkdevice" + ), + route=Types.list( + elements=str, + help="Routes of networks that can be reached with this device", + ), ), required_if=(("defaultdns", True, ("dns",), False),), required_one_of=(("mac", "device"),), ) def prepare(self): - self.unitfile = SYSTEMD_NETWORK_CONFIG.joinpath(self.get("name")).with_suffix(".network") + self.unitfile = SYSTEMD_NETWORK_CONFIG.joinpath(self.get("name")).with_suffix( + ".network" + ) self.__unit = None def unit(self) -> str: @@ -111,7 +128,7 @@ class Module(SystemdUnitModule): DOCUMENTATION = """--- description: - Sets up the systemd network unit -module: systemd_network +module: network options: address: description: diff --git a/update_doc b/update_doc index 7fd5223..32302ba 100755 --- a/update_doc +++ b/update_doc @@ -1,7 +1,7 @@ #!/usr/bin/python -import re -import pathlib import importlib +import pathlib +import re import sys sys.path.append(".") @@ -21,7 +21,10 @@ if __name__ == "__main__": else: print("Error loading Module of File: {}. No Module or __module_name__ defined".format(modfile)) continue - moddoc = module.doc() + try: + moddoc = module.doc() + except AttributeError: + print("Broken module. skipping {}".format(modfile)) moddata = modfile.read_text() match = regex.search(moddata) if not match: