1
0
Fork 0

updated the dependency sebastian.base to the 0.4.0 methods

Dieser Commit ist enthalten in:
Sebastian Tobie 2024-03-09 00:13:24 +01:00
Ursprung 3d528fe1a6
Commit 8ee18934a9
12 geänderte Dateien mit 152 neuen und 136 gelöschten Zeilen

Datei anzeigen

@ -1,10 +1,18 @@
===================================== =====================================
sebastian.systemd 0.4.0 Release Notes sebastian.systemd 0.4.2 Release Notes
===================================== =====================================
.. contents:: Topics .. contents:: Topics
v0.4.2
======
Changelog
---------
upgraded to the new method used by sebastian.base
v0.4.0 v0.4.0
====== ======

Datei anzeigen

@ -66,3 +66,7 @@ releases:
release_date: "2024-02-24" release_date: "2024-02-24"
changes: changes:
release_summary: added timer module release_summary: added timer module
0.4.2:
release_date: "2024-03-09"
changes:
release_summary: upgraded to the new method used by sebastian.base

Datei anzeigen

@ -1,7 +1,7 @@
--- ---
namespace: sebastian namespace: sebastian
name: systemd name: systemd
version: 0.4.1 version: 0.4.2
readme: README.md readme: README.md
@ -13,7 +13,7 @@ tags:
- systemd - systemd
- linux - linux
dependencies: dependencies:
sebastian.base: ">=0.3.1" sebastian.base: ">=0.4.0"
repository: https://gitea.sebastian-tobie.de/ansible/ansible-systemd.git repository: https://gitea.sebastian-tobie.de/ansible/ansible-systemd.git
# documentation: http://docs.example.com # documentation: http://docs.example.com
homepage: https://gitea.sebastian-tobie.de/ansible/ansible-systemd homepage: https://gitea.sebastian-tobie.de/ansible/ansible-systemd

Datei anzeigen

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
import pathlib import pathlib
from typing import List from typing import List, Optional
try: try:
from ansible_module.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types, modspec from ansible_module.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types, modspec
@ -54,10 +54,10 @@ class Module(SystemdUnitModule): # type: ignore
def unit(self) -> str: def unit(self) -> str:
if self.__unit is None: if self.__unit is None:
self.__unit = "\n".join((self.match(), self.link())) self.__unit = self._unit(self.match(), self.link())
return self.__unit return self.__unit
def match(self) -> str: def match(self) -> Optional[str]:
options = self.map_param( options = self.map_param(
mac="MACAddress", mac="MACAddress",
permanentmac="PermanentAddress", permanentmac="PermanentAddress",
@ -67,9 +67,11 @@ class Module(SystemdUnitModule): # type: ignore
kind="Kind", kind="Kind",
virtualization="Virtualization", virtualization="Virtualization",
) )
if len(options) == 0:
return None
return "[Match]\n" + "".join(options) return "[Match]\n" + "".join(options)
def link(self) -> str: def link(self) -> Optional[str]:
options = [] options = []
if self.get("description", False): if self.get("description", False):
options.append("Description={}\n".format(self.get("description", False))) options.append("Description={}\n".format(self.get("description", False)))
@ -77,6 +79,8 @@ class Module(SystemdUnitModule): # type: ignore
options.append("Name={}\n".format(self.get("name", False))) options.append("Name={}\n".format(self.get("name", False)))
if self.get("mtu", False): if self.get("mtu", False):
options.append("MTUBytes={}\n".format(self.get("mtu", False))) options.append("MTUBytes={}\n".format(self.get("mtu", False)))
if len(options) == 0:
return None
return "[Link]\n" + "".join(options) return "[Link]\n" + "".join(options)
def post(self): def post(self):

Datei anzeigen

@ -18,7 +18,7 @@ OPTION_MAPPING = dict(
@installable @installable
class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore[misc]
"""Creates an systemd mount""" """Creates an systemd mount"""
name = "mount" name = "mount"
@ -45,26 +45,25 @@ class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore
def unit(self) -> str: def unit(self) -> str:
if self.__unit is None: if self.__unit is None:
self.__unit = "\n".join( self.__unit = self._unit(
(
self.header(), self.header(),
self.mount(), self.mount(),
self.install(), self.install(), # type: ignore[misc,call-arg]
)
) )
return self.__unit return self.__unit
def header(self) -> str: def header(self) -> str:
return "[Unit]\nDescription={}\n".format(self.get("description", "Mount for {}".format(self.get("where")))) description = self.get("description", "Mount for {}".format(self.get("where")))
return f"[Unit]\nDescription={description}\n"
def mount(self) -> str: def mount(self) -> str:
output = "[Mount]\n" options = []
output += "Where={}\n".format(self.get("where")) options.append("Where={}\n".format(self.get("where")))
output += "What={}\n".format(self.get("what")) options.append("What={}\n".format(self.get("what")))
output += "Type={}\n".format(self.get("fs")) options.append("Type={}\n".format(self.get("fs")))
if self.get("options", False): if self.get("options", False):
output += "Options={}\n".format(",".join(self.get("options"))) options.append("Options={}\n".format(",".join(self.get("options"))))
return output return "[Mount]\n" + "".join(options)
DOCUMENTATION = """--- DOCUMENTATION = """---

Datei anzeigen

@ -75,55 +75,65 @@ class Module(SystemdUnitModule):
parts = [self.match(), self.netdev()] parts = [self.match(), self.netdev()]
if kind != "dummy": if kind != "dummy":
parts.append(getattr(self, kind)()) parts.append(getattr(self, kind)())
self.__unit = "\n".join(parts) self.__unit = self._unit(*parts)
return self.__unit return self.__unit
def match(self) -> str: def match(self) -> Optional[str]:
options = self.map_param( options = self.map_param(
host="Host", host="Host",
kernelcmd="KernelCommandLine", kernelcmd="KernelCommandLine",
virtualization="Virtualization", virtualization="Virtualization",
) )
if len(options) == 0:
return None
return "[Match]\n" + "".join(options) return "[Match]\n" + "".join(options)
def netdev(self) -> str: def netdev(self) -> Optional[str]:
options = self.map_param( options = self.map_param(
description="Description", description="Description",
name="Name", name="Name",
kind="Kind", kind="Kind",
) )
if len(options) == 0:
return None
return "[NetDev]\n" + "".join(options) return "[NetDev]\n" + "".join(options)
def bond(self) -> str: def bond(self) -> Optional[str]:
return "[Bond]\n" + "".join( options = self.map_param(
self.map_param(
mode="Mode", mode="Mode",
minlinks="MinLinks", minlinks="MinLinks",
) )
) if len(options) == 0:
return None
return "[Bond]\n" + "".join(options)
def bridge(self) -> str: def bridge(self) -> Optional[str]:
return "[Bridge]\n" + "".join( options = self.map_param(
self.map_param(
stp="STP", stp="STP",
priority="Priority", priority="Priority",
) )
) if len(options) == 0:
return None
return "[Bridge]\n" + "".join(options)
def wireguard(self) -> str: def wireguard(self) -> Optional[str]:
port = self.get("port", False) options = self.map_param(
if port not in (False, "auto") and (port < 1 or port > 65535):
raise ValueError("Port must be between 0 and 65536")
return "[Wireguard]\n" + "".join(
self.map_param(
privatekey="PrivateKey", privatekey="PrivateKey",
privatekeyfile="PrivateKeyFile", privatekeyfile="PrivateKeyFile",
port="ListenPort", port="ListenPort",
) )
) port = self.get("port", False)
if port not in (False, "auto") and (port < 1 or port > 65535):
raise ValueError("Port must be between 0 and 65536")
if len(options) == 0:
return None
return "[Wireguard]\n" + "".join(options)
def vlan(self) -> str: def vlan(self) -> Optional[str]:
return "" options: list[str] = []
if len(options) == 0:
return None
return "[Vlan]\n" + "".join(options)
DOCUMENTATION = """--- DOCUMENTATION = """---

Datei anzeigen

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
import pathlib import pathlib
from typing import List, Union from typing import List, Union, Optional
try: try:
from ansible_module.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types, modspec, systemdbool from ansible_module.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types, modspec, systemdbool
@ -36,7 +36,7 @@ class Module(SystemdUnitModule): # type: ignore
), ),
masquerade=Types.str( masquerade=Types.str(
help="how the packets are modified to look like the come from the computer itself.", help="how the packets are modified to look like the come from the computer itself.",
choices=("true", "false", "both", "ipv4", "ipv6"), choices=("true", "false", "both", "ipv4", "ipv6", "no"),
), ),
), ),
required_if=(("defaultdns", True, ("dns",), False),), required_if=(("defaultdns", True, ("dns",), False),),
@ -49,56 +49,46 @@ class Module(SystemdUnitModule): # type: ignore
def unit(self) -> str: def unit(self) -> str:
if self.__unit is None: if self.__unit is None:
self.__unit = "\n".join( self.__unit = self._unit(
(
self.match(), self.match(),
self.network(), self.network(),
self.addresses(), self.addresses(),
self.routes(), self.routes(),
) )
)
return self.__unit return self.__unit
def match(self) -> str: def match(self) -> Optional[str]:
matches = [] matches = self.map_param(
return "[Match]\n" + "".join(
self.map_param(
mac="MACAddress", mac="MACAddress",
device="Name", device="Name",
virtualization="Virtualization", virtualization="Virtualization",
) )
) if len(matches) == 0:
return None
return "[Match]\n" + "".join(matches)
def network(self) -> str: def network(self) -> Optional[str]:
output = "[Network]\n"
options = [] options = []
try: if self.get("description", None) is None:
options.append("Description={}".format(self.get("description"))) options.append("Description={}".format(self.get("description")))
except KeyError: server: str
pass
try:
for server in self.get("dns", []): for server in self.get("dns", []):
options.append(f"DNS={server}") options.append(f"DNS={server}")
options.append("DNSDefaultRoute={}".format(self.get("defaultdns", False))) options.append("DNSDefaultRoute={}".format(self.get("defaultdns", False)))
except KeyError: if self.get("domain", False):
pass options.append("Domains={}".format(" ".join(self.get("domain"))))
try:
domain = self.get("domain")
self.set("domainlog", str(domain))
options.append("Domains={}".format(" ".join(domain)))
options.append("DNSOverTLS={}".format(systemdbool(self.get("dot", "opportunistic")))) options.append("DNSOverTLS={}".format(systemdbool(self.get("dot", "opportunistic"))))
options.append("DNSSEC={}".format(systemdbool(self.get("dnssec", "allow-downgrade")))) options.append("DNSSEC={}".format(systemdbool(self.get("dnssec", "allow-downgrade"))))
except KeyError: if self.get("masquerade", None) is not None:
pass masquerade: str = self.get("masquerade")
if self.get("masquerade", -1) != -1:
masquerade = self.get("masquerade")
if masquerade == "true": if masquerade == "true":
masquerade = "both" masquerade = "both"
elif masquerade == "false": elif masquerade == "false":
masquerade = "no" masquerade = "no"
options.append(f"IPMasquerade={masquerade}") options.append(f"IPMasquerade={masquerade}")
output += "\n".join(options) if len(options) == 0:
return output return None
return "[Network]\n" + "".join(options)
def addresses(self) -> str: def addresses(self) -> str:
output = [] output = []
@ -106,13 +96,13 @@ class Module(SystemdUnitModule): # type: ignore
output.append(f"[Address]\nAddress={address}\n") output.append(f"[Address]\nAddress={address}\n")
return "\n".join(output) return "\n".join(output)
def routes(self) -> str: def routes(self) -> Optional[str]:
output = [] output = []
routes = self.get("route", []) routes: list[str] = self.get("route", [])
self.set("routes", routes)
for gw in routes: for gw in routes:
output.append(f"[Route]\nGateway={gw}\nGatewayOnLink=yes\nQuickAck=yes\n") output.append(f"[Route]\nGateway={gw}\nGatewayOnLink=yes\nQuickAck=yes\n")
self.set("routes", output) if len(output) == 0:
return None
return "\n".join(output) return "\n".join(output)
@ -205,6 +195,7 @@ options:
- both - both
- ipv4 - ipv4
- ipv6 - ipv6
- 'no'
description: description:
- how the packets are modified to look like the come from the computer itself. - how the packets are modified to look like the come from the computer itself.
required: false required: false

Datei anzeigen

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
import pathlib import pathlib
from typing import List, Union from typing import List, Union, Optional
try: try:
from ansible_module.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types, modspec from ansible_module.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types, modspec
@ -47,10 +47,8 @@ class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore
self.unitfile = (SYSTEMD_SERVICE_CONFIG / self.get("name")).with_suffix(".socket") self.unitfile = (SYSTEMD_SERVICE_CONFIG / self.get("name")).with_suffix(".socket")
self.__unit = None self.__unit = None
def socket(self): def socket(self) -> Optional[str]:
section = "[Socket]\n" section = self.map_param(
section += "".join(
self.map_param(
stream="ListenStream", stream="ListenStream",
datagram="ListenDatagram", datagram="ListenDatagram",
sequential="ListenSequential", sequential="ListenSequential",
@ -59,17 +57,16 @@ class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore
socketgroup="SocketGroup", socketgroup="SocketGroup",
socketmode="SocketMode", socketmode="SocketMode",
) )
) if len(section) == 0:
return section return None
return "[Socket]\n" + "".join(section)
def unit(self) -> str: def unit(self) -> str:
if self.__unit is None: if self.__unit is None:
self.__unit = "\n".join( self.__unit = self._unit(
(
self.header(), self.header(),
self.socket(), self.socket(),
self.install(), self.install(), # type: ignore[call-arg,misc]
)
) )
return self.__unit return self.__unit

Datei anzeigen

@ -11,7 +11,7 @@ except ImportError:
@installable @installable
class Module(SystemdUnitModule, SystemdReloadMixin): class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore[misc]
"""Creates System Services units""" """Creates System Services units"""
name = "system_service" name = "system_service"
@ -95,8 +95,7 @@ class Module(SystemdUnitModule, SystemdReloadMixin):
if self.get("type", "simple") != "oneshot" and len(self.get("start")) > 1: if self.get("type", "simple") != "oneshot" and len(self.get("start")) > 1:
self.module.fail_json("only oneshot services are allowed to have multiple start commands", **self.result) self.module.fail_json("only oneshot services are allowed to have multiple start commands", **self.result)
def service(self): def service(self) -> str:
section = "[Service]\n"
params = [] params = []
if self.get("environment", False): if self.get("environment", False):
for env in self.get("environment"): for env in self.get("environment"):
@ -122,17 +121,14 @@ class Module(SystemdUnitModule, SystemdReloadMixin):
nonewprivileges="NoNewPriviledges", nonewprivileges="NoNewPriviledges",
) )
) )
section += "".join(params) return "[Service]\n" + "".join(params)
return section
def unit(self) -> str: def unit(self) -> str:
if self.__unit is None: if self.__unit is None:
self.__unit = "\n".join( self.__unit = self._unit(
(
self.header(), self.header(),
self.service(), self.service(),
self.install(), self.install(), # type: ignore[call-arg,misc]
)
) )
return self.__unit return self.__unit
@ -246,7 +242,7 @@ options:
pre: pre:
default: [] default: []
description: description:
- command or list of commands that are started before the main command(Types.str) - command or list of commands that are started before the main command
elements: str elements: str
required: false required: false
type: list type: list

Datei anzeigen

@ -13,7 +13,7 @@ __module_name__ = "TargetModule"
@installable @installable
class TargetModule(SystemdUnitModule, SystemdReloadMixin): class TargetModule(SystemdUnitModule, SystemdReloadMixin): # type: ignore[misc]
"""Creates Target units""" """Creates Target units"""
name = "target" name = "target"
@ -35,16 +35,16 @@ class TargetModule(SystemdUnitModule, SystemdReloadMixin):
def header(self) -> str: def header(self) -> str:
section = super().header() section = super().header()
if section is None:
section = "[Unit]\n"
section += "AllowIsolate={}\n".format(systemdbool(self.get("allow_isolate", False))) section += "AllowIsolate={}\n".format(systemdbool(self.get("allow_isolate", False)))
return section return section
def unit(self) -> str: def unit(self) -> str:
if self.__unit is None: if self.__unit is None:
self.__unit = "\n".join( self.__unit = self._unit(
(
self.header(), self.header(),
self.install(), self.install(), # type: ignore[call-arg,misc]
)
) )
return self.__unit return self.__unit

Datei anzeigen

@ -14,7 +14,7 @@ __module_name__ = "TimerModule"
@installable @installable
class TimerModule(SystemdUnitModule, SystemdReloadMixin): # type: ignore class TimerModule(SystemdUnitModule, SystemdReloadMixin): # type: ignore[misc]
"""Creates Timer units""" """Creates Timer units"""
name = "timer" name = "timer"
@ -56,14 +56,14 @@ class TimerModule(SystemdUnitModule, SystemdReloadMixin): # type: ignore
unit=Types.str(help="The name of the unit. only needed if its not {{name}}.service"), unit=Types.str(help="The name of the unit. only needed if its not {{name}}.service"),
), ),
required_one_of=[ required_one_of=[
[ (
"onactive", "onactive",
"onboot", "onboot",
"onstartup", "onstartup",
"onunitactive", "onunitactive",
"onunitinactive", "onunitinactive",
"oncalendar", "oncalendar",
], ),
], ],
) )
@ -82,19 +82,23 @@ class TimerModule(SystemdUnitModule, SystemdReloadMixin): # type: ignore
onunitactive="OnUnitActiveSec", onunitactive="OnUnitActiveSec",
onunitinactive="OnUnitInactiveSec", onunitinactive="OnUnitInactiveSec",
oncalendar="OnCalendar", oncalendar="OnCalendar",
persistent="Persistent",
randomdelay="RandomizedDelaySec",
fixdelay="FixedRandomDelay",
unit="Unit",
), ),
) )
if len(params) == 0:
return None
section += "".join(params) section += "".join(params)
return section return section
def unit(self) -> str: def unit(self) -> str:
if self.__unit is None: if self.__unit is None:
self.__unit = "\n".join( self.__unit = self._unit(
(
self.header(), self.header(),
self.body(), self.body(),
self.install(), self.install(), # type: ignore[call-arg,misc]
)
) )
return self.__unit return self.__unit

Datei anzeigen

@ -5,3 +5,6 @@ line-length = 140
atomic = true atomic = true
profile = "black" profile = "black"
line_length = 140 line_length = 140
[tool.mypy]
disable_error_code = ["import-untyped", "no-redef", "attr-defined"]