| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: azure_rm_privateendpointconnection_info |
| 15 |
|
| 16 |
version_added: "1.12.0" |
| 17 |
|
| 18 |
short_description: Get private endpoint connection info |
| 19 |
|
| 20 |
description: |
| 21 |
- Get facts for private endpoint connection info. |
| 22 |
|
| 23 |
options: |
| 24 |
name: |
| 25 |
description: |
| 26 |
- The name of the private end point connection. |
| 27 |
type: str |
| 28 |
service_name: |
| 29 |
description: |
| 30 |
- The name of the private link service. |
| 31 |
type: str |
| 32 |
required: true |
| 33 |
resource_group: |
| 34 |
description: |
| 35 |
- The name of the resource group. |
| 36 |
type: str |
| 37 |
required: true |
| 38 |
|
| 39 |
extends_documentation_fragment: |
| 40 |
- azure.azcollection.azure |
| 41 |
|
| 42 |
author: |
| 43 |
- xuzhang3 (@xuzhang3) |
| 44 |
- Fred-sun (@Fred-sun) |
| 45 |
''' |
| 46 |
|
| 47 |
EXAMPLES = ''' |
| 48 |
- name: Get private endpoint connection info by name |
| 49 |
azure_rm_privateendpointconnection_info: |
| 50 |
name: pe-connection-name |
| 51 |
service_name: testserviceName |
| 52 |
resource_group: myRG |
| 53 |
|
| 54 |
- name: Get all private endpoint connection info by service name |
| 55 |
azure_rm_privateendpointconnection_info: |
| 56 |
service_name: testserviceName |
| 57 |
resource_group: myRG |
| 58 |
''' |
| 59 |
|
| 60 |
RETURN = ''' |
| 61 |
endpoint_connection: |
| 62 |
description: |
| 63 |
- List of private endpoint connection info. |
| 64 |
returned: always |
| 65 |
type: complex |
| 66 |
contains: |
| 67 |
id: |
| 68 |
description: |
| 69 |
- Resource ID of the private endpoint connection. |
| 70 |
sample: "/subscriptions/xxx/resourceGroups/myRG/providers/Microsoft.Network/privateLinkServices/linkservice/privateEndpointConnections/link.09" |
| 71 |
returned: always |
| 72 |
type: str |
| 73 |
name: |
| 74 |
description: |
| 75 |
- Name of the private endpoint connection. |
| 76 |
returned: always |
| 77 |
type: str |
| 78 |
sample: testlink.09 |
| 79 |
link_identifier: |
| 80 |
description: |
| 81 |
- The consumer link id. |
| 82 |
returned: always |
| 83 |
type: str |
| 84 |
sample: 536890208 |
| 85 |
PrivateEndpoint: |
| 86 |
description: |
| 87 |
- The resource of private end point. |
| 88 |
type: complex |
| 89 |
returned: always |
| 90 |
contains: |
| 91 |
id: |
| 92 |
description: |
| 93 |
- The private endpoint resource ID. |
| 94 |
type: str |
| 95 |
returned: always |
| 96 |
sample: "/subscriptions/xxx-xxx/resourceGroups/myRG/providers/Microsoft.Network/privateEndpoints/testlink02" |
| 97 |
private_link_service_connection_state: |
| 98 |
description: |
| 99 |
- A collection of information about the state of the connection between service consumer and provider. |
| 100 |
type: complex |
| 101 |
returned: always |
| 102 |
contains: |
| 103 |
description: |
| 104 |
description: |
| 105 |
- The reason for approval/rejection of the connection. |
| 106 |
returned: always |
| 107 |
type: str |
| 108 |
sample: "Auto Approved" |
| 109 |
status: |
| 110 |
description: |
| 111 |
- Indicates whether the connection has been Approved/Rejected/Removed by the owner of the service. |
| 112 |
returned: always |
| 113 |
type: str |
| 114 |
sample: Approved |
| 115 |
actions_required: |
| 116 |
description: |
| 117 |
- A message indicating if changes on the service provider require any updates on the consumer. |
| 118 |
type: str |
| 119 |
returned: always |
| 120 |
sample: "This is action_required string" |
| 121 |
provisioning_state: |
| 122 |
description: |
| 123 |
- Provisioning state of the resource. |
| 124 |
returned: always |
| 125 |
type: str |
| 126 |
sample: Succeeded |
| 127 |
etag: |
| 128 |
description: |
| 129 |
- A unique read-only string that changes whenever the resource is updated. |
| 130 |
type: str |
| 131 |
returned: always |
| 132 |
sample: "f7d60f37-ea2b-4091-8546-1327f35468c4" |
| 133 |
type: |
| 134 |
description: |
| 135 |
- The resource type. |
| 136 |
type: str |
| 137 |
returned: always |
| 138 |
sample: Microsoft.Network/privateLinkServices/privateEndpointConnections |
| 139 |
''' |
| 140 |
|
| 141 |
try: |
| 142 |
from azure.core.exceptions import ResourceNotFoundError |
| 143 |
except Exception: |
| 144 |
|
| 145 |
pass |
| 146 |
|
| 147 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 148 |
|
| 149 |
|
| 150 |
class AzureRMPrivateEndpointConnectionInfo(AzureRMModuleBase): |
| 151 |
|
| 152 |
def __init__(self): |
| 153 |
|
| 154 |
self.module_arg_spec = dict( |
| 155 |
name=dict(type="str"), |
| 156 |
service_name=dict(type="str", required=True), |
| 157 |
resource_group=dict(type="str", required=True), |
| 158 |
) |
| 159 |
|
| 160 |
self.name = None |
| 161 |
self.service_name = None |
| 162 |
self.resource_group = None |
| 163 |
self.results = dict( |
| 164 |
changed=False, |
| 165 |
) |
| 166 |
|
| 167 |
super(AzureRMPrivateEndpointConnectionInfo, self).__init__(self.module_arg_spec, |
| 168 |
supports_check_mode=True, |
| 169 |
supports_tags=False, |
| 170 |
facts_module=True) |
| 171 |
|
| 172 |
def exec_module(self, **kwargs): |
| 173 |
for key in list(self.module_arg_spec.keys()): |
| 174 |
setattr(self, key, kwargs[key]) |
| 175 |
|
| 176 |
if self.name is not None: |
| 177 |
self.results["endpoint_connection"] = self.get_item() |
| 178 |
else: |
| 179 |
self.results["endpoint_connection"] = self.list_items() |
| 180 |
|
| 181 |
return self.results |
| 182 |
|
| 183 |
def get_item(self): |
| 184 |
self.log("Get properties for {0} in {1}".format(self.name, self.service_name)) |
| 185 |
|
| 186 |
try: |
| 187 |
response = self.network_client.private_link_services.get_private_endpoint_connection(self.resource_group, self.service_name, self.name) |
| 188 |
return [self.connect_to_dict(response)] |
| 189 |
except ResourceNotFoundError: |
| 190 |
self.log("Could not get info for {0} in {1}".format(self.name, self.service_name)) |
| 191 |
|
| 192 |
return [] |
| 193 |
|
| 194 |
def list_items(self): |
| 195 |
result = [] |
| 196 |
self.log("List all in {0}".format(self.service_name)) |
| 197 |
try: |
| 198 |
response = self.network_client.private_link_services.list_private_endpoint_connections(self.resource_group, self.service_name) |
| 199 |
while True: |
| 200 |
result.append(response.next()) |
| 201 |
except StopIteration: |
| 202 |
pass |
| 203 |
except Exception as exc: |
| 204 |
self.fail("Failed to list all items in {0}: {1}".format(self.service_name, str(exc))) |
| 205 |
return [self.connect_to_dict(item) for item in result] |
| 206 |
|
| 207 |
def connect_to_dict(self, connect_info): |
| 208 |
connect = connect_info.as_dict() |
| 209 |
result = dict( |
| 210 |
id=connect.get("id"), |
| 211 |
name=connect.get('name'), |
| 212 |
type=connect.get('type'), |
| 213 |
etag=connect.get('etag'), |
| 214 |
private_endpoint=dict(), |
| 215 |
private_link_service_connection_state=dict(), |
| 216 |
provisioning_state=connect.get('provisioning_state'), |
| 217 |
link_identifier=connect.get('link_identifier') |
| 218 |
) |
| 219 |
if connect.get('private_endpoint') is not None: |
| 220 |
result['private_endpoint']['id'] = connect.get('private_endpoint')['id'] |
| 221 |
|
| 222 |
if connect.get('private_link_service_connection_state') is not None: |
| 223 |
result['private_link_service_connection_state']['status'] = connect.get('private_link_service_connection_state')['status'] |
| 224 |
result['private_link_service_connection_state']['description'] = connect.get('private_link_service_connection_state')['description'] |
| 225 |
result['private_link_service_connection_state']['actions_required'] = connect.get('private_link_service_connection_state')['actions_required'] |
| 226 |
return result |
| 227 |
|
| 228 |
|
| 229 |
def main(): |
| 230 |
AzureRMPrivateEndpointConnectionInfo() |
| 231 |
|
| 232 |
|
| 233 |
if __name__ == "__main__": |
| 234 |
main() |