1
0
Fork 0

added virtualization and negative matches to link and network

Dieser Commit ist enthalten in:
Sebastian Tobie 2023-07-15 22:25:59 +02:00
Ursprung 62e4cbe040
Commit 5feb959f42
7 geänderte Dateien mit 89 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -1,10 +1,18 @@
===================================== =====================================
sebastian.systemd 0.3.1 Release Notes sebastian.systemd 0.3.2 Release Notes
===================================== =====================================
.. contents:: Topics .. contents:: Topics
v0.3.2
======
Changelog
---------
added virtualization and negative matches to link and network
v0.3.1 v0.3.1
====== ======

Datei anzeigen

@ -1,6 +1,11 @@
format:
black .
isort .
changelog: changelog:
antsibull-changelog generate antsibull-changelog generate
docs:
docs: format
./update_doc ./update_doc
release: changelog docs release: changelog docs

Datei anzeigen

@ -44,3 +44,7 @@ releases:
changes: changes:
release_date: "2023-04-23" release_date: "2023-04-23"
release_summary: "fixed runtime.yml" release_summary: "fixed runtime.yml"
0.3.2:
changes:
release_date: "2023-07-15"
release_summary: "added virtualization and negative matches to link and network"

Datei anzeigen

@ -116,3 +116,10 @@ def modspec(
required_if=required_if, required_if=required_if,
required_by=required_by, required_by=required_by,
) )
def format_condition(key: str, value: str) -> str:
if value[0] == "!":
value = value[1:]
key = "!" + key
return f"{key}={value}\n"

Datei anzeigen

@ -5,9 +5,9 @@ from typing import Any, Callable, ClassVar, Dict, NoReturn, Optional, Type, Type
import ansible.module_utils.basic as basic import ansible.module_utils.basic as basic
try: try:
from ansible_collections.sebastian.systemd.plugins.module_utils.generic import AnsibleParameter, Types from ansible_collections.sebastian.systemd.plugins.module_utils.generic import AnsibleParameter, Types, format_condition
except ImportError: except ImportError:
from plugins.module_utils.generic import AnsibleParameter, Types from plugins.module_utils.generic import AnsibleParameter, Types, format_condition
__all__ = ( __all__ = (
@ -250,9 +250,9 @@ class SystemdUnitModule(AnsibleModule):
if self.params[param] is not None: if self.params[param] is not None:
params = self.params[param] params = self.params[param]
if isinstance(params, list): if isinstance(params, list):
output.extend(("{}={}\n".format(key, p) for p in params)) output.extend((format_condition(key, p) for p in params))
else: else:
output.append("{}={}\n".format(key, self.params[param])) output.append(format_condition(key, self.params[param]))
return output return output
def unitfile_gen(self): def unitfile_gen(self):
@ -352,6 +352,7 @@ class SystemdReloadMixin:
unitfile: pathlib.Path unitfile: pathlib.Path
restartable: bool = True restartable: bool = True
changed: bool changed: bool
def post(self): def post(self):
if not self.changed: if not self.changed:
return return

Datei anzeigen

@ -3,10 +3,10 @@ import pathlib
from typing import List from typing import List
try: try:
from ansible_collections.sebastian.systemd.plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types, modspec from ansible_collections.sebastian.systemd.plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types, format_condition, modspec
from ansible_collections.sebastian.systemd.plugins.module_utils.module import SystemdUnitModule from ansible_collections.sebastian.systemd.plugins.module_utils.module import SystemdUnitModule
except ImportError: except ImportError:
from plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types, modspec from plugins.module_utils.generic import SYSTEMD_NETWORK_CONFIG, Types, format_condition, modspec
from plugins.module_utils.module import SystemdUnitModule from plugins.module_utils.module import SystemdUnitModule
@ -16,12 +16,26 @@ class Module(SystemdUnitModule): # type: ignore
name = "link" name = "link"
module_spec = modspec( module_spec = modspec(
argument_spec=dict( argument_spec=dict(
mac=Types.str(help="The Mac address of the device"), mac=Types.str(help="The Mac address of the device." "An ! before the value matches anything but this value."),
permanentmac=Types.str(help="The Permanent Mac address advertised by the device"), permanentmac=Types.str(
path=Types.str(help="A shell-style glob matching the persistent path, as exposed by the udev property ID_PATH."), help="The Permanent Mac address advertised by the device. " "An ! before the value matches anything but this value."
driver=Types.str(help="A glob matching the driver currently bound to the device"), ),
type=Types.str(help="A glob matching the device type, as exposed by networkctl list"), path=Types.str(
kind=Types.str(help="a glob matching the device kind, as exposed by networkctl status INTERFACE or ip -d link show INTERFACE."), help="A shell-style glob matching the persistent path, as exposed by the udev property ID_PATH. "
"An ! before the value matches anything but this value."
),
driver=Types.str(
help="A glob matching the driver currently bound to the device. " "An ! before the value matches anything but this value."
),
type=Types.str(
help="A glob matching the device type, as exposed by networkctl list. "
"An ! before the value matches anything but this value."
),
kind=Types.str(
help="a glob matching the device kind, as exposed by networkctl status INTERFACE or ip -d link show INTERFACE. "
"An ! before the value matches anything but this value."
),
virtualization=Types.str(help="The virtualization type. An ! before the value matches anything but this value."),
description=Types.str(help="The description for the link"), description=Types.str(help="The description for the link"),
name=Types.str(required=True, help="The new name of the device"), name=Types.str(required=True, help="The new name of the device"),
mtu=Types.int(help="The maximum Transmission unit for the link"), mtu=Types.int(help="The maximum Transmission unit for the link"),
@ -51,6 +65,7 @@ class Module(SystemdUnitModule): # type: ignore
driver="Driver", driver="Driver",
type="Type", type="Type",
kind="Kind", kind="Kind",
virtualization="Virtualization",
) )
return "[Match]\n" + "".join(options) return "[Match]\n" + "".join(options)
@ -115,18 +130,20 @@ options:
type: list type: list
driver: driver:
description: description:
- A glob matching the driver currently bound to the device - A glob matching the driver currently bound to the device. An ! before the value
matches anything but this value.
required: false required: false
type: str type: str
kind: kind:
description: description:
- a glob matching the device kind, as exposed by networkctl status INTERFACE or - a glob matching the device kind, as exposed by networkctl status INTERFACE or
ip -d link show INTERFACE. ip -d link show INTERFACE. An ! before the value matches anything but this value.
required: false required: false
type: str type: str
mac: mac:
description: description:
- The Mac address of the device - The Mac address of the device.An ! before the value matches anything but this
value.
required: false required: false
type: str type: str
mtu: mtu:
@ -151,12 +168,13 @@ options:
path: path:
description: description:
- A shell-style glob matching the persistent path, as exposed by the udev property - A shell-style glob matching the persistent path, as exposed by the udev property
ID_PATH. ID_PATH. An ! before the value matches anything but this value.
required: false required: false
type: str type: str
permanentmac: permanentmac:
description: description:
- The Permanent Mac address advertised by the device - The Permanent Mac address advertised by the device. An ! before the value matches
anything but this value.
required: false required: false
type: str type: str
requires: requires:
@ -169,7 +187,13 @@ options:
type: list type: list
type: type:
description: description:
- A glob matching the device type, as exposed by networkctl list - A glob matching the device type, as exposed by networkctl list. An ! before
the value matches anything but this value.
required: false
type: str
virtualization:
description:
- The virtualization type. An ! before the value matches anything but this value.
required: false required: false
type: str type: str
wants: wants:

Datei anzeigen

@ -16,8 +16,9 @@ class Module(SystemdUnitModule): # type: ignore
name = "network" name = "network"
module_spec = modspec( module_spec = modspec(
argument_spec=dict( argument_spec=dict(
mac=Types.str(help="The MAC-Address of the device"), mac=Types.str(help="The MAC-Address of the device. An ! before the value matches anything but this value."),
device=Types.str(help="The name of the network device"), device=Types.str(help="The name of the network device. An ! before the value matches anything but this value."),
virtualization=Types.str(help="The virtualization type. An ! before the value matches anything but this value."),
name=Types.str(required=True, help="name of the unit"), name=Types.str(required=True, help="name of the unit"),
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"), 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( dnssec=Types.bool(
@ -35,7 +36,7 @@ class Module(SystemdUnitModule): # type: ignore
), ),
), ),
required_if=(("defaultdns", True, ("dns",), False),), required_if=(("defaultdns", True, ("dns",), False),),
required_one_of=(("mac", "device"),), required_one_of=(("mac", "device", "virtualization"),),
) )
def prepare(self): def prepare(self):
@ -56,11 +57,13 @@ class Module(SystemdUnitModule): # type: ignore
def match(self) -> str: def match(self) -> str:
matches = [] matches = []
if self.get("mac", False): return "[Match]\n" + "".join(
matches.append("MACAddress={}\n".format(self.get("mac"))) self.map_param(
if self.get("device", False): mac="MACAddress",
matches.append("Name={}\n".format(self.get("device"))) device="Name",
return "[Match]\n" + "".join(matches) virtualization="Virtualization",
)
)
def network(self) -> str: def network(self) -> str:
output = "[Network]\n" output = "[Network]\n"
@ -140,7 +143,8 @@ options:
type: str type: str
device: device:
description: description:
- The name of the network device - The name of the network device. An ! before the value matches anything but this
value.
required: false required: false
type: str type: str
dns: dns:
@ -179,7 +183,8 @@ options:
type: bool type: bool
mac: mac:
description: description:
- The MAC-Address of the device - The MAC-Address of the device. An ! before the value matches anything but this
value.
required: false required: false
type: str type: str
name: name:
@ -211,6 +216,11 @@ options:
elements: str elements: str
required: false required: false
type: list type: list
virtualization:
description:
- The virtualization type. An ! before the value matches anything but this value.
required: false
type: str
wants: wants:
default: [] default: []
description: description: