| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
DOCUMENTATION = ''' |
| 9 |
--- |
| 10 |
module: azure_rm_serviceendpointpolicydefinition_info |
| 11 |
version_added: "3.9.0" |
| 12 |
short_description: Get or list the service endpoint policy definition |
| 13 |
description: |
| 14 |
- Get or list the service endpoint policy definition. |
| 15 |
|
| 16 |
options: |
| 17 |
resource_group: |
| 18 |
description: |
| 19 |
- The name of the resource group. |
| 20 |
type: str |
| 21 |
required: true |
| 22 |
service_endpoint_policy_name: |
| 23 |
description: |
| 24 |
- The name of the service endpoint policy name. |
| 25 |
type: str |
| 26 |
required: true |
| 27 |
name: |
| 28 |
description: |
| 29 |
- The name of the service endpoint policy definition name. |
| 30 |
type: str |
| 31 |
extends_documentation_fragment: |
| 32 |
- azure.azcollection.azure |
| 33 |
|
| 34 |
author: |
| 35 |
- magodo (@magodo) |
| 36 |
- Fred Sun (@Fred-sun) |
| 37 |
''' |
| 38 |
|
| 39 |
EXAMPLES = ''' |
| 40 |
- name: Get the specified service endpoint policy definitions from service endpoint policy |
| 41 |
azure.azcollection.azure_rm_serviceendpointpolicydefinition_info: |
| 42 |
resource_group: testRG |
| 43 |
service_endpoint_policy_name: testpolicy |
| 44 |
name: definitionname |
| 45 |
|
| 46 |
- name: List all service endpoint policy definitions in a service end point policy |
| 47 |
azure.azcollection.azure_rm_serviceendpointpolicydefinition_info: |
| 48 |
resource_group: testRG |
| 49 |
service_endpoint_policy_name: testpolicy |
| 50 |
''' |
| 51 |
|
| 52 |
RETURN = ''' |
| 53 |
serviceendpointpolicydefinitions: |
| 54 |
description: |
| 55 |
- List of the service endpoint policy definitions in a service end point 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/\ |
| 65 |
policy01/serviceEndpointPolicyDefinitions/definition01" |
| 66 |
name: |
| 67 |
description: |
| 68 |
- The name of the resource that is unique within a resource group. |
| 69 |
type: str |
| 70 |
returned: always |
| 71 |
sample: definition01 |
| 72 |
etag: |
| 73 |
description: |
| 74 |
- A unique read-only string that changes whenever the resource is updated. |
| 75 |
returned: always |
| 76 |
type: str |
| 77 |
sample: "4a66fa1c-3d17-43c9-9b9d-da07ffdbb695" |
| 78 |
resource_group: |
| 79 |
description: |
| 80 |
- The name of the resource group. |
| 81 |
type: str |
| 82 |
returned: always |
| 83 |
sample: TestRG |
| 84 |
description: |
| 85 |
description: |
| 86 |
- A description for this rule. Restricted to 140 chars. |
| 87 |
type: str |
| 88 |
returned: always |
| 89 |
sample: definition-test |
| 90 |
service_endpoint_policy_name: |
| 91 |
description: |
| 92 |
- The name of the service endpoint policy name. |
| 93 |
type: str |
| 94 |
returned: always |
| 95 |
sample: policy01 |
| 96 |
type: |
| 97 |
description: |
| 98 |
- The type of the resource. |
| 99 |
type: str |
| 100 |
returned: always |
| 101 |
sample: "Microsoft.Network/serviceEndpointPolicies/serviceEndpointPolicyDefinitions" |
| 102 |
provisioning_state: |
| 103 |
description: |
| 104 |
- The provisioning state of the service endpoint policy definition resource. |
| 105 |
type: str |
| 106 |
returned: always |
| 107 |
sample: Successded |
| 108 |
service: |
| 109 |
description: |
| 110 |
- Service endpoint name. |
| 111 |
type: str |
| 112 |
returned: always |
| 113 |
sample: Microsoft.Storage |
| 114 |
service_resources: |
| 115 |
description: |
| 116 |
- A list of service resources. |
| 117 |
type: list |
| 118 |
returned: always |
| 119 |
sample: ["/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Storage/storageAccounts/account01"] |
| 120 |
''' |
| 121 |
|
| 122 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 123 |
|
| 124 |
|
| 125 |
class AzureRMServiceEndpointPolicyDefinitionInfo(AzureRMModuleBase): |
| 126 |
"""Information class for an Azure RM Data Collection Rules""" |
| 127 |
|
| 128 |
def __init__(self): |
| 129 |
self.module_arg_spec = dict( |
| 130 |
resource_group=dict(type='str', required=True), |
| 131 |
service_endpoint_policy_name=dict(type='str', required=True), |
| 132 |
name=dict(type='str') |
| 133 |
) |
| 134 |
|
| 135 |
self.resource_group = None |
| 136 |
self.service_endpoint_policy_name = None |
| 137 |
self.name = None |
| 138 |
self.log_path = None |
| 139 |
self.log_mode = None |
| 140 |
|
| 141 |
self.results = dict( |
| 142 |
changed=False, |
| 143 |
serviceendpointpolicydefinitions=[] |
| 144 |
) |
| 145 |
|
| 146 |
super(AzureRMServiceEndpointPolicyDefinitionInfo, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 147 |
supports_check_mode=True, |
| 148 |
supports_tags=False, |
| 149 |
facts_module=True) |
| 150 |
|
| 151 |
def exec_module(self, **kwargs): |
| 152 |
"""Main module execution method""" |
| 153 |
|
| 154 |
for key in self.module_arg_spec: |
| 155 |
setattr(self, key, kwargs[key]) |
| 156 |
|
| 157 |
result = [] |
| 158 |
if self.name: |
| 159 |
result = self.get_definition(self.name) |
| 160 |
else: |
| 161 |
result = self.list_all_definition() |
| 162 |
self.results['serviceendpointpolicydefinitions'] = result |
| 163 |
|
| 164 |
return self.results |
| 165 |
|
| 166 |
def get_definition(self, name): |
| 167 |
''' |
| 168 |
Gets the specified service endpoint policy definition |
| 169 |
''' |
| 170 |
result = [] |
| 171 |
response = None |
| 172 |
|
| 173 |
try: |
| 174 |
response = self.network_client.service_endpoint_policy_definitions.get(self.resource_group, self.service_endpoint_policy_name, self.name) |
| 175 |
except Exception: |
| 176 |
self.log("Could not get the specified service endpoint policy definition {0}".format(self.name)) |
| 177 |
return [] |
| 178 |
if response: |
| 179 |
result = [self.format_item(response)] |
| 180 |
return result |
| 181 |
|
| 182 |
def list_all_definition(self): |
| 183 |
''' |
| 184 |
List all service endpoint policy definitions for the specified resource. |
| 185 |
''' |
| 186 |
result = [] |
| 187 |
response = None |
| 188 |
|
| 189 |
try: |
| 190 |
response = self.network_client.service_endpoint_policy_definitions.list_by_resource_group(self.resource_group, self.service_endpoint_policy_name) |
| 191 |
except Exception as ex: |
| 192 |
self.log("Could not list all service endpoint policy definitions for the specified resource, Exception as {0}".format(ex)) |
| 193 |
return [] |
| 194 |
if response: |
| 195 |
for item in response: |
| 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.resource_group |
| 202 |
response['service_endpoint_policy_name'] = self.service_endpoint_policy_name |
| 203 |
return response |
| 204 |
|
| 205 |
|
| 206 |
def main(): |
| 207 |
"""Main execution""" |
| 208 |
AzureRMServiceEndpointPolicyDefinitionInfo() |
| 209 |
|
| 210 |
|
| 211 |
if __name__ == '__main__': |
| 212 |
main() |