ez_docker/plugins/module_utils/service/custom.py
2024-12-28 21:22:44 +01:00

39 lines
1,003 B
Python

# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
# MIT License (see LICENSE)
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from ansible_collections.ssnailed.ez_compose.plugins.module_utils import (
label,
service,
)
if TYPE_CHECKING:
from ansible_collections.ssnailed.ez_compose.plugins.module_utils.common import (
State,
)
# NOTE: Label helper arguments are added in the compose module itself
EXTRA_ARGS = {
"internal_network": {"type": "bool", "default": False},
}
def helper(state: State, params: dict[str, Any]) -> State:
internal_network: bool = params["internal_network"]
update: dict[str, Any] = {}
networks = update.get("networks", {})
if internal_network:
networks["internal"] = None
update["networks"] = networks
for name, args in params["label_helpers"].items():
state = getattr(label, name).helper(state, params["name"], args)
return service.common.update(state, params, update)