Debian Codegraph @

lib/ansible/module_utils/_internal/_messages.py

raw
1 """
2 Message contract definitions for various target-side types.
3
4 These types and the wire format they implement are currently considered provisional and subject to change without notice.
5 A future release will remove the provisional status.
6 """
7
8 from __future__ import annotations as _annotations
9
10 import dataclasses as _dataclasses
11 import enum as _enum
12 import sys as _sys
13 import typing as _t
14
15 from ansible.module_utils._internal import _datatag, _dataclass_validation
16
17 if _sys.version_info >= (3, 10):
18 # Using slots for reduced memory usage and improved performance.
19 _dataclass_kwargs = dict(frozen=True, kw_only=True, slots=True)
20 else:
21 # deprecated: description='always use dataclass slots and keyword-only args' python_version='3.9'
22 _dataclass_kwargs = dict(frozen=True)
23
24
25 class PluginType(_datatag.AnsibleSerializableEnum):
26 """Enum of Ansible plugin types."""
27
28 ACTION = _enum.auto()
29 BECOME = _enum.auto()
30 CACHE = _enum.auto()
31 CALLBACK = _enum.auto()
32 CLICONF = _enum.auto()
33 CONNECTION = _enum.auto()
34 DOC_FRAGMENTS = _enum.auto()
35 FILTER = _enum.auto()
36 HTTPAPI = _enum.auto()
37 INVENTORY = _enum.auto()
38 LOOKUP = _enum.auto()
39 MODULE = _enum.auto()
40 NETCONF = _enum.auto()
41 SHELL = _enum.auto()
42 STRATEGY = _enum.auto()
43 TERMINAL = _enum.auto()
44 TEST = _enum.auto()
45 VARS = _enum.auto()
46
47
48 @_dataclasses.dataclass(**_dataclass_kwargs)
49 class PluginInfo(_datatag.AnsibleSerializableDataclass):
50 """Information about a loaded plugin."""
51
52 resolved_name: _t.Optional[str]
53 """The resolved canonical plugin name; always fully-qualified for collection plugins."""
54
55 type: _t.Optional[PluginType]
56 """The plugin type."""
57
58
59 @_dataclasses.dataclass(**_dataclass_kwargs)
60 class EventChain(_datatag.AnsibleSerializableDataclass):
61 """A chain used to link one event to another."""
62
63 _validation_auto_enabled = False
64
65 def __post_init__(self): ... # required for deferred dataclass validation
66
67 msg_reason: str
68 traceback_reason: str
69 event: Event
70 follow: bool = True
71
72
73 @_dataclasses.dataclass(**_dataclass_kwargs)
74 class Event(_datatag.AnsibleSerializableDataclass):
75 """Base class for an error/warning/deprecation event with optional chain (from an exception __cause__ chain) and an optional traceback."""
76
77 _validation_auto_enabled = False
78
79 def __post_init__(self): ... # required for deferred dataclass validation
80
81 msg: str
82 formatted_source_context: _t.Optional[str] = None
83 formatted_traceback: _t.Optional[str] = None
84 help_text: _t.Optional[str] = None
85 chain: _t.Optional[EventChain] = None
86 events: _t.Optional[_t.Tuple[Event, ...]] = None
87
88
89 _dataclass_validation.inject_post_init_validation(EventChain, EventChain._validation_allow_subclasses)
90 _dataclass_validation.inject_post_init_validation(Event, Event._validation_allow_subclasses)
91
92
93 @_dataclasses.dataclass(**_dataclass_kwargs)
94 class SummaryBase(_datatag.AnsibleSerializableDataclass):
95 """Base class for an error/warning/deprecation summary with details (possibly derived from an exception __cause__ chain) and an optional traceback."""
96
97 event: Event
98
99
100 @_dataclasses.dataclass(**_dataclass_kwargs)
101 class ErrorSummary(SummaryBase):
102 """Error summary with details (possibly derived from an exception __cause__ chain) and an optional traceback."""
103
104
105 @_dataclasses.dataclass(**_dataclass_kwargs)
106 class WarningSummary(SummaryBase):
107 """Warning summary with details (possibly derived from an exception __cause__ chain) and an optional traceback."""
108
109
110 @_dataclasses.dataclass(**_dataclass_kwargs)
111 class DeprecationSummary(WarningSummary):
112 """Deprecation summary with details (possibly derived from an exception __cause__ chain) and an optional traceback."""
113
114 deprecator: _t.Optional[PluginInfo] = None
115 """
116 The identifier for the content which is being deprecated.
117 """
118
119 date: _t.Optional[str] = None
120 """
121 The date after which a new release of `deprecator` will remove the feature described by `msg`.
122 Ignored if `deprecator` is not provided.
123 """
124
125 version: _t.Optional[str] = None
126 """
127 The version of `deprecator` which will remove the feature described by `msg`.
128 Ignored if `deprecator` is not provided.
129 Ignored if `date` is provided.
130 """