1
0
Fork 0
Dieser Commit ist enthalten in:
Sebastian Tobie 2023-04-16 00:10:13 +02:00
Ursprung 491270a022
Commit c584ff60f7
5 geänderte Dateien mit 33 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -2,7 +2,10 @@ import pathlib
from typing import Any, Callable, ClassVar, Dict, Optional, TypeVar, NoReturn, overload from typing import Any, Callable, ClassVar, Dict, Optional, TypeVar, NoReturn, overload
import ansible.module_utils.basic as basic import ansible.module_utils.basic as basic
try:
from ansible.module_utils.generic import _sdict from ansible.module_utils.generic import _sdict
except ImportError:
from plugins.module_utils.generic import _sdict
__all__ = ( __all__ = (
"AnsibleModule", "AnsibleModule",

Datei anzeigen

@ -2,9 +2,13 @@
import pathlib import pathlib
from typing import List from typing import List
from ansible.module_utils.generic import SYSTEMD_NETWORK_CONFIG as SYSTEMD_PATH try:
from ansible.module_utils.generic import Types from ansible_collections.sebastian.systemd.plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types
from ansible.module_utils.module import SystemdUnitModule 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
class Module(SystemdUnitModule): class Module(SystemdUnitModule):
"""generates an systemd-networkd link""" """generates an systemd-networkd link"""
@ -44,7 +48,7 @@ class Module(SystemdUnitModule):
self.get("name", "") or self.get("mac", "") or self.get("permanentmac", "") self.get("name", "") or self.get("mac", "") or self.get("permanentmac", "")
) )
newname = newname.replace(":", "").replace("/", "-").lower() newname = newname.replace(":", "").replace("/", "-").lower()
self.unitfile = SYSTEMD_PATH.joinpath("50-" + newname).with_suffix(".link") self.unitfile = SYSTEMD_NETWORK_CONFIG.joinpath("50-" + newname).with_suffix(".link")
def unit(self) -> str: def unit(self) -> str:
if self.__unit is None: if self.__unit is None:

Datei anzeigen

@ -2,11 +2,14 @@
import pathlib import pathlib
from typing import List, Optional from typing import List, Optional
from ansible.module_utils.generic import SYSTEMD_SERVICE_CONFIG as SYSTEMD_PATH try:
from ansible.module_utils.generic import Types from ansible_collections.sebastian.systemd.plugins.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types
from ansible.module_utils.module import SystemdUnitModule 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.module import SystemdUnitModule
SYSTEMD_PATH = pathlib.Path("/etc/systemd/system") SYSTEMD_SERVICE_CONFIG = pathlib.Path("/etc/systemd/system")
OPTION_MAPPING = dict( OPTION_MAPPING = dict(
required_by="RequiredBy", required_by="RequiredBy",
@ -50,7 +53,7 @@ class Module(SystemdUnitModule):
def prepare(self): def prepare(self):
self.mountdir = pathlib.Path(self.params["where"]) self.mountdir = pathlib.Path(self.params["where"])
self.unitfile = SYSTEMD_PATH.joinpath( self.unitfile = SYSTEMD_SERVICE_CONFIG.joinpath(
self.mountdir.relative_to("/").as_posix().replace("/", "-") self.mountdir.relative_to("/").as_posix().replace("/", "-")
).with_suffix(".mount") ).with_suffix(".mount")
self.__unit = None self.__unit = None

Datei anzeigen

@ -2,9 +2,13 @@
import pathlib import pathlib
from typing import List, Union from typing import List, Union
from ansible.module_utils.generic import SYSTEMD_NETWORK_CONFIG as SYSTEMD_PATH try:
from ansible.module_utils.generic import Types from ansible_collections.sebastian.systemd.plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types
from ansible.module_utils.module import SystemdUnitModule 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
def boolconvert(b: Union[bool, str]) -> str: def boolconvert(b: Union[bool, str]) -> str:
if b is True: if b is True:
@ -37,7 +41,7 @@ class Module(SystemdUnitModule):
) )
def prepare(self): def prepare(self):
self.unitfile = SYSTEMD_PATH.joinpath(self.get("name")).with_suffix(".network") self.unitfile = SYSTEMD_NETWORK_CONFIG.joinpath(self.get("name")).with_suffix(".network")
self.__unit = None self.__unit = None
def unit(self) -> str: def unit(self) -> str:

Datei anzeigen

@ -3,12 +3,9 @@ import re
import pathlib import pathlib
import importlib import importlib
import sys import sys
import ansible.module_utils
mindocstring = "DOCUMENTATION = ''''''"
sys.path.append("plugins/modules")
sys.path.append(".") sys.path.append(".")
mindocstring = "DOCUMENTATION = ''''''"
moduledir = pathlib.Path("plugins/modules") moduledir = pathlib.Path("plugins/modules")
regex = re.compile("DOCUMENTATION *= *r?(?P<quote>\"{3}|'{3})(---)?.*?(?P=quote)", re.MULTILINE | re.DOTALL) regex = re.compile("DOCUMENTATION *= *r?(?P<quote>\"{3}|'{3})(---)?.*?(?P=quote)", re.MULTILINE | re.DOTALL)
@ -16,11 +13,14 @@ if __name__ == "__main__":
for modfile in moduledir.iterdir(): for modfile in moduledir.iterdir():
if modfile.name in ( "__init__.py", "__pycache__"): if modfile.name in ( "__init__.py", "__pycache__"):
continue continue
mod = importlib.import_module("plugins.modules."+modfile.stem) mod = importlib.import_module(".".join((modfile.parts[:-1])+(modfile.stem,)))
if hasattr(mod, "Module"): if hasattr(mod, "Module"):
module = mod.Module module = mod.Module
elif hasattr(mod, "__module_name__"): elif hasattr(mod, "__module_name__"):
module = getattr(mod, mod.__module_name__) module = getattr(mod, mod.__module_name__)
else:
print("Error loading Module of File: {}. No Module or __module_name__ defined".format(modfile))
continue
moddoc = module.doc() moddoc = module.doc()
moddata = modfile.read_text() moddata = modfile.read_text()
match = regex.search(moddata) match = regex.search(moddata)