ansible-module/plugins/module_utils/generic.pyi
Sebastian Tobie 749ae48441 Release 0.5.0
- Added ReturnTypes
- improved the AnsibleParameter Type
- added an set containing  the arguments from add_file_common_args
- added an functio to move generated files to their location according to the common_args
- the modspec function was extended with arguments for metadata in the documentation
2025-03-22 16:29:19 +01:00

245 Zeilen
7,2 KiB
Python

from pathlib import PosixPath
from typing import Any, Dict, Literal, NotRequired, Optional, Required, Sequence, Tuple, Type, TypedDict
__all__ = [
"Types",
"SYSTEMD_SERVICE_CONFIG",
"SYSTEMD_NETWORK_CONFIG",
"SYSTEMD_CONFIG_ROOT",
"FILE_COMMON_ARGS",
"systemdbool",
"AnsibleParameter",
"AnsibleReturnParameter",
]
SYSTEMD_CONFIG_ROOT: PosixPath
SYSTEMD_NETWORK_CONFIG: PosixPath
SYSTEMD_SERVICE_CONFIG: PosixPath
FILE_COMMON_ARGS: frozenset[str]
AnsibleType = Literal[
"str",
"bool",
"int",
"float",
"path",
"raw",
"jsonarg",
"json",
"bytes",
"dict",
"list",
"bits",
]
ReturnOptions = Literal["always", "changed", "success"]
class AnsibleParameter(TypedDict, total=False):
description: Required[str | list[str]]
required: NotRequired[bool]
default: NotRequired[Any]
type: Required[AnsibleType]
choices: NotRequired[list[Any] | tuple[Any]]
elements: NotRequired["AnsibleParameter" | AnsibleType]
aliases: NotRequired[list[str]]
version_added: NotRequired[str]
options: NotRequired[dict[str, "AnsibleParameter"]]
class AnsibleReturnParameter(TypedDict, total=False):
description: Required[str | list[str]]
type: Required[AnsibleType]
returned: NotRequired[ReturnOptions]
elements: NotRequired[AnsibleType]
sample: NotRequired[list[Any] | Any]
version_added: NotRequired[str]
contains: NotRequired[dict[str, "AnsibleReturnParameter"]]
class TypeBase(type):
def __new__(cls, clsname, bases, attrs): ...
class Types(metaclass=TypeBase):
@staticmethod
def str(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def bool(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def int(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def float(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def path(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def raw(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def jsonarg(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def json(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def bytes(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def bits(
required: bool = False,
help: str | list[str] | None = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def list(
elements: type[object] | str | AnsibleParameter,
required: bool = False,
help: str | list[str] | None = None,
default: list[Any] | None = None,
) -> AnsibleParameter: ...
@staticmethod
def dict(
required: bool = False, help: str | list[str] | None = None, **options: AnsibleParameter
) -> AnsibleParameter: ...
class ReturnTypes(metaclass=TypeBase):
@staticmethod
def list(
help: str | list[str],
elements: AnsibleType | AnsibleReturnParameter | Type[object],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def dict(
help: str | list[str],
contains: dict[str, AnsibleReturnParameter],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def str(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def bool(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def int(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def float(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def path(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def raw(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def jsonarg(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def json(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def bytes(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
@staticmethod
def bits(
help: str | list[str],
returned: ReturnOptions | None = None,
sample: list[Any] | None = None,
version_added: str | None = None,
): ...
def systemdbool(b: bool | str) -> str: ...
def joindict(*items: dict) -> dict: ...
def modspec(
argument_spec: Dict[str, Dict[str, Any]],
mutually_exclusive: Sequence[Tuple[str, ...]] = (),
required_together: Sequence[Tuple[str, ...]] = (),
required_one_of: Sequence[Tuple[str, ...]] = (),
required_if: Sequence[Tuple[str, Any, Tuple[str, ...]] | Tuple[str, Any, Tuple[str, ...], bool]] = (),
required_by: Dict[str, str | Tuple[str, ...]] = {},
supports_check_mode: bool = False,
add_file_common_args: bool = False,
deprecated: bool = False,
version_added: str | None = None,
notes: list[str] | None = None,
extends_documentation_fragment: list[str] | None = None,
) -> Dict[str, Any]: ...