Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_storage_policy_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: intersight_storage_policy_info
16 short_description: Gather information about Storage Policies in Cisco Intersight
17 description:
18 - Gather information about Storage Policies in L(Cisco Intersight,https://intersight.com).
19 - Information can be filtered by O(organization) and O(name).
20 - If no filters are passed, all Storage Policies will be returned.
21 extends_documentation_fragment: intersight
22 options:
23 organization:
24 description:
25 - The name of the organization the Storage Policy belongs to.
26 type: str
27 name:
28 description:
29 - The name of the Storage Policy to gather information from.
30 type: str
31 author:
32 - Ron Gershburg (@rgershbu)
33 '''
34
35 EXAMPLES = r'''
36 - name: Fetch a specific Storage Policy by name
37 cisco.intersight.intersight_storage_policy_info:
38 api_private_key: "{{ api_private_key }}"
39 api_key_id: "{{ api_key_id }}"
40 name: "basic-storage-policy"
41
42 - name: Fetch all Storage Policies in a specific Organization
43 cisco.intersight.intersight_storage_policy_info:
44 api_private_key: "{{ api_private_key }}"
45 api_key_id: "{{ api_key_id }}"
46 organization: "default"
47
48 - name: Fetch all Storage Policies
49 cisco.intersight.intersight_storage_policy_info:
50 api_private_key: "{{ api_private_key }}"
51 api_key_id: "{{ api_key_id }}"
52 '''
53
54 RETURN = r'''
55 api_response:
56 description: The API response output returned by the specified resource.
57 returned: always
58 type: dict
59 sample:
60 "api_response": [
61 {
62 "Name": "basic-storage-policy",
63 "ObjectType": "storage.StoragePolicy",
64 "UseJbodForVdCreation": true,
65 "UnusedDisksState": "NoChange",
66 "DefaultDriveMode": "UnconfiguredGood",
67 "ControllerAttachedNvmeSlots": "",
68 "DirectAttachedNvmeSlots": "",
69 "SecureJbods": "",
70 "M2VirtualDrive": {
71 "Enable": false,
72 "ControllerSlot": "MSTOR-RAID-1",
73 "Name": "MStorBootVd"
74 },
75 "Raid0Drive": {
76 "Enable": false,
77 "DriveSlots": "",
78 "VirtualDrivePolicy": {
79 "StripSize": 64,
80 "AccessPolicy": "Default",
81 "ReadPolicy": "Default",
82 "WritePolicy": "Default",
83 "DriveCache": "Default"
84 }
85 },
86 "DriveGroups": [
87 {
88 "Name": "raid0-group",
89 "RaidLevel": "Raid0",
90 "SecureDriveGroup": false,
91 "ManualDriveGroup": {
92 "SpanGroups": [
93 {
94 "Slots": "1,2"
95 }
96 ]
97 },
98 "VirtualDrives": [
99 {
100 "Name": "raid0-vd",
101 "Size": 1024,
102 "ExpandToAvailable": false,
103 "BootDrive": true,
104 "VirtualDrivePolicy": {
105 "StripSize": 128,
106 "AccessPolicy": "ReadWrite",
107 "ReadPolicy": "ReadAhead",
108 "WritePolicy": "WriteBackGoodBbu",
109 "DriveCache": "Enable"
110 }
111 }
112 ]
113 }
114 ],
115 "Tags": [
116 {
117 "Key": "Environment",
118 "Value": "Production"
119 }
120 ]
121 },
122 {
123 "Name": "m2-enabled-storage-policy",
124 "ObjectType": "storage.StoragePolicy",
125 "UseJbodForVdCreation": true,
126 "UnusedDisksState": "NoChange",
127 "DefaultDriveMode": "UnconfiguredGood",
128 "ControllerAttachedNvmeSlots": "",
129 "DirectAttachedNvmeSlots": "",
130 "SecureJbods": "",
131 "M2VirtualDrive": {
132 "Enable": true,
133 "ControllerSlot": "MSTOR-RAID-1",
134 "Name": "MStorBootVd"
135 },
136 "Raid0Drive": {
137 "Enable": false,
138 "DriveSlots": "",
139 "VirtualDrivePolicy": {
140 "StripSize": 64,
141 "AccessPolicy": "Default",
142 "ReadPolicy": "Default",
143 "WritePolicy": "Default",
144 "DriveCache": "Default"
145 }
146 },
147 "Tags": [
148 {
149 "Key": "Site",
150 "Value": "Datacenter1"
151 }
152 ]
153 }
154 ]
155 '''
156
157
158 from ansible.module_utils.basic import AnsibleModule
159 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
160
161
162 def main():
163 argument_spec = intersight_argument_spec.copy()
164 argument_spec.update(
165 organization=dict(type='str'),
166 name=dict(type='str')
167 )
168 module = AnsibleModule(
169 argument_spec,
170 supports_check_mode=True,
171 )
172
173 intersight = IntersightModule(module)
174 intersight.result['api_response'] = {}
175 intersight.result['trace_id'] = ''
176
177 resource_path = '/storage/StoragePolicies'
178
179 query_params = intersight.set_query_params()
180
181 intersight.get_resource(
182 resource_path=resource_path,
183 query_params=query_params,
184 return_list=True
185 )
186
187 # Fetch drive groups for each storage policy
188 storage_policies = intersight.result['api_response']
189 if isinstance(storage_policies, list):
190 for policy in storage_policies:
191 if policy.get('Moid'):
192 # Fetch drive groups for this policy using StoragePolicy.Moid filter
193 drive_groups_query_params = {
194 '$filter': f"StoragePolicy.Moid eq '{policy['Moid']}'"
195 }
196
197 # Create a temporary intersight instance for drive groups query
198 temp_intersight = IntersightModule(module)
199 temp_intersight.get_resource(
200 resource_path='/storage/DriveGroups',
201 query_params=drive_groups_query_params,
202 return_list=True
203 )
204
205 # Add drive groups to the policy
206 policy['DriveGroups'] = temp_intersight.result.get('api_response', [])
207 elif isinstance(storage_policies, dict) and storage_policies.get('Moid'):
208 # Single policy case
209 drive_groups_query_params = {
210 '$filter': f"StoragePolicy.Moid eq '{storage_policies['Moid']}'"
211 }
212
213 # Create a temporary intersight instance for drive groups query
214 temp_intersight = IntersightModule(module)
215 temp_intersight.get_resource(
216 resource_path='/storage/DriveGroups',
217 query_params=drive_groups_query_params,
218 return_list=True
219 )
220
221 # Add drive groups to the policy
222 storage_policies['DriveGroups'] = temp_intersight.result.get('api_response', [])
223
224 module.exit_json(**intersight.result)
225
226
227 if __name__ == '__main__':
228 main()