Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_afdroute_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.routesoperations?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_afdroute_info
15 version_added: "3.4.0"
16 short_description: Get Azure Front Door Route facts to be used with Standard or Premium Frontdoor Service
17 description:
18 - Get facts for a specific Azure Front Door (AFD) Route or all AFD Routes.
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 endpoint_name:
23 description:
24 - Name of the endpoint under the profile which is unique globally.
25 required: true
26 type: str
27 name:
28 description:
29 - Name of the route.
30 type: str
31 profile_name:
32 description:
33 - Name of the Azure Front Door Standard or Azure Front Door Premium profile which is unique within the resource group
34 required: true
35 type: str
36 resource_group:
37 description:
38 - Name of the Resource group within the Azure subscription.
39 required: true
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 Routes in the AFD Profile
51 azure_rm_afdroute_info:
52 endpoint_name: myEndpoint
53 profile_name: myProfile
54 resource_group: myResourceGroup
55
56 - name: Get facts of specific AFD Route
57 azure_rm_afdroute_info:
58 name: myRoute1
59 endpoint_name: myEndpoint
60 profile_name: myProfile
61 resource_group: myResourceGroup
62 '''
63
64 RETURN = '''
65 afdroutes:
66 description: List of AFD Routes.
67 returned: always
68 type: complex
69 contains:
70 content_types_to_compress:
71 description:
72 - List of content types (str) on which compression applies. The value should be a valid MIME type.
73 type: list
74 custom_domains:
75 description:
76 - Domain id's referenced by this endpoint.
77 type: list
78 deployment_status:
79 description:
80 - Current state of the resource.
81 type: str
82 sample: NotStarted
83 enabled_state:
84 description:
85 - Whether to enable use of this rule.
86 type: str
87 endpoint_name:
88 description:
89 - Name of the endpoint.
90 type: str
91 forwarding_protocol:
92 description:
93 - Protocol this rule will use when forwarding traffic to backends.
94 type: str
95 https_redirect:
96 description:
97 - Whether to automatically redirect HTTP traffic to HTTPS traffic.
98 - Note that this is a easy way to set up this rule and it will be the first rule that gets executed.
99 type: str
100 id:
101 description:
102 - ID of the AFD Route.
103 type: str
104 sample: "/subscriptions/xxxxx-xxxx-xxxx-xxxx-xxxxxx/resourcegroups/myRG/providers/Microsoft.Cdn/profiles/myProf/routegroups/myRtGrp/routes/myRt"
105 is_compression_enabled:
106 description:
107 - Indicates whether content compression is enabled on AzureFrontDoor. If compression is enabled,
108 - content will be served as compressed if user requests for a compressed version. Content won't be compressed
109 - on AzureFrontDoor when requested content is smaller than 1 byte or larger than 1 MB.
110 type: bool
111 link_to_default_domain:
112 description:
113 - Whether this route will be linked to the default endpoint domain.
114 type: str
115 name:
116 description:
117 - Name of the AFD Route.
118 type: str
119 origin_group_id:
120 description:
121 - The origin group id.
122 type: str
123 sample: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/resourcegroups/myRG/providers/Microsoft.Cdn/profiles/myProf/origingroups/myOG
124 origin_path:
125 description:
126 - A directory path on the origin that AzureFrontDoor can use to retrieve content from, e.g. contoso.cloudapp.net/originpath.
127 type: str
128 patterns_to_match:
129 description:
130 - The route patterns of the rule.
131 type: list
132 profile_name:
133 description:
134 - Name of the AFD Profile where the Route is.
135 type: str
136 provisioning_state:
137 description:
138 - Provisioning status of the AFD Route.
139 type: str
140 sample: Succeeded
141 query_parameters:
142 description:
143 - query parameters to include or exclude (comma separated).
144 type: str
145 query_string_caching_behavior:
146 description:
147 - Defines how Frontdoor caches requests that include query strings. You can ignore any query strings when caching,
148 - ignore specific query strings, cache every request with a unique URL, or cache specific query strings.
149 type: str
150 resource_group_name:
151 description:
152 - Name of a resource group where the AFD Route exists.
153 type: str
154 rule_sets:
155 description:
156 - List of rule set id referenced by this endpoint.
157 type: list
158 supported_protocols:
159 description:
160 - List of supported protocols for this route.
161 type: list
162 type:
163 description:
164 - Resource type.
165 type: str
166 sample: Microsoft.Cdn/profiles/afdendpoints/routes
167 '''
168
169 import re
170 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
171
172
173 AZURE_OBJECT_CLASS = 'AFDRoute'
174
175
176 class AzureRMAFDRouteInfo(AzureRMModuleBase):
177 """Utility class to get Azure AFD Route facts"""
178
179 def __init__(self):
180
181 self.module_args = dict(
182 name=dict(type='str'),
183 endpoint_name=dict(
184 type='str',
185 required=True
186 ),
187 profile_name=dict(
188 type='str',
189 required=True
190 ),
191 resource_group=dict(
192 type='str',
193 required=True
194 )
195 )
196
197 self.results = dict(
198 changed=False,
199 afdroutes=[]
200 )
201
202 self.name = None
203 self.endpoint_name = None
204 self.resource_group = None
205 self.profile_name = None
206
207 super(AzureRMAFDRouteInfo, self).__init__(
208 supports_check_mode=True,
209 derived_arg_spec=self.module_args,
210 supports_tags=False,
211 facts_module=True
212 )
213
214 def exec_module(self, **kwargs):
215
216 for key in self.module_args:
217 setattr(self, key, kwargs[key])
218
219 if self.name:
220 self.results['afdroutes'] = self.get_item()
221 else:
222 self.results['afdroutes'] = self.list_by_endpoint()
223
224 return self.results
225
226 def get_item(self):
227 """Get a single Azure AFD Route"""
228
229 self.log('Get properties for {0}'.format(self.name))
230
231 item = None
232 result = []
233
234 try:
235 item = self.cdn_client.routes.get(
236 resource_group_name=self.resource_group,
237 profile_name=self.profile_name,
238 endpoint_name=self.endpoint_name,
239 route_name=self.name
240 )
241 except Exception as exc:
242 self.log("Failed to find an existing resource. {0}".format(str(exc)))
243
244 if item:
245 result = [self.serialize_afdroute(item)]
246
247 return result
248
249 def list_by_endpoint(self):
250 """Get all Azure AFD Routes within an AFD profile"""
251
252 self.log('List all AFD Routes within an AFD profile')
253
254 try:
255 response = self.cdn_client.routes.list_by_endpoint(
256 resource_group_name=self.resource_group,
257 profile_name=self.profile_name,
258 endpoint_name=self.endpoint_name
259 )
260 except Exception as exc:
261 self.fail('Failed to list all items - {0}'.format(str(exc)))
262
263 results = []
264 for item in response:
265 results.append(self.serialize_afdroute(item))
266
267 return results
268
269 def serialize_afdroute(self, afdroute):
270 '''
271 Convert a AFD Route object to dict.
272 :param afdroute: AFD Route object
273 :return: dict
274 '''
275 result = self.serialize_obj(afdroute, AZURE_OBJECT_CLASS)
276
277 new_result = {}
278 new_result['content_types_to_compress'] = None
279 new_result['is_compression_enabled'] = None
280 new_result['query_parameters'] = None
281 new_result['query_string_caching_behavior'] = None
282 if afdroute.cache_configuration:
283 new_result['content_types_to_compress'] = \
284 afdroute.cache_configuration.compression_settings.content_types_to_compress
285 new_result['is_compression_enabled'] = \
286 afdroute.cache_configuration.compression_settings.is_compression_enabled
287 new_result['query_parameters'] = afdroute.cache_configuration.query_parameters
288 new_result['query_string_caching_behavior'] = afdroute.cache_configuration.query_string_caching_behavior
289 new_result['custom_domains'] = []
290 for domain in afdroute.custom_domains:
291 dom = {
292 "id": domain.id,
293 "is_active": domain.is_active
294 }
295 new_result['custom_domains'].append(dom)
296 new_result['deployment_status'] = afdroute.deployment_status
297 new_result['enabled_state'] = afdroute.enabled_state
298 new_result['endpoint_name'] = self.endpoint_name
299 new_result['forwarding_protocol'] = afdroute.forwarding_protocol
300 new_result['https_redirect'] = afdroute.https_redirect
301 new_result['id'] = afdroute.id
302 new_result['link_to_default_domain'] = afdroute.link_to_default_domain
303 new_result['name'] = afdroute.name
304 new_result['origin_group_id'] = afdroute.origin_group.id
305 new_result['origin_path'] = afdroute.origin_path
306 new_result['patterns_to_match'] = afdroute.patterns_to_match
307 new_result['provisioning_state'] = afdroute.provisioning_state
308 new_result['rule_sets'] = []
309 for rule_set in afdroute.rule_sets:
310 new_result['rule_sets'].append(rule_set.id)
311 new_result['profile_name'] = re.sub('\\/.*', '', re.sub('.*profiles\\/', '', result['id']))
312 new_result['resource_group_name'] = re.sub('\\/.*', '', re.sub('.*resourcegroups\\/', '', result['id']))
313 new_result['supported_protocols'] = afdroute.supported_protocols
314 new_result['type'] = afdroute.type
315 return new_result
316
317
318 def main():
319 """Main module execution code path"""
320 AzureRMAFDRouteInfo()
321
322
323 if __name__ == '__main__':
324 main()