Skip to content

Commit 4f0d79b

Browse files
caladdbsanders
authored andcommitted
FEATURE: Ansible module for getting pallet info
1 parent 9861478 commit 4f0d79b

2 files changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# @copyright@
2+
# Copyright (c) 2006 - 2020 Teradata
3+
# All rights reserved. Stacki(r) v5.x stacki.com
4+
# https://github.com/Teradata/stacki/blob/master/LICENSE.txt
5+
# @copyright@
6+
7+
from ansible.module_utils.basic import AnsibleModule
8+
from ansible.module_utils.stacki import run_stack_command, StackCommandError
9+
10+
DOCUMENTATION = """
11+
module: stacki_pallet_info
12+
short_description: Return data about pallets in Stacki
13+
description:
14+
- If name is supplied, returns information about the single pallet
15+
- If name is not supplied, returns information about all the pallets in the system
16+
options:
17+
name:
18+
description:
19+
- The name of the pallet
20+
required: false
21+
"""
22+
23+
EXAMPLES = """
24+
- name: Get info on all the pallets
25+
stacki_pallet_info:
26+
register: result
27+
28+
- name: Get the stacki pallet info
29+
stacki_pallet_info:
30+
name: stacki
31+
register: result
32+
"""
33+
34+
RETURN = """
35+
pallets:
36+
description:
37+
- List of pallets on the frontend
38+
returned: on success
39+
type: complex
40+
contains:
41+
name:
42+
description:
43+
- Name of the pallet
44+
type: str
45+
46+
version:
47+
description:
48+
- Version of the pallet
49+
type: str
50+
51+
release:
52+
description:
53+
- Release of the pallet
54+
type: str
55+
56+
arch:
57+
description:
58+
- Architecture of the pallet
59+
type: str
60+
61+
os:
62+
description:
63+
- OS the pallet works with
64+
type: str
65+
66+
boxes:
67+
description:
68+
- Boxes the pallet is in
69+
type: list
70+
elements: str
71+
"""
72+
73+
74+
def main():
75+
argument_spec = dict(
76+
name=dict(type="str", required=False, default=None)
77+
)
78+
79+
module = AnsibleModule(
80+
argument_spec=argument_spec,
81+
supports_check_mode=True
82+
)
83+
84+
results = {
85+
"changed": False,
86+
"pallets": []
87+
}
88+
89+
if module.check_mode:
90+
module.exit_json(**results)
91+
92+
args = []
93+
if module.params["name"]:
94+
args.append(module.params["name"])
95+
96+
try:
97+
for pallet in run_stack_command("list.pallet", args):
98+
pallet["boxes"] = pallet["boxes"].split()
99+
100+
results["pallets"].append(pallet)
101+
102+
except StackCommandError as e:
103+
module.fail_json(msg=e.message, **results)
104+
105+
module.exit_json(**results)
106+
107+
108+
if __name__ == "__main__":
109+
main()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class TestStackiPalletInfo:
2+
3+
def test_no_pallet_name(self, run_ansible_module):
4+
result = run_ansible_module("stacki_pallet_info")
5+
6+
assert result.status == "SUCCESS"
7+
assert result.data["changed"] is False
8+
9+
def test_pallet_name(self, run_ansible_module):
10+
pallet_name = "stacki"
11+
result = run_ansible_module("stacki_pallet_info", name=pallet_name)
12+
13+
assert result.status == "SUCCESS"
14+
assert result.data["changed"] is False
15+
assert len(result.data["pallets"]) == 1
16+
assert result.data["pallets"][0]["name"] == pallet_name
17+
18+
def test_invalid_pallet_name(self, run_ansible_module):
19+
pallet_name = "fake_pallet_name"
20+
result = run_ansible_module("stacki_pallet_info", name=pallet_name)
21+
22+
assert "FAIL" in result.status
23+
assert result.data["changed"] is False
24+
25+
assert "error" in result.data["msg"]
26+
assert "not a valid pallet" in result.data["msg"]

0 commit comments

Comments
 (0)