1
0
Fork 0

renamed the modules

Dieser Commit ist enthalten in:
Sebastian Tobie 2023-04-20 22:09:58 +02:00
Ursprung 3923d2cedb
Commit 172cce0b04
7 geänderte Dateien mit 88 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -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
======

Datei anzeigen

@ -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"

Datei anzeigen

@ -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(

Datei anzeigen

@ -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:

Datei anzeigen

@ -3,8 +3,10 @@ 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.module import SystemdUnitModule
@ -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:

Datei anzeigen

@ -3,8 +3,10 @@ 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.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:

Datei anzeigen

@ -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
try:
moddoc = module.doc()
except AttributeError:
print("Broken module. skipping {}".format(modfile))
moddata = modfile.read_text()
match = regex.search(moddata)
if not match: