Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2021 Andrii Bilorus <[email protected]>
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_storageshare_info
14 version_added: "1.8.0"
15 short_description: Get Azure storage file share info
16 description:
17 - Get facts for storage file share.
18 options:
19 resource_group:
20 description:
21 - Name of the resource group to use.
22 required: true
23 type: str
24 name:
25 description:
26 - Name of the storage file share.
27 type: str
28 required: false
29 account_name:
30 description:
31 - Name of the parent storage account for the storage file share.
32 required: true
33 type: str
34
35 extends_documentation_fragment:
36 - azure.azcollection.azure
37
38 author:
39 - Andrii Bilorus (@ewscat)
40 '''
41
42 EXAMPLES = '''
43 ---
44 - name: Get storage share details
45 azure_rm_storageshare_info:
46 name: testShare
47 resource_group: myResourceGroup
48 account_name: testStorageAccount
49
50
51 - name: Get all storage file shares in storage account
52 azure_rm_storageshare:
53 resource_group: myResourceGroup
54 account_name: testStorageAccount
55 '''
56
57 RETURN = '''
58 state:
59 description:
60 - Facts about the current state of the storage file share
61 returned: always
62 type: complex
63 contains:
64 id:
65 description:
66 - Resource ID of the storage file share
67 sample: "/subscriptions/9e700857-1631-4d8a-aed5-908520ede375/resourceGroups/myResourceGroup/providers/Microsoft.Storage/
68 storageAccounts/mystorageaccount/fileServices/default/shares/myshare"
69 returned: always
70 type: str
71 name:
72 description:
73 - Name of the file share
74 sample: myshare
75 returned: always
76 type: str
77 type:
78 description:
79 - The type of the resource
80 sample: "Microsoft.Storage/storageAccounts/fileServices/shares"
81 returned: always
82 type: str
83 etag:
84 description:
85 - Resource Etag
86 sample: "0x8D75E4BA3E275F1"
87 returned: always
88 type: str
89 last_modified_time:
90 description:
91 - Returns the date and time the file share was last modified
92 sample: "2021-08-23T08:17:35+00:00"
93 returned: always
94 type: str
95 metadata:
96 description:
97 - A name-value pair to associate with the file share as metadata
98 sample: '{"key1": "value1"}'
99 returned: always
100 type: dict
101 share_quota:
102 description:
103 - The maximum size of the file share, in gigabytes
104 sample: 102400
105 returned: always
106 type: int
107 access_tier:
108 description:
109 - Access tier for specific file share
110 sample: 'TransactionOptimized'
111 returned: always
112 type: str
113 access_tier_change_time:
114 description:
115 - Indicates the last modification time for file share access tier
116 sample: "2021-08-23T08:17:35+00:00"
117 returned: always
118 type: str
119 enabled_protocols:
120 description:
121 - The authentication protocol that is used for the file share.
122 sample: 'SMB'
123 returned: always
124 type: str
125 root_squash:
126 description:
127 - The property is for NFS share only. The default is NoRootSquash.
128 sample: 'NoRootSquash'
129 returned: always
130 type: str
131 version:
132 description:
133 - The version of the file share
134 returned: always
135 type: str
136 deleted:
137 description:
138 - Indicates whether the share was deleted
139 returned: always
140 type: str
141 deleted_time:
142 description:
143 - The deleted time if the share was deleted
144 returned: always
145 type: str
146 remaining_retention_days:
147 description:
148 - Remaining retention days for share that
149 returned: always
150 type: str
151 access_tier_status:
152 description:
153 - Indicates if there is a pending transition for access tier
154 returned: always
155 type: str
156 share_usage_bytes:
157 description:
158 - The approximate size of the data stored on the share. Note that this value may not include
159 all recently created or recently resized files.
160 returned: always
161 type: int
162 '''
163
164 try:
165 from azure.core.exceptions import ResourceNotFoundError
166 except ImportError:
167 # This is handled in azure_rm_common
168 pass
169
170 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
171
172
173 class AzureRMStorageShareInfo(AzureRMModuleBase):
174 '''
175 Info class for an Azure RM Storage share resource
176 '''
177
178 def __init__(self):
179
180 self.module_arg_spec = dict(
181 resource_group=dict(type='str', required=True),
182 name=dict(type='str'),
183 account_name=dict(type='str', required=True),
184 )
185 self.results = dict(
186 changed=False,
187 storageshares=list()
188 )
189
190 self.resource_group = None
191 self.name = None
192 self.account_name = None
193
194 super(AzureRMStorageShareInfo, self).__init__(self.module_arg_spec,
195 supports_check_mode=True,
196 supports_tags=False,
197 facts_module=True)
198
199 def exec_module(self, **kwargs):
200 '''
201 Main module execution method
202 '''
203
204 for key in self.module_arg_spec:
205 setattr(self, key, kwargs[key])
206
207 if self.name:
208 self.results['storageshares'] = self.get_share()
209 else:
210 self.results['storageshares'] = self.list_all()
211
212 return self.results
213
214 def get_share(self):
215 '''
216 Get the properties of the specified Azure Storage file share.
217 :return: dict with properties of the storage file share
218 '''
219 storage_share = None
220 try:
221 storage_share = self.storage_client.file_shares.get(resource_group_name=self.resource_group,
222 account_name=self.account_name,
223 share_name=self.name)
224 self.log("Response : {0}".format(storage_share))
225 except ResourceNotFoundError as e:
226 self.log("Did not find the storage share with name {0} : {1}".format(self.name, str(e)))
227 return self.storage_share_to_dict(storage_share)
228
229 def storage_share_to_dict(self, storage_share):
230 '''
231 Transform Azure RM Storage share object to dictionary
232 :param storage_share: contains information about storage file share
233 :type storage_share: FileShare
234 :return: dict generated from storage_share
235 '''
236 return dict(
237 id=storage_share.id,
238 name=storage_share.name,
239 type=storage_share.type,
240 etag=storage_share.etag.replace('"', ''),
241 last_modified_time=storage_share.last_modified_time,
242 metadata=storage_share.metadata,
243 share_quota=storage_share.share_quota,
244 access_tier=storage_share.access_tier,
245 access_tier_change_time=storage_share.access_tier_change_time,
246 enabled_protocols=storage_share.enabled_protocols,
247 root_squash=storage_share.root_squash,
248 version=storage_share.version,
249 deleted=storage_share.deleted,
250 deleted_time=storage_share.deleted_time,
251 remaining_retention_days=storage_share.remaining_retention_days,
252 access_tier_status=storage_share.access_tier_status,
253 share_usage_bytes=storage_share.share_usage_bytes
254 ) if storage_share else None
255
256 def list_all(self):
257 '''
258 Method calling the Azure SDK to create storage file share.
259 :return: dict with description of the new storage file share
260 '''
261 '''
262 Get the properties of the specified Azure Storage file share.
263 :return: dict with properties of the storage file share
264 '''
265 all_items = None
266 try:
267 storage_shares = self.storage_client.file_shares.list(resource_group_name=self.resource_group,
268 account_name=self.account_name)
269 self.log("Response : {0}".format(storage_shares))
270 all_items = [self.storage_share_to_dict(share) for share in storage_shares]
271 except Exception as e:
272 self.log("Did not find the storage file share : {0}".format(str(e)))
273 return all_items
274
275
276 def main():
277 AzureRMStorageShareInfo()
278
279
280 if __name__ == '__main__':
281 main()