Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_storageaccountmanagementpolicy_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2024 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun)
4 #
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10
11 DOCUMENTATION = '''
12 ---
13 module: azure_rm_storageaccountmanagementpolicy_info
14
15 version_added: "2.4.0"
16
17 short_description: Get the data policy rules associated with the specified storage account
18
19 description:
20 - Get the data policy rules associated with the specified storage account.
21
22 options:
23 resource_group:
24 description:
25 - Name of the resource group to use.
26 required: true
27 type: str
28 aliases:
29 - resource_group_name
30 storage_account_name:
31 description:
32 - Name of the storage account to update or create.
33 type: str
34 required: true
35
36 extends_documentation_fragment:
37 - azure.azcollection.azure
38
39 author:
40 - xuzhang3 (@xuzhang3)
41 - Fred-sun (@Fred-sun)
42 '''
43
44 EXAMPLES = '''
45 - name: Get the data policy rules associated with the specified storage account
46 azure_rm_storageaccountmanagementpolicy_info:
47 resource_group: myResourceGroup
48 storage_account_name: testaccount
49 '''
50
51
52 RETURN = '''
53 state:
54 description:
55 - The data policy rules associated with the specified storage account.
56 returned: always
57 type: complex
58 contains:
59 id:
60 description:
61 - The data policy's ID.
62 returned: always
63 type: str
64 sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Storage/storageAccounts/sttest/managementPolicies/default"
65 resource_group:
66 description:
67 - The resource group name.
68 returned: always
69 type: str
70 sample: testRG
71 storage_account_name:
72 description:
73 - The storage account name.
74 returned: always
75 type: str
76 sample: teststname
77 type:
78 description:
79 - The type of the resource.
80 returned: always
81 type: str
82 sample: "Microsoft.Storage/storageAccounts/managementPolicies"
83 last_modified_time:
84 description:
85 - Returns the date and time the ManagementPolicies was last modified.
86 returned: always
87 type: str
88 sample: "2024-04-12T11:40:10.376465+00:00"
89 name:
90 description:
91 - The name of the resource.
92 returned: always
93 type: str
94 sample: DefaultManagementPolicy
95 policy:
96 description:
97 - The Storage Account ManagementPolicy.
98 returned: always
99 type: complex
100 contains:
101 rules:
102 description:
103 - The Storage Account ManagementPolicies Rules.
104 type: list
105 returned: always
106 sample: [
107 {
108 "definition": {
109 "actions": {
110 "base_blob": {
111 "delete": {
112 "days_after_last_access_time_greater_than": 33.0,
113 "days_after_modification_greater_than": 33.0
114 },
115 "enable_auto_tier_to_hot_from_cool": true,
116 "tier_to_archive": {
117 "days_after_last_access_time_greater_than": 33.0,
118 "days_after_modification_greater_than": 33.0
119 },
120 "tier_to_cool": {
121 "days_after_last_access_time_greater_than": 33.0,
122 "days_after_modification_greater_than": 33.0
123 }
124 },
125 "snapshot": {
126 "delete": {
127 "days_after_creation_greater_than": 33.0
128 },
129 "tier_to_archive": {
130 "days_after_creation_greater_than": 33.0
131 },
132 "tier_to_cool": {
133 "days_after_creation_greater_than": 33.0
134 }
135 },
136 "version": {
137 "delete": {
138 "days_after_creation_greater_than": 33.0
139 },
140 "tier_to_archive": {
141 "days_after_creation_greater_than": 33.0
142 },
143 "tier_to_cool": {
144 "days_after_creation_greater_than": 33.0
145 }
146 }
147 },
148 "filters": {
149 "blob_index_match": [
150 {
151 "name": "tags3",
152 "op": "==",
153 "value": "value3"
154 }
155 ],
156 "blob_types": [
157 "blockBlob",
158 "appendBlob"
159 ],
160 "prefix_match": [
161 "olcmtestcontainer2"
162 ]
163 }
164 },
165 "enabled": false,
166 "name": "olcmtest5",
167 "type": "Lifecycle"
168 }
169 ]
170 '''
171
172
173 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
174 try:
175 from azure.core.exceptions import ResourceNotFoundError
176 except Exception:
177 # This is handled in azure_rm_common
178 pass
179
180
181 class AzureRMStorageAccountManagementPolicyInfo(AzureRMModuleBase):
182
183 def __init__(self):
184
185 self.module_arg_spec = dict(
186 resource_group=dict(required=True, type='str', aliases=['resource_group_name']),
187 storage_account_name=dict(type='str', required=True),
188 )
189
190 self.results = dict(
191 changed=False,
192 state=dict()
193 )
194
195 self.resource_group = None
196 self.storage_account_name = None
197 self.state = None
198 self.rules = None
199
200 super(AzureRMStorageAccountManagementPolicyInfo, self).__init__(self.module_arg_spec,
201 supports_tags=False,
202 supports_check_mode=True)
203
204 def exec_module(self, **kwargs):
205
206 for key in list(self.module_arg_spec.keys()):
207 setattr(self, key, kwargs[key])
208
209 self.results['state'] = self.get_management_policy()
210
211 return self.results
212
213 def get_management_policy(self):
214 self.log('Get info for storage account management policy')
215
216 response = None
217 try:
218 response = self.storage_client.management_policies.get(self.resource_group, self.storage_account_name, 'default')
219 except ResourceNotFoundError as ec:
220 self.log("Failed to obtain the storage acount management policy, detail as {0}".format(ec))
221 return
222
223 return self.format_to_dict(response)
224
225 def format_to_dict(self, obj):
226 result = dict()
227 result['id'] = obj.id
228 result['resource_group'] = self.resource_group
229 result['storage_account_name'] = self.storage_account_name
230 result['name'] = obj.name
231 result['type'] = obj.type
232 result['last_modified_time'] = obj.last_modified_time
233 result['policy'] = dict(rules=[])
234 if obj.policy is not None:
235 result['policy'] = obj.policy.as_dict()
236
237 return result
238
239
240 def main():
241 AzureRMStorageAccountManagementPolicyInfo()
242
243
244 if __name__ == '__main__':
245 main()