-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetal_resource_info.py
88 lines (73 loc) · 2.16 KB
/
metal_resource_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# DOCUMENTATION, EXAMPLES, and RETURN are generated by
# ansible_specdoc. Do not edit them directly.
DOCUMENTATION = ""
EXAMPLES = ""
RETURN = ""
# End
from ansible.module_utils._text import to_native
from ansible_specdoc.objects import SpecField, FieldType, SpecReturnValue
import traceback
from ansible_collections.equinix.cloud.plugins.module_utils.equinix import (
EquinixModule,
getSpecDocMeta,
)
module_spec = dict(
name=SpecField(
type=FieldType.string,
description=['Filter resource on substring in name attribute.'],
),
parent_resource_id=SpecField(
type=FieldType.string,
description=['UUID of parent resource containing the resource.'],
),
)
specdoc_examples = ['''
- name: Gather information about all resources in parent resource
hosts: localhost
tasks:
- equinix.cloud.metal_resource_info
parent_resource_id: 2a5122b9-c323-4d5c-b53c-9ad3f54273e7
''', '''
''',
]
return_values = ['''
[
{
"id": "31d3ae8b-bd5a-41f3-a420-055211345cc7",
"name": "ansible-integration-test-resource-csle6t2y-resource2",
"parent_resource_id": "845b45a3-c565-47e5-b9b6-a86204a73d29"
}
]''',
]
SPECDOC_META = getSpecDocMeta(
short_description="Gather information about Equinix Metal resources",
description=(
'Gather information about Equinix Metal resources'
),
examples=specdoc_examples,
options=module_spec,
return_values={
"resources": SpecReturnValue(
description='Found resources',
type=FieldType.dict,
sample=return_values,
),
},
)
def main():
module = EquinixModule(
argument_spec=SPECDOC_META.ansible_spec,
is_info=True,
)
try:
module.params_syntax_check()
return_value = {'resources': module.get_list("metal_resource")}
except Exception as e:
tr = traceback.format_exc()
module.fail_json(msg=to_native(e), exception=tr)
module.exit_json(**return_value)
if __name__ == '__main__':
main()