Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/module_helper/library/mstate.py

raw
1 #!/usr/bin/python
2 # Copyright (c) 2021, Alexei Znamensky <[email protected]>
3 #
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from __future__ import annotations
8
9 DOCUMENTATION = """
10 module: mstate
11 author: "Alexei Znamensky (@russoz)"
12 short_description: State-based module for testing
13 description:
14 - State-based module test description.
15 options:
16 a:
17 description: aaaa
18 type: int
19 required: true
20 b:
21 description: bbbb
22 type: str
23 c:
24 description: cccc
25 type: str
26 state:
27 description: test states
28 type: str
29 choices: [join, b_x_a, c_x_a, both_x_a]
30 default: join
31 """
32
33 EXAMPLES = ""
34
35 RETURN = ""
36
37 from ansible_collections.community.general.plugins.module_utils._module_helper import StateModuleHelper
38
39
40 class MState(StateModuleHelper):
41 output_params = ("a", "b", "c", "state")
42 module = dict(
43 argument_spec=dict(
44 a=dict(type="int", required=True),
45 b=dict(type="str"),
46 c=dict(type="str"),
47 state=dict(type="str", choices=["join", "b_x_a", "c_x_a", "both_x_a", "nop"], default="join"),
48 ),
49 )
50
51 def __init_module__(self):
52 self.vars.set("result", "abc", diff=True)
53
54 def state_join(self):
55 self.vars["result"] = "".join([str(self.vars.a), str(self.vars.b), str(self.vars.c)])
56
57 def state_b_x_a(self):
58 self.vars["result"] = str(self.vars.b) * self.vars.a
59
60 def state_c_x_a(self):
61 self.vars["result"] = str(self.vars.c) * self.vars.a
62
63 def state_both_x_a(self):
64 self.vars["result"] = (str(self.vars.b) + str(self.vars.c)) * self.vars.a
65
66 def state_nop(self):
67 pass
68
69
70 def main():
71 mstate = MState()
72 mstate.run()
73
74
75 if __name__ == "__main__":
76 main()