Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_privatelinkservice_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2022 xuzhang3 (@xuzhang3), Fred-sun (@Fred-sun)
4 #
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11
12 DOCUMENTATION = '''
13 ---
14 module: azure_rm_privatelinkservice_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 link service.
27 type: str
28 resource_group:
29 description:
30 - The name of the resource group.
31 type: str
32 tags:
33 description:
34 - Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
35 type: list
36 elements: str
37
38 extends_documentation_fragment:
39 - azure.azcollection.azure
40
41 author:
42 - xuzhang3 (@xuzhang3)
43 - Fred-sun (@Fred-sun)
44 '''
45
46 EXAMPLES = '''
47 - name: Get private link service info by name
48 azure_rm_privatelinkservice_info:
49 name: pn-service-name
50 resource_group: myResourceGroup
51
52 - name: Get all private link service by resource group
53 azure_rm_privatelinkservice_info:
54 resource_group: myResourceGroup
55
56 - name: Get all private link service by subscription filter by tags
57 azure_rm_privatelinkservice_info:
58 tags:
59 - key1
60 - abc
61 '''
62
63 RETURN = '''
64 link_service:
65 description:
66 - List of private link service info.
67 returned: always
68 type: complex
69 contains:
70 id:
71 description:
72 - Resource ID of the private link service.
73 sample: "/subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/privateLinkServices/linkservice"
74 returned: always
75 type: str
76 name:
77 description:
78 - Name of the private link service.
79 returned: always
80 type: str
81 sample: linkservice
82 location:
83 description:
84 - Resource location.
85 returned: always
86 type: str
87 sample: eastus
88 alias:
89 description:
90 - The alias of the private link service.
91 type: str
92 returned: always
93 sample: "linkservice.6a244dd8-8416-40cf-8c04-52b353bdd507.eastus.azure.privatelinkservice"
94 auto_approval:
95 description:
96 - The auto-approval list of the private link service.
97 type: dict
98 returned: always
99 sample: { "subscriptions": [] }
100 enable_proxy_protocol:
101 description:
102 - Whether the private link service is enabled for proxy protocol or not
103 type: bool
104 returned: always
105 sample: False
106 etag:
107 description:
108 - A unique read-only string that changes whenever the resource is updated.
109 type: str
110 returned: always
111 sample: "f7d60f37-ea2b-4091-8546-1327f35468c4"
112 type:
113 description:
114 - The resource type.
115 type: str
116 returned: always
117 sample: Microsoft.Network/privateLinkServices
118 visibility:
119 description:
120 - The visibility list of the private link service.
121 type: dict
122 returned: always
123 sample: { "subscriptions": [] }
124 tags:
125 description:
126 - The resource tags.
127 type: dict
128 returned: always
129 sample: { 'key1': 'value1' }
130 provisioning_state:
131 description:
132 - The provisioning state of the private link service resource.
133 type: str
134 returned: always
135 sample: Succeeded
136 network_interfaces:
137 description:
138 - An array of references to the network interfaces created for this private link service.
139 type: list
140 returned: always
141 sample: [{ "id": "/subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/testlinkservice.nic.f5"}]
142 ip_configurations:
143 description:
144 - An array of private link service IP configurations.
145 type: complex
146 returned: always
147 contains:
148 name:
149 description:
150 - The name of the IP configurations.
151 type: str
152 returned: always
153 sample: subnetfredprivate-1
154 properties:
155 description:
156 - The IP configuration properties.
157 type: complex
158 returned: always
159 contains:
160 primary:
161 description:
162 - Whether the ip configuration is primary or not.
163 returned: always
164 type: bool
165 sample: True
166 private_ip_address_version:
167 description:
168 - Whether the specific IP configuration is IPv4 or IPv6.
169 returned: always
170 type: str
171 sample: IPv4
172 private_ip_allocation_method:
173 description:
174 - The private IP address allocation method.
175 returned: always
176 type: str
177 sample: Dynamic
178 subnet:
179 description:
180 - The reference to the subnet resource.
181 returned: always
182 type: dict
183 sample: { "id": "/subscriptions/xxx/resourceGroups/myRG/providers/Microsoft.Network/virtualNetworks/vnet/subnets/subname" }
184 load_balancer_frontend_ip_configurations:
185 description:
186 - An array of references to the load balancer IP configurations.
187 type: list
188 returned: awalys
189 sample: [{ "id": "/subscriptions/xxx/resourceGroups/myRG/providers/Microsoft.Network/loadBalancers/testlb/frontendIPConfigurations/front01" }]
190 fqdns:
191 description:
192 - The list of Fqdn.
193 type: list
194 returned: always
195 sample: ['fqdns1.com', 'fqdns2.com']
196 private_endpoint_connections:
197 description:
198 - An array of list about connections to the private endpoint.
199 type: complex
200 returned: always
201 contains:
202 id:
203 description:
204 - The ID of the private endpoint connection.
205 type: str
206 returned: always
207 sample: "/subscriptions/xxx/resourceGroups/myReG/providers/Microsoft.Network/privateLinkServices/linkservice/privateEndpointConnections/tes"
208 private_endpoint:
209 description:
210 - The ID of the private endpoint.
211 type: str
212 returned: always
213 sample: "/subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/privateEndpoints/test002"
214 '''
215
216 try:
217 from azure.core.exceptions import ResourceNotFoundError
218 except Exception:
219 # This is handled in azure_rm_common
220 pass
221
222 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
223
224
225 class AzureRMPrivateLinkServiceInfo(AzureRMModuleBase):
226
227 def __init__(self):
228
229 self.module_arg_spec = dict(
230 name=dict(type="str"),
231 resource_group=dict(type="str"),
232 tags=dict(type='list', elements='str')
233 )
234
235 self.name = None
236 self.tags = None
237 self.resource_group = None
238 self.results = dict(
239 changed=False,
240 )
241
242 super(AzureRMPrivateLinkServiceInfo, self).__init__(self.module_arg_spec,
243 supports_check_mode=True,
244 supports_tags=False,
245 facts_module=True)
246
247 def exec_module(self, **kwargs):
248 for key in list(self.module_arg_spec.keys()):
249 setattr(self, key, kwargs[key])
250
251 if self.name is not None and self.resource_group is not None:
252 result = self.get_item()
253 elif self.resource_group is not None:
254 result = self.list_resourcegroup()
255 else:
256 result = self.list_by_subscription()
257
258 self.results["link_service"] = [item for item in result if item and self.has_tags(item['tags'], self.tags)]
259 return self.results
260
261 def get_item(self):
262 self.log("Get properties for {0} in {1}".format(self.name, self.resource_group))
263
264 try:
265 response = self.network_client.private_link_services.get(self.resource_group, self.name)
266 return [self.service_to_dict(response)]
267 except ResourceNotFoundError:
268 self.log("Could not get info for {0} in {1}".format(self.name, self.resource_group))
269
270 return []
271
272 def list_resourcegroup(self):
273 result = []
274 self.log("List all in {0}".format(self.resource_group))
275 try:
276 response = self.network_client.private_link_services.list(self.resource_group)
277 while True:
278 result.append(response.next())
279 except StopIteration:
280 pass
281 except Exception:
282 pass
283 return [self.service_to_dict(item) for item in result]
284
285 def list_by_subscription(self):
286 result = []
287 self.log("List all in by subscription")
288 try:
289 response = self.network_client.private_link_services.list_by_subscription()
290 while True:
291 result.append(response.next())
292 except StopIteration:
293 pass
294 except Exception:
295 pass
296 return [self.service_to_dict(item) for item in result]
297
298 def service_to_dict(self, service_info):
299
300 service = service_info.as_dict()
301 result = dict(
302 id=service.get("id"),
303 name=service.get('name'),
304 type=service.get('type'),
305 etag=service.get('etag'),
306 location=service.get('location'),
307 tags=service.get('tags'),
308 load_balancer_frontend_ip_configurations=service.get('load_balancer_frontend_ip_configurations'),
309 ip_configurations=list(),
310 network_interfaces=service.get('network_interfaces'),
311 provisioning_state=service.get('provisioning_state'),
312 private_endpoint_connections=list(),
313 visibility=service.get('visibility'),
314 auto_approval=service.get('auto_approval'),
315 fqdns=service.get('fqdns'),
316 alias=service.get('alias'),
317 enable_proxy_protocol=service.get('enable_proxy_protocol')
318 )
319 if service.get('private_endpoint_connections'):
320 for items in service['private_endpoint_connections']:
321 result['private_endpoint_connections'].append({'id': items['id'], 'private_endpoint': items['private_endpoint']['id']})
322
323 if service.get('ip_configurations'):
324 for items in service['ip_configurations']:
325 result['ip_configurations'].append(
326 {
327 "name": items['name'],
328 'properties': {
329 "primary": items['primary'],
330 "private_ip_address_version": items["private_ip_address_version"],
331 "private_ip_allocation_method": items["private_ip_allocation_method"],
332 "subnet": items["subnet"],
333 }
334 }
335 )
336
337 return result
338
339
340 def main():
341 AzureRMPrivateLinkServiceInfo()
342
343
344 if __name__ == "__main__":
345 main()