Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_afdorigingroup_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.afdorigingroupsoperations?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_afdorigingroup_info
15 version_added: "3.4.0"
16 short_description: Get Azure Front Door OriginGroup facts to be used with Standard or Premium Frontdoor Service
17 description:
18 - Get facts for a specific Azure Front Door (AFD) OriginGroup or all AFD OriginGroups.
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 name:
23 description:
24 - Limit results to a specific AFD OriginGroup.
25 type: str
26 profile_name:
27 description:
28 - Name of the AFD profile.
29 required: true
30 type: str
31 resource_group:
32 description:
33 - Name of the resource group where this AFD Profile belongs.
34 required: true
35 type: str
36
37 extends_documentation_fragment:
38 - azure.azcollection.azure
39
40 author:
41 - Jarret Tooley (@jartoo)
42 '''
43
44 EXAMPLES = '''
45 - name: Get facts for all OriginGroups in AFD Profile
46 azure_rm_afdorigingroup_info:
47 resource_group: myResourceGroup
48 profile_name: myCDNProfile
49
50 - name: Get facts of specific AFD OriginGroup
51 azure_rm_afdorigingroup_info:
52 name: myOriginGroup1
53 profile_name: myCDNProfile
54 resource_group: myResourceGroup
55 '''
56
57 RETURN = '''
58 afdorigingroups:
59 description: List of AFD OriginGroups.
60 returned: always
61 type: complex
62 contains:
63 deployment_status:
64 description:
65 - Current state of the resource.
66 type: str
67 sample: NotStarted
68 health_probe_settings:
69 description:
70 - Health probe settings to the origin that is used to determine the health of the origin.
71 type: dict
72 contains:
73 probe_interval_in_seconds:
74 description:
75 - The number of seconds between health probes.
76 type: int
77 probe_path:
78 description:
79 - The path relative to the origin that is used to determine the health of the origin.
80 type: str
81 probe_protocol:
82 description:
83 - Protocol to use for health probe.
84 type: str
85 choices:
86 - Http
87 - Https
88 - NotSet
89 probe_request_type:
90 description:
91 - The type of health probe request that is made.
92 type: str
93 choices:
94 - GET
95 - HEAD
96 - NotSet
97 id:
98 description:
99 - ID of the AFD OriginGroup.
100 type: str
101 sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myCDN/providers/Microsoft.Cdn/profiles/myProfile/origingroups/myOG1"
102 load_balancing_settings:
103 description:
104 - Load balancing settings for a backend pool.
105 type: dict
106 contains:
107 additional_latency_in_milliseconds:
108 description:
109 - The additional latency in milliseconds for probes to fall into the lowest latency bucket.
110 type: int
111 sample_size:
112 description:
113 - The number of samples to consider for load balancing decisions.
114 type: int
115 successful_samples_required:
116 description:
117 - The number of samples within the sample period that must succeed.
118 type: int
119 name:
120 description:
121 - Name of the AFD OriginGroup.
122 type: str
123 profile_name:
124 description:
125 - Name of the AFD Profile where the OriginGroup will be added.
126 type: str
127 provisioning_state:
128 description:
129 - Provisioning status of the AFD OriginGroup.
130 type: str
131 sample: Succeeded
132 resource_group:
133 description:
134 - Name of a resource group where the AFD OriginGroup exists or will be created.
135 type: str
136 session_affinity_state:
137 description:
138 - Whether to allow session affinity on this host.
139 type: str
140 choices:
141 - Enabled
142 - Disabled
143 type:
144 description:
145 - Resource type.
146 type: str
147 sample: Microsoft.Cdn/profiles/afdorigingroups
148 '''
149
150 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
151 import re
152
153 AZURE_OBJECT_CLASS = 'AFDOriginGroup'
154
155
156 class AzureRMAFDOriginGroupInfo(AzureRMModuleBase):
157 """Utility class to get Azure AFD OriginGroup facts"""
158
159 def __init__(self):
160
161 self.module_args = dict(
162 name=dict(
163 type='str'
164 ),
165 resource_group=dict(
166 type='str',
167 required=True
168 ),
169 profile_name=dict(
170 type='str',
171 required=True
172 )
173 )
174
175 self.results = dict(
176 changed=False,
177 afdorigingroups=[]
178 )
179
180 self.name = None
181 self.resource_group = None
182 self.profile_name = None
183
184 super(AzureRMAFDOriginGroupInfo, self).__init__(
185 supports_check_mode=True,
186 derived_arg_spec=self.module_args,
187 supports_tags=False,
188 facts_module=True
189 )
190
191 def exec_module(self, **kwargs):
192
193 for key in self.module_args:
194 setattr(self, key, kwargs[key])
195
196 if self.name:
197 self.results['afdorigingroups'] = self.get_item()
198 else:
199 self.results['afdorigingroups'] = self.list_by_profile()
200
201 return self.results
202
203 def get_item(self):
204 """Get a single Azure AFD OriginGroup"""
205
206 self.log('Get properties for {0}'.format(self.name))
207
208 item = None
209 result = []
210
211 try:
212 item = self.cdn_client.afd_origin_groups.get(self.resource_group, self.profile_name, self.name)
213 except Exception:
214 pass
215
216 if item:
217 result = [self.serialize_afdorigingroup(item)]
218
219 return result
220
221 def list_by_profile(self):
222 """Get all Azure AFD OriginGroups within an AFD profile"""
223
224 self.log('List all AFD OriginGroups within an AFD profile')
225
226 try:
227 response = self.cdn_client.afd_origin_groups.list_by_profile(self.resource_group, self.profile_name)
228 except Exception as exc:
229 self.fail('Failed to list all items - {0}'.format(str(exc)))
230
231 results = []
232 for item in response:
233 results.append(self.serialize_afdorigingroup(item))
234
235 return results
236
237 def serialize_afdorigingroup(self, afdorigingroup):
238 '''
239 Convert a AFD OriginGroup object to dict.
240 :param afdorigingroup: AFD OriginGroup object
241 :return: dict
242 '''
243 result = self.serialize_obj(afdorigingroup, AZURE_OBJECT_CLASS)
244
245 new_result = {}
246 new_result['deployment_status'] = afdorigingroup.deployment_status
247 new_result['health_probe_settings'] = dict()
248 new_result['health_probe_settings']['probe_interval_in_seconds'] = afdorigingroup.health_probe_settings.probe_interval_in_seconds
249 new_result['health_probe_settings']['probe_path'] = afdorigingroup.health_probe_settings.probe_path
250 new_result['health_probe_settings']['probe_protocol'] = afdorigingroup.health_probe_settings.probe_protocol
251 new_result['health_probe_settings']['probe_request_type'] = afdorigingroup.health_probe_settings.probe_request_type
252 new_result['id'] = afdorigingroup.id
253 new_result['load_balancing_settings'] = dict()
254 new_result['load_balancing_settings']['additional_latency_in_milliseconds'] = afdorigingroup.load_balancing_settings.additional_latency_in_milliseconds
255 new_result['load_balancing_settings']['sample_size'] = afdorigingroup.load_balancing_settings.sample_size
256 new_result['load_balancing_settings']['successful_samples_required'] = afdorigingroup.load_balancing_settings.successful_samples_required
257 new_result['name'] = afdorigingroup.name
258 new_result['profile_name'] = re.sub('\\/.*', '', re.sub('.*profiles\\/', '', result['id']))
259 new_result['provisioning_state'] = afdorigingroup.provisioning_state
260 new_result['resource_group'] = re.sub('\\/.*', '', re.sub('.*resourcegroups\\/', '', result['id']))
261 new_result['session_affinity_state'] = afdorigingroup.session_affinity_state
262 new_result['type'] = afdorigingroup.type
263 return new_result
264
265
266 def main():
267 """Main module execution code path"""
268 AzureRMAFDOriginGroupInfo()
269
270
271 if __name__ == '__main__':
272 main()