Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2018 Fred-sun, <[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_datafactory_info
14 version_added: "0.1.12"
15 short_description: Get data factory facts
16 description:
17 - Get facts for a specific data factory.
18
19 options:
20 name:
21 description:
22 - The factory name.
23 type: str
24 resource_group:
25 description:
26 - Limit results by resource group. Required when using name parameter.
27 type: str
28 if_none_match:
29 description:
30 - ETag of the factory entity.
31 - Should only be specified for get.
32 - If the ETag matches the existing entity tag, or if * was provided, then no content will be returned.
33 type: str
34 tags:
35 description:
36 - Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
37 type: list
38 elements: str
39
40 extends_documentation_fragment:
41 - azure.azcollection.azure
42
43 author:
44 - Fred-sun (@Fred-sun)
45 - xuzhang3 (@xuzhang3)
46 '''
47
48 EXAMPLES = '''
49 - name: Get data factory by name
50 azure_rm_datafactory_info:
51 resource_group: "{{ resource_group }}"
52 name: "{{ name }}"
53
54 - name: Get data factory by resource group
55 azure_rm_datafactory_info:
56 resource_group: "{{ resource_group }}"
57
58 - name: Get data factory in relate subscription
59 azure_rm_datafactory_info:
60 tags:
61 - key1
62 '''
63
64 RETURN = '''
65 datafactory:
66 description:
67 - Current state fo the data factory.
68 returned: always
69 type: complex
70 contains:
71 id:
72 description:
73 - The data facotry ID.
74 type: str
75 returned: always
76 sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.DataFactory/factories/testpro"
77 create_time:
78 description:
79 - Time the factory was created in ISO8601 format.
80 type: str
81 returned: always
82 sample: "2022-04-26T08:24:41.391164+00:00"
83 location:
84 description:
85 - The resource location.
86 type: str
87 returned: always
88 sample: eastus
89 name:
90 description:
91 - The resource name.
92 type: str
93 returned: always
94 sample: testfactory
95 provisioning_state:
96 description:
97 - Factory provisioning state, example Succeeded.
98 type: str
99 returned: always
100 sample: Succeeded
101 e_tag:
102 description:
103 - Etag identifies change in the resource.
104 type: str
105 returned: always
106 sample: "3000fa80-0000-0100-0000-6267ac490000"
107 type:
108 description:
109 - The resource type.
110 type: str
111 returned: always
112 sample: "Microsoft.DataFactory/factories"
113 public_network_access:
114 description:
115 - Whether or not public network access is allowed for the data factory.
116 type: str
117 returned: always
118 sample: "Enabled"
119 tags:
120 description:
121 - List the data factory tags.
122 type: str
123 returned: always
124 sample: {'key1':'value1'}
125 identity:
126 description:
127 - Managed service identity of the factory.
128 type: str
129 returned: always
130 contains:
131 principal_id:
132 description:
133 - The principal id of the identity.
134 type: str
135 returned: always
136 sample: "***********"
137 tenant_id:
138 description:
139 - The client tenant id of the identity.
140 type: str
141 returned: always
142 sample: "***********"
143 repo_configuration:
144 description:
145 - Git repo information of the factory.
146 type: str
147 returned: always
148 contains:
149 type:
150 description:
151 - Type of repo configuration.
152 type: str
153 returned: always
154 sample: FactoryGitHubConfiguration
155 ccount_name:
156 description:
157 - Account name.
158 type: str
159 returned: always
160 sample: fredaccount
161 collaboration_branch:
162 description:
163 - Collaboration branch.
164 type: str
165 returned: always
166 sample: branch
167 repository_name:
168 description:
169 - Repository name.
170 type: str
171 returned: always
172 sample: "vault"
173 root_folder:
174 description:
175 - Root folder.
176 type: str
177 returned: always
178 sample: "/home/"
179 '''
180
181 try:
182 from azure.core.exceptions import ResourceNotFoundError
183 except Exception:
184 # This is handled in azure_rm_common
185 pass
186
187 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
188
189 AZURE_OBJECT_CLASS = 'DataFactoryInfo'
190
191
192 class AzureRMDataFactoryInfo(AzureRMModuleBase):
193
194 def __init__(self):
195
196 self.module_arg_spec = dict(
197 name=dict(type='str'),
198 resource_group=dict(type='str'),
199 if_none_match=dict(type='str'),
200 tags=dict(type='list', elements='str')
201 )
202
203 self.results = dict(
204 changed=False,
205 )
206
207 self.name = None
208 self.resource_group = None
209 self.if_none_match = None
210 self.tags = None
211
212 super(AzureRMDataFactoryInfo, self).__init__(self.module_arg_spec,
213 supports_check_mode=True,
214 supports_tags=False,
215 facts_module=True)
216
217 def exec_module(self, **kwargs):
218
219 for key in self.module_arg_spec:
220 setattr(self, key, kwargs[key])
221
222 result = []
223
224 if self.name and self.resource_group:
225 result = self.get_item()
226 elif self.resource_group:
227 result = self.list_by_resourcegroup()
228 else:
229 result = self.list_all()
230
231 self.results['datafactory'] = self.format(result)
232
233 return self.results
234
235 def format(self, raw):
236 results = []
237 for item in raw:
238 if self.has_tags(item.tags, self.tags):
239 results.append(self.pip_to_dict(item))
240 return results
241
242 def pip_to_dict(self, pip):
243 result = dict(
244 id=pip.id,
245 name=pip.name,
246 type=pip.type,
247 location=pip.location,
248 tags=pip.tags,
249 e_tag=pip.e_tag,
250 provisioning_state=pip.provisioning_state,
251 create_time=pip.create_time,
252 repo_configuration=dict(),
253 identity=dict(),
254 public_network_access=pip.public_network_access,
255 )
256 if pip.identity:
257 result['identity']['principal_id'] = pip.identity.principal_id
258 result['identity']['tenant_id'] = pip.identity.tenant_id
259 if pip.repo_configuration:
260 result['repo_configuration']['type'] = pip.repo_configuration.type
261 result['repo_configuration']['account_name'] = pip.repo_configuration.account_name
262 result['repo_configuration']['repository_name'] = pip.repo_configuration.repository_name
263 result['repo_configuration']['collaboration_branch'] = pip.repo_configuration.collaboration_branch
264 result['repo_configuration']['root_folder'] = pip.repo_configuration.root_folder
265 if pip.repo_configuration.type == "FactoryVSTSConfiguration":
266 result['repo_configuration']['project_name'] = pip.repo_configuration.project_name
267 return result
268
269 def get_item(self):
270 response = None
271 self.log('Get properties for {0}'.format(self.name))
272 try:
273 response = self.datafactory_client.factories.get(self.resource_group, self.name, self.if_none_match)
274 except ResourceNotFoundError:
275 pass
276 return [response] if response else []
277
278 def list_by_resourcegroup(self):
279 self.log("Get GitHub Access Token Response")
280 try:
281 response = self.datafactory_client.factories.list_by_resource_group(self.resource_group)
282 except Exception:
283 pass
284 return response if response else []
285
286 def list_all(self):
287 self.log("Get GitHub Access Token Response")
288 try:
289 response = self.datafactory_client.factories.list()
290 except Exception:
291 pass
292 return response if response else []
293
294
295 def main():
296 AzureRMDataFactoryInfo()
297
298
299 if __name__ == '__main__':
300 main()