Debian Codegraph @

ansible_collections/community/docker/plugins/plugin_utils/_common_api.py

raw
1 # Copyright (c) 2019-2020, Felix Fontein <[email protected]>
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
6 # Do not use this from other collections or standalone plugins/modules!
7
8 from __future__ import annotations
9
10 import typing as t
11
12 from ansible.errors import AnsibleConnectionFailure
13 from ansible.utils.display import Display
14
15 from ansible_collections.community.docker.plugins.module_utils._common_api import (
16 AnsibleDockerClientBase,
17 )
18 from ansible_collections.community.docker.plugins.module_utils._util import (
19 DOCKER_COMMON_ARGS,
20 )
21
22 if t.TYPE_CHECKING:
23 from ansible.plugins import AnsiblePlugin
24
25
26 class AnsibleDockerClient(AnsibleDockerClientBase):
27 def __init__(
28 self, plugin: AnsiblePlugin, min_docker_api_version: str | None = None
29 ) -> None:
30 self.plugin = plugin
31 self.display = Display()
32 super().__init__(min_docker_api_version=min_docker_api_version)
33
34 def fail(self, msg: str, **kwargs: t.Any) -> t.NoReturn:
35 if kwargs:
36 msg += "\nContext:\n" + "\n".join(
37 f" {k} = {v!r}" for (k, v) in kwargs.items()
38 )
39 raise AnsibleConnectionFailure(msg)
40
41 def deprecate(
42 self,
43 msg: str,
44 version: str | None = None,
45 date: str | None = None,
46 collection_name: str | None = None,
47 ) -> None:
48 self.display.deprecated(
49 msg, version=version, date=date, collection_name=collection_name
50 )
51
52 def _get_params(self) -> dict[str, t.Any]:
53 return {option: self.plugin.get_option(option) for option in DOCKER_COMMON_ARGS}