| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
DOCUMENTATION = ''' |
| 9 |
--- |
| 10 |
module: azure_rm_serviceendpointpolicy_info |
| 11 |
version_added: "3.9.0" |
| 12 |
short_description: Get or list the service endpoint policy |
| 13 |
description: |
| 14 |
- Get or list the service endpoint policy. |
| 15 |
|
| 16 |
options: |
| 17 |
resource_group: |
| 18 |
description: |
| 19 |
- The name of the resource group. |
| 20 |
type: str |
| 21 |
name: |
| 22 |
description: |
| 23 |
- The name of the service endpoint policy name. |
| 24 |
type: str |
| 25 |
tags: |
| 26 |
description: |
| 27 |
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'. |
| 28 |
type: list |
| 29 |
elements: str |
| 30 |
extends_documentation_fragment: |
| 31 |
- azure.azcollection.azure |
| 32 |
|
| 33 |
author: |
| 34 |
- magodo (@magodo) |
| 35 |
- Fred Sun (@Fred-sun) |
| 36 |
''' |
| 37 |
|
| 38 |
EXAMPLES = ''' |
| 39 |
- name: Get the specified service endpoint policy |
| 40 |
azure.azcollection.azure_rm_serviceendpointpolicy_info: |
| 41 |
resource_group: testRG |
| 42 |
name: testpolicy |
| 43 |
|
| 44 |
- name: List all service endpoint policy under same resource group |
| 45 |
azure.azcollection.azure_rm_serviceendpointpolicy_info: |
| 46 |
resource_group: testRG |
| 47 |
|
| 48 |
- name: List all service endpoint policy |
| 49 |
azure.azcollection.azure_rm_serviceendpointpolicy_info: |
| 50 |
''' |
| 51 |
|
| 52 |
RETURN = ''' |
| 53 |
serviceendpointpolicies: |
| 54 |
description: |
| 55 |
- List the facts of service endpoint policy. |
| 56 |
type: complex |
| 57 |
returned: always |
| 58 |
contains: |
| 59 |
id: |
| 60 |
description: |
| 61 |
- Fully qualified ID of the resource. |
| 62 |
type: str |
| 63 |
returned: always |
| 64 |
sample: "/subscriptions/xxx-xxx/resourceGroups/TestRG/providers/Microsoft.Network/serviceEndpointPolicies/testpolicy" |
| 65 |
name: |
| 66 |
description: |
| 67 |
- The name of the resource that is unique within a resource group. |
| 68 |
type: str |
| 69 |
returned: always |
| 70 |
sample: testpolicy |
| 71 |
etag: |
| 72 |
description: |
| 73 |
- A unique read-only string that changes whenever the resource is updated. |
| 74 |
returned: always |
| 75 |
type: str |
| 76 |
sample: "49e15a7b-1bff-46ba-b962-7a11e75cb729" |
| 77 |
resource_group: |
| 78 |
description: |
| 79 |
- The name of the resource group. |
| 80 |
type: str |
| 81 |
returned: always |
| 82 |
sample: TestRG |
| 83 |
location: |
| 84 |
description: |
| 85 |
- The resource's location. |
| 86 |
type: str |
| 87 |
returned: always |
| 88 |
sample: eastus |
| 89 |
type: |
| 90 |
description: |
| 91 |
- The type of the resource. |
| 92 |
type: str |
| 93 |
returned: always |
| 94 |
sample: Microsoft.Network/serviceEndpointPolicies |
| 95 |
service_endpoint_policy_definitions: |
| 96 |
description: |
| 97 |
- A collection of service endpoint policy definitions of the service endpoint policy. |
| 98 |
type: list |
| 99 |
returned: always |
| 100 |
sample: [] |
| 101 |
provisioning_state: |
| 102 |
description: |
| 103 |
- The provisioning state of the service endpoint policy resource. |
| 104 |
type: str |
| 105 |
returned: always |
| 106 |
sample: Successded |
| 107 |
resource_guid: |
| 108 |
description: |
| 109 |
- The resource GUID property of the service endpoint policy resource. |
| 110 |
type: str |
| 111 |
returned: always |
| 112 |
sample: 77ee69ee-4152-4271-bfc0-1d431b7b7d28 |
| 113 |
''' |
| 114 |
|
| 115 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 116 |
|
| 117 |
|
| 118 |
class AzureRMServiceEndpointPolicyInfo(AzureRMModuleBase): |
| 119 |
"""Information class for an Azure RM Data Collection Rules""" |
| 120 |
|
| 121 |
def __init__(self): |
| 122 |
self.module_arg_spec = dict( |
| 123 |
resource_group=dict(type='str'), |
| 124 |
name=dict(type='str'), |
| 125 |
tags=dict(type='list', elements='str') |
| 126 |
) |
| 127 |
|
| 128 |
self.resource_group = None |
| 129 |
self.name = None |
| 130 |
self.tags = None |
| 131 |
self.log_path = None |
| 132 |
self.log_mode = None |
| 133 |
self.required_by = { |
| 134 |
'name': 'resource_group' |
| 135 |
} |
| 136 |
|
| 137 |
self.results = dict( |
| 138 |
changed=False, |
| 139 |
serviceendpointpolicies=[] |
| 140 |
) |
| 141 |
|
| 142 |
super(AzureRMServiceEndpointPolicyInfo, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 143 |
supports_check_mode=True, |
| 144 |
supports_tags=False, |
| 145 |
facts_module=True, |
| 146 |
required_by=self.required_by) |
| 147 |
|
| 148 |
def exec_module(self, **kwargs): |
| 149 |
"""Main module execution method""" |
| 150 |
|
| 151 |
for key in self.module_arg_spec: |
| 152 |
setattr(self, key, kwargs[key]) |
| 153 |
|
| 154 |
result = [] |
| 155 |
if self.name: |
| 156 |
result = self.get_policy(self.name) |
| 157 |
else: |
| 158 |
result = self.list_all_policy() |
| 159 |
self.results['serviceendpointpolicies'] = result |
| 160 |
|
| 161 |
return self.results |
| 162 |
|
| 163 |
def get_policy(self, name): |
| 164 |
''' |
| 165 |
Gets the specified service endpoint policy |
| 166 |
''' |
| 167 |
result = [] |
| 168 |
response = None |
| 169 |
|
| 170 |
try: |
| 171 |
response = self.network_client.service_endpoint_policies.get(self.resource_group, self.name) |
| 172 |
except Exception: |
| 173 |
self.log("Could not get the specified service endpoint policy {0}".format(self.name)) |
| 174 |
return [] |
| 175 |
if response and self.has_tags(response.tags, self.tags): |
| 176 |
result = [self.format_item(response)] |
| 177 |
return result |
| 178 |
|
| 179 |
def list_all_policy(self): |
| 180 |
''' |
| 181 |
List all service endpoint policys for the specified resource. |
| 182 |
''' |
| 183 |
result = [] |
| 184 |
response = None |
| 185 |
try: |
| 186 |
if self.resource_group: |
| 187 |
response = self.network_client.service_endpoint_policies.list_by_resource_group(self.resource_group) |
| 188 |
else: |
| 189 |
response = self.network_client.service_endpoint_policies.list() |
| 190 |
except Exception as ex: |
| 191 |
self.log("Could not list all service endpoint policys for the specified resource, Exception as {0}".format(ex)) |
| 192 |
return [] |
| 193 |
if response: |
| 194 |
for item in response: |
| 195 |
if self.has_tags(item.tags, self.tags): |
| 196 |
result.append(self.format_item(item)) |
| 197 |
return result |
| 198 |
|
| 199 |
def format_item(self, item): |
| 200 |
response = item.as_dict() |
| 201 |
response['resource_group'] = self.parse_resource_to_dict(response['id']).get('resource_group') |
| 202 |
return response |
| 203 |
|
| 204 |
|
| 205 |
def main(): |
| 206 |
"""Main execution""" |
| 207 |
AzureRMServiceEndpointPolicyInfo() |
| 208 |
|
| 209 |
|
| 210 |
if __name__ == '__main__': |
| 211 |
main() |