ez_docker/plugins/module_utils/label/docker_volume_backupper.py
2024-12-11 18:42:59 +01:00

37 lines
1 KiB
Python

# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
# MIT License (see LICENSE)
"""Docker Volume Backup label helper."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
import ansible_collections.snailed.ez_compose.plugins.module_utils.label.common as label
import ansible_collections.snailed.ez_compose.plugins.module_utils.service.common as service
if TYPE_CHECKING:
from ansible_collections.snailed.ez_compose.plugins.module_utils.common import State
def helper(state: State) -> State:
"""Add labels to the service to stop it during backup."""
stop = state.module.params.get("stop", True)
project_name = state.module.params["project_name"]
update: dict[str, Any] = {}
if stop:
update["labels"] = {
"docker-volume-backup.stop-during-backup": project_name,
}
return service.update(state, update)
def run() -> None:
"""Run the backupper label helper."""
extra_args = {
"stop": {"type": "bool"},
}
label.run(extra_args, helper)