Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4 #
5 # Python SDK Reference: https://learn.microsoft.com/en-us/python/api/azure-mgmt-cdn/azure.mgmt.cdn.operations.afdoriginsoperations?view=azure-python
6 #
7
8 from __future__ import absolute_import, division, print_function
9 __metaclass__ = type
10
11
12 DOCUMENTATION = '''
13 ---
14 module: azure_rm_afdorigin_info
15 version_added: "3.4.0"
16 short_description: Get Azure Front Door Origin facts to be used with Standard or Premium Frontdoor Service
17 description:
18 - Get facts for a specific Azure Front Door (AFD) Origin or all AFD Origins.
19 - This differs from the Front Door classic service and only is intended to be used by the Standard or Premium service offering.
20
21 options:
22 resource_group:
23 description:
24 - Name of the resource group where this AFD Profile belongs.
25 required: true
26 type: str
27 origin_group_name:
28 description:
29 - Name of the origin group which is unique within the profile.
30 required: true
31 type: str
32 profile_name:
33 description:
34 - Name of the AFD profile.
35 required: true
36 type: str
37 name:
38 description:
39 - Limit results to a specific AFD Origin.
40 type: str
41
42 extends_documentation_fragment:
43 - azure.azcollection.azure
44
45 author:
46 - Jarret Tooley (@jartoo)
47 '''
48
49 EXAMPLES = '''
50 - name: Get facts for all Origins in AFD Profile
51 azure_rm_afdorigin_info:
52 resource_group: myResourceGroup
53 profile_name: myCDNProfile
54
55 - name: Get facts of specific AFD Origin
56 azure_rm_afdorigin_info:
57 name: myOrigin1
58 profile_name: myCDNProfile
59 resource_group: myResourceGroup
60 '''
61
62 RETURN = '''
63 afdorigins:
64 description: List of AFD Origins.
65 returned: always
66 type: complex
67 contains:
68 azure_origin:
69 description:
70 - Resource reference to the AFD origin resource.
71 type: str
72 deployment_status:
73 description:
74 - Current state of the resource.
75 type: str
76 sample: NotStarted
77 enabled_state:
78 description:
79 - Whether to enable health probes to be made against backends defined under backend pools.
80 - Health probes can only be disabled if there is a single enabled backend in single enabled backend pool.
81 type: str
82 sample: Enabled
83 host_name:
84 description:
85 - The address of the origin. Domain names, IPv4 addresses, and IPv6 addresses are supported.
86 - This should be unique across all origins in an endpoint.
87 type: str
88 http_port:
89 description:
90 - The value of the HTTP port. Must be between 1 and 65535.
91 type: int
92 sample: 80
93 https_port:
94 description:
95 - The value of the HTTPS port. Must be between 1 and 65535.
96 type: int
97 sample: 443
98 id:
99 description:
100 - ID of the AFD Origin.
101 type: str
102 sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxx/resourcegroups/myRG/providers/Microsoft.Cdn/profiles/myProf/origingroups/myOG/origins/myO"
103 name:
104 description:
105 - Name of the AFD Origin.
106 type: str
107 origin_group_name:
108 description:
109 - Name of the origin group which is unique within the profile.
110 type: str
111 origin_host_header:
112 description:
113 - The host header value sent to the origin with each request. If you leave this blank, the request hostname determines this value.
114 - Azure Front Door origins, such as Web Apps, Blob Storage, and Cloud Services require this host header value to match the origin
115 - hostname by default. This overrides the host header defined at the AFD Endpoint.
116 type: str
117 priority:
118 description:
119 - Priority of origin in given origin group for load balancing. Higher priorities will not be used for load balancing if any
120 - lower priority origin is healthy. Must be between 1 and 5.
121 type: int
122 profile_name:
123 description:
124 - Name of the AFD Profile where the Origin will be added.
125 type: str
126 provisioning_state:
127 description:
128 - Provisioning status of the AFD Origin.
129 type: str
130 sample: Succeeded
131 resource_group:
132 description:
133 - Name of a resource group where the AFD Origin exists or will be created.
134 type: str
135 shared_private_link_resource:
136 description:
137 - The properties of the private link resource for private origin.
138 type: dict
139 contains:
140 group_id:
141 description:
142 - The group id from the provider of resource the shared private link resource is for.
143 type: str
144 private_link:
145 description:
146 - The resource id of the resource the shared private link resource is for.
147 type: str
148 private_link_location:
149 description:
150 - The location of the shared private link resource.
151 type: str
152 request_message:
153 description:
154 - The request message for requesting approval of the shared private link resource.
155 type: str
156 status:
157 description:
158 - Status of the shared private link resource. Can be Pending, Approved, Rejected, Disconnected, or Timeout.
159 type: str
160 sample: Approved
161 type:
162 description:
163 - Resource type.
164 type: str
165 sample: Microsoft.Cdn/profiles/origingroups/origins
166 weight:
167 description:
168 - Weight of the origin in given origin group for load balancing. Must be between 1 and 1000.
169 type: int
170 '''
171
172 import re
173 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
174
175
176 AZURE_OBJECT_CLASS = 'AFDOrigin'
177
178
179 class AzureRMAFDOriginInfo(AzureRMModuleBase):
180 """Utility class to get Azure AFD Origin facts"""
181
182 def __init__(self):
183
184 self.module_args = dict(
185 name=dict(type='str'),
186 origin_group_name=dict(
187 type='str',
188 required=True
189 ),
190 profile_name=dict(
191 type='str',
192 required=True
193 ),
194 resource_group=dict(
195 type='str',
196 required=True
197 )
198 )
199
200 self.results = dict(
201 changed=False,
202 afdorigins=[]
203 )
204
205 self.name = None
206 self.origin_group_name = None
207 self.resource_group = None
208 self.profile_name = None
209
210 super(AzureRMAFDOriginInfo, self).__init__(
211 supports_check_mode=True,
212 derived_arg_spec=self.module_args,
213 supports_tags=False,
214 facts_module=True
215 )
216
217 def exec_module(self, **kwargs):
218
219 for key in self.module_args:
220 setattr(self, key, kwargs[key])
221
222 if self.name:
223 self.results['afdorigins'] = self.get_item()
224 else:
225 self.results['afdorigins'] = self.list_by_profile()
226
227 return self.results
228
229 def get_item(self):
230 """Get a single Azure AFD Origin"""
231
232 self.log('Get properties for {0}'.format(self.name))
233
234 item = None
235 result = []
236
237 try:
238 item = self.cdn_client.afd_origins.get(resource_group_name=self.resource_group,
239 profile_name=self.profile_name,
240 origin_group_name=self.origin_group_name,
241 origin_name=self.name)
242 except Exception as exc:
243 self.log("Did not find resource. {0}".format(str(exc)))
244
245 if item:
246 result = [self.serialize_afdorigin(item)]
247
248 return result
249
250 def list_by_profile(self):
251 """Get all Azure AFD Origins within an AFD profile"""
252
253 self.log('List all AFD Origins within an AFD profile')
254
255 try:
256 response = self.cdn_client.afd_origins.list_by_origin_group(resource_group_name=self.resource_group,
257 profile_name=self.profile_name,
258 origin_group_name=self.origin_group_name)
259 except Exception as exc:
260 self.fail('Failed to list all origins. {0}'.format(str(exc)))
261
262 results = []
263 for item in response:
264 results.append(self.serialize_afdorigin(item))
265
266 return results
267
268 def serialize_afdorigin(self, afdorigin):
269 '''
270 Convert a AFD Origin object to dict.
271 :param afdorigin: AFD Origin object
272 :return: dict
273 '''
274 result = self.serialize_obj(afdorigin, AZURE_OBJECT_CLASS)
275
276 new_result = {}
277 new_result['azure_origin'] = afdorigin.azure_origin
278 new_result['deployment_status'] = afdorigin.deployment_status
279 new_result['enabled_state'] = afdorigin.enabled_state
280 new_result['host_name'] = afdorigin.host_name
281 new_result['http_port'] = afdorigin.http_port
282 new_result['https_port'] = afdorigin.https_port
283 new_result['https_port'] = afdorigin.https_port
284 new_result['id'] = afdorigin.id
285 new_result['name'] = afdorigin.name
286 new_result['origin_group_name'] = re.sub('\\/.*', '', re.sub('.*origingroups\\/', '', result['id']))
287 new_result['origin_host_header'] = afdorigin.origin_host_header
288 new_result['priority'] = afdorigin.priority
289 new_result['provisioning_state'] = afdorigin.provisioning_state
290 new_result['priority'] = afdorigin.priority
291 new_result['profile_name'] = re.sub('\\/.*', '', re.sub('.*profiles\\/', '', result['id']))
292 new_result['resource_group'] = re.sub('\\/.*', '', re.sub('.*resourcegroups\\/', '', result['id']))
293 new_result['shared_private_link_resource'] = dict()
294 if afdorigin.shared_private_link_resource:
295 new_result['shared_private_link_resource']['group_id'] = afdorigin.shared_private_link_resource.group_id
296 new_result['shared_private_link_resource']['private_link'] = afdorigin.shared_private_link_resource.private_link
297 new_result['shared_private_link_resource']['private_link_location'] = afdorigin.shared_private_link_resource.private_link_location
298 new_result['shared_private_link_resource']['request_message'] = afdorigin.shared_private_link_resource.request_message
299 new_result['shared_private_link_resource']['status'] = afdorigin.shared_private_link_resource.status
300 else:
301 new_result['shared_private_link_resource']['group_id'] = None
302 new_result['shared_private_link_resource']['private_link'] = None
303 new_result['shared_private_link_resource']['private_link_location'] = None
304 new_result['shared_private_link_resource']['request_message'] = None
305 new_result['shared_private_link_resource']['status'] = None
306 new_result['type'] = afdorigin.type
307 new_result['weight'] = afdorigin.weight
308 return new_result
309
310
311 def main():
312 """Main module execution code path"""
313 AzureRMAFDOriginInfo()
314
315
316 if __name__ == '__main__':
317 main()