| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: azure_rm_afdendpoint_info |
| 14 |
version_added: "2.7.0" |
| 15 |
short_description: Get Azure Front Door Endpoint facts to be used with Standard or Premium Frontdoor Service |
| 16 |
description: |
| 17 |
- Get facts for a specific Azure Front Door (AFD) Endpoint or all AFD Endpoints. |
| 18 |
- This differs from the Front Door classic service and only is intended to be used by the Standard or Premium service offering. |
| 19 |
|
| 20 |
options: |
| 21 |
resource_group: |
| 22 |
description: |
| 23 |
- Name of the resource group where this AFD Profile belongs. |
| 24 |
required: true |
| 25 |
type: str |
| 26 |
profile_name: |
| 27 |
description: |
| 28 |
- Name of the AFD profile. |
| 29 |
required: true |
| 30 |
type: str |
| 31 |
name: |
| 32 |
description: |
| 33 |
- Limit results to a specific AFD Endpoint. |
| 34 |
type: str |
| 35 |
tags: |
| 36 |
description: |
| 37 |
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'. |
| 38 |
type: list |
| 39 |
elements: str |
| 40 |
|
| 41 |
extends_documentation_fragment: |
| 42 |
- azure.azcollection.azure |
| 43 |
|
| 44 |
author: |
| 45 |
- Jarret Tooley (@jartoo) |
| 46 |
''' |
| 47 |
|
| 48 |
EXAMPLES = ''' |
| 49 |
- name: Get facts for all Endpoints in AFD Profile |
| 50 |
azure_rm_afdendpoint_info: |
| 51 |
resource_group: myResourceGroup |
| 52 |
profile_name: myCDNProfile |
| 53 |
tags: |
| 54 |
- key |
| 55 |
- key:value |
| 56 |
|
| 57 |
- name: Get facts of specific AFD Endpoint |
| 58 |
azure_rm_afdendpoint_info: |
| 59 |
resource_group: myResourceGroup |
| 60 |
profile_name: myCDNProfile |
| 61 |
name: myEndpoint1 |
| 62 |
''' |
| 63 |
|
| 64 |
RETURN = ''' |
| 65 |
afdendpoints: |
| 66 |
description: List of AFD Endpoints. |
| 67 |
returned: always |
| 68 |
type: complex |
| 69 |
contains: |
| 70 |
auto_generated_domain_name_label_scope: |
| 71 |
description: |
| 72 |
- Indicates the endpoint name reuse scope. |
| 73 |
type: str |
| 74 |
sample: TenantReuse |
| 75 |
deployment_status: |
| 76 |
description: |
| 77 |
- Current state of the resource. |
| 78 |
type: str |
| 79 |
sample: NotStarted |
| 80 |
enabled_state: |
| 81 |
description: |
| 82 |
- Whether to enable use of this rule. |
| 83 |
type: str |
| 84 |
sample: Enabled |
| 85 |
host_name: |
| 86 |
description: |
| 87 |
- The host name of the AFD Endpoint structured as endpointName.DNSZone. |
| 88 |
type: str |
| 89 |
sample: contoso.azureedge.net |
| 90 |
id: |
| 91 |
description: |
| 92 |
- ID of the AFD Endpoint. |
| 93 |
type: str |
| 94 |
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myCDN/providers/Microsoft.Cdn/profiles/myProf/endpoints/myEndpoint1" |
| 95 |
location: |
| 96 |
description: |
| 97 |
- Location of the AFD Endpoint. |
| 98 |
type: str |
| 99 |
sample: Global |
| 100 |
name: |
| 101 |
description: |
| 102 |
- Name of the AFD Endpoint. |
| 103 |
returned: always |
| 104 |
type: str |
| 105 |
sample: myEndpoint |
| 106 |
profile_name: |
| 107 |
description: |
| 108 |
- Name of the AFD Profile which holds the Endpoint. |
| 109 |
returned: always |
| 110 |
type: str |
| 111 |
sample: myProfile |
| 112 |
provisioning_state: |
| 113 |
description: |
| 114 |
- Provisioning status of the AFD Endpoint. |
| 115 |
type: str |
| 116 |
sample: Succeeded |
| 117 |
resource_group: |
| 118 |
description: |
| 119 |
- Name of a resource group where the AFD Endpoint exists. |
| 120 |
returned: always |
| 121 |
type: str |
| 122 |
sample: myResourceGroup |
| 123 |
tags: |
| 124 |
description: |
| 125 |
- The tags of the AFD Endpoint. |
| 126 |
type: list |
| 127 |
sample: foo |
| 128 |
type: |
| 129 |
description: |
| 130 |
- Resource type. |
| 131 |
type: str |
| 132 |
sample: Microsoft.Cdn/profiles/afdendpoints |
| 133 |
''' |
| 134 |
|
| 135 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 136 |
import re |
| 137 |
|
| 138 |
AZURE_OBJECT_CLASS = 'AFDEndpoint' |
| 139 |
|
| 140 |
|
| 141 |
class AzureRMAFDEndpointInfo(AzureRMModuleBase): |
| 142 |
"""Utility class to get Azure AFD Endpoint facts""" |
| 143 |
|
| 144 |
def __init__(self): |
| 145 |
|
| 146 |
self.module_args = dict( |
| 147 |
name=dict(type='str'), |
| 148 |
resource_group=dict( |
| 149 |
type='str', |
| 150 |
required=True |
| 151 |
), |
| 152 |
profile_name=dict( |
| 153 |
type='str', |
| 154 |
required=True |
| 155 |
), |
| 156 |
tags=dict( |
| 157 |
type='list', |
| 158 |
elements='str' |
| 159 |
) |
| 160 |
) |
| 161 |
|
| 162 |
self.results = dict( |
| 163 |
changed=False, |
| 164 |
afdendpoints=[] |
| 165 |
) |
| 166 |
|
| 167 |
self.name = None |
| 168 |
self.resource_group = None |
| 169 |
self.profile_name = None |
| 170 |
self.tags = None |
| 171 |
|
| 172 |
super(AzureRMAFDEndpointInfo, self).__init__( |
| 173 |
supports_check_mode=True, |
| 174 |
derived_arg_spec=self.module_args, |
| 175 |
supports_tags=False, |
| 176 |
facts_module=True |
| 177 |
) |
| 178 |
|
| 179 |
def exec_module(self, **kwargs): |
| 180 |
|
| 181 |
for key in self.module_args: |
| 182 |
setattr(self, key, kwargs[key]) |
| 183 |
|
| 184 |
if self.name: |
| 185 |
self.results['afdendpoints'] = self.get_item() |
| 186 |
else: |
| 187 |
self.results['afdendpoints'] = self.list_by_profile() |
| 188 |
|
| 189 |
return self.results |
| 190 |
|
| 191 |
def get_item(self): |
| 192 |
"""Get a single Azure AFD Endpoint""" |
| 193 |
|
| 194 |
self.log('Get properties for {0}'.format(self.name)) |
| 195 |
|
| 196 |
item = None |
| 197 |
result = [] |
| 198 |
|
| 199 |
try: |
| 200 |
item = self.cdn_client.afd_endpoints.get(self.resource_group, self.profile_name, self.name) |
| 201 |
except Exception: |
| 202 |
pass |
| 203 |
|
| 204 |
if item and self.has_tags(item.tags, self.tags): |
| 205 |
result = [self.serialize_afdendpoint(item)] |
| 206 |
|
| 207 |
return result |
| 208 |
|
| 209 |
def list_by_profile(self): |
| 210 |
"""Get all Azure AFD Endpoints within an AFD profile""" |
| 211 |
|
| 212 |
self.log('List all AFD Endpoints within an AFD profile') |
| 213 |
|
| 214 |
try: |
| 215 |
response = self.cdn_client.afd_endpoints.list_by_profile(self.resource_group, self.profile_name) |
| 216 |
except Exception as exc: |
| 217 |
self.fail('Failed to list all items - {0}'.format(str(exc))) |
| 218 |
|
| 219 |
results = [] |
| 220 |
for item in response: |
| 221 |
if self.has_tags(item.tags, self.tags): |
| 222 |
results.append(self.serialize_afdendpoint(item)) |
| 223 |
|
| 224 |
return results |
| 225 |
|
| 226 |
def serialize_afdendpoint(self, afdendpoint): |
| 227 |
''' |
| 228 |
Convert a AFD Endpoint object to dict. |
| 229 |
:param afdendpoint: AFD Endpoint object |
| 230 |
:return: dict |
| 231 |
''' |
| 232 |
result = self.serialize_obj(afdendpoint, AZURE_OBJECT_CLASS) |
| 233 |
|
| 234 |
new_result = {} |
| 235 |
new_result['auto_generated_domain_name_label_scope'] = afdendpoint.auto_generated_domain_name_label_scope |
| 236 |
new_result['deployment_status'] = afdendpoint.deployment_status |
| 237 |
new_result['enabled_state'] = afdendpoint.enabled_state |
| 238 |
new_result['host_name'] = afdendpoint.host_name |
| 239 |
new_result['id'] = afdendpoint.id |
| 240 |
new_result['location'] = afdendpoint.location |
| 241 |
new_result['name'] = afdendpoint.name |
| 242 |
new_result['profile_name'] = re.sub('\\/.*', '', re.sub('.*profiles\\/', '', result['id'])) |
| 243 |
new_result['provisioning_state'] = afdendpoint.provisioning_state |
| 244 |
new_result['resource_group'] = re.sub('\\/.*', '', re.sub('.*resourcegroups\\/', '', result['id'])) |
| 245 |
new_result['tags'] = afdendpoint.tags |
| 246 |
new_result['type'] = afdendpoint.type |
| 247 |
return new_result |
| 248 |
|
| 249 |
|
| 250 |
def main(): |
| 251 |
"""Main module execution code path""" |
| 252 |
|
| 253 |
AzureRMAFDEndpointInfo() |
| 254 |
|
| 255 |
|
| 256 |
if __name__ == '__main__': |
| 257 |
main() |