Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2020 XiuxiSun, (@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 __metaclass__ = type
9
10
11 DOCUMENTATION = '''
12 ---
13 module: azure_rm_virtualhub_info
14 version_added: '1.10.0'
15 short_description: Get VirtualHub info
16 description:
17 - Get info of VirtualHub.
18 options:
19 resource_group:
20 description:
21 - The resource group name of the VirtualHub.
22 type: str
23 name:
24 description:
25 - The name of the VirtualHub.
26 type: str
27 extends_documentation_fragment:
28 - azure.azcollection.azure
29 author:
30 - Fred-Sun (@Fred-Sun)
31 - Haiyuan Zhang (@haiyuazhang)
32
33 '''
34
35 EXAMPLES = '''
36 - name: Get virtual hub info by name
37 azure_rm_virtualhub_info:
38 resource_group: myResourceGroup
39 name: virtualHub
40
41 - name: Get virtual hub info by resource group
42 azure_rm_virtualhub_info:
43 resource_group: myResourceGroup
44
45 - name: Get birtual hub info by sub
46 azure_rm_virtualhub_info:
47 '''
48
49 RETURN = '''
50 virtual_hubs:
51 description:
52 - A list of dict results where the key is the name of the VirtualHub and the values are the facts for that VirtualHub.
53 returned: always
54 type: complex
55 contains:
56 id:
57 description:
58 - Resource ID.
59 returned: always
60 type: str
61 sample: /subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualHubs/fredhub
62 name:
63 description:
64 - Resource name.
65 returned: always
66 type: str
67 sample: fredhub
68 type:
69 description:
70 - Resource type.
71 returned: always
72 type: str
73 sample: Microsoft.Network/virtualHubs
74 location:
75 description:
76 - Resource location.
77 returned: always
78 type: str
79 sample: eastus
80 tags:
81 description:
82 - Resource tags.
83 returned: always
84 type: dict
85 sample: {"key1":"value1"}
86 etag:
87 description:
88 - A unique read-only string that changes whenever the resource is updated.
89 returned: always
90 type: str
91 sample: 4462b9db-6569-49be-8d00-000178b29e90
92 virtual_wan:
93 description:
94 - The VirtualWAN to which the VirtualHub belongs.
95 returned: always
96 type: complex
97 contains:
98 id:
99 description:
100 - Resource ID.
101 returned: always
102 type: str
103 sample: /subscriptions/xxx-xxx/resourceGroups/v-xisuRG/providers/Microsoft.Network/virtualWans/virtualwanfred01
104 vpn_gateway:
105 description:
106 - The VpnGateway associated with this VirtualHub.
107 returned: always
108 type: complex
109 contains:
110 id:
111 description:
112 - Resource ID.
113 returned: always
114 type: str
115 sample: null
116 p2_s_vpn_gateway:
117 description:
118 - The P2SVpnGateway associated with this VirtualHub.
119 returned: always
120 type: complex
121 contains:
122 id:
123 description:
124 - Resource ID.
125 returned: always
126 type: str
127 sample: null
128 express_route_gateway:
129 description:
130 - The expressRouteGateway associated with this VirtualHub.
131 returned: always
132 type: complex
133 contains:
134 id:
135 description:
136 - Resource ID.
137 returned: always
138 type: str
139 sample: null
140 azure_firewall:
141 description:
142 - The azureFirewall associated with this VirtualHub.
143 returned: always
144 type: complex
145 contains:
146 id:
147 description:
148 - Resource ID.
149 returned: always
150 type: str
151 sample: null
152 security_partner_provider:
153 description:
154 - The securityPartnerProvider associated with this VirtualHub.
155 returned: always
156 type: complex
157 contains:
158 id:
159 description:
160 - Resource ID.
161 returned: always
162 type: str
163 sample: null
164 address_prefix:
165 description:
166 - Address-prefix for this VirtualHub.
167 returned: always
168 type: str
169 sample: 10.0.0.0/24
170 route_table:
171 description:
172 - The routeTable associated with this virtual hub.
173 returned: always
174 type: complex
175 contains:
176 routes:
177 description:
178 - List of all routes.
179 returned: always
180 type: list
181 contains:
182 address_prefixes:
183 description:
184 - List of all addressPrefixes.
185 returned: always
186 type: list
187 sample: null
188 next_hop_ip_address:
189 description:
190 - NextHop ip address.
191 returned: always
192 type: str
193 sample: null
194 provisioning_state:
195 description:
196 - The provisioning state of the virtual hub resource.
197 returned: always
198 type: str
199 sample: Succeeded
200 security_provider_name:
201 description:
202 - The Security Provider name.
203 returned: always
204 type: str
205 sample: null
206 virtual_hub_route_table_v2_s:
207 description:
208 - List of all virtual hub route table v2s associated with this VirtualHub.
209 returned: always
210 type: complex
211 contains:
212 name:
213 description:
214 - The name of the resource that is unique within a resource group.
215 - This name can be used to access the resource.
216 returned: always
217 type: str
218 sample: null
219 routes:
220 description:
221 - List of all routes.
222 returned: always
223 type: complex
224 contains:
225 destination_type:
226 description:
227 - The type of destinations.
228 returned: always
229 type: str
230 sample: null
231 destinations:
232 description:
233 - List of all destinations.
234 returned: always
235 type: list
236 sample: null
237 next_hop_type:
238 description:
239 - The type of next hops.
240 returned: always
241 type: str
242 sample: null
243 next_hops:
244 description:
245 - NextHops ip address.
246 returned: always
247 type: list
248 sample: null
249 attached_connections:
250 description:
251 - List of all connections attached to this route table v2.
252 returned: always
253 type: list
254 sample: null
255 sku:
256 description:
257 - The sku of this VirtualHub.
258 returned: always
259 type: str
260 sample: Standard
261 routing_state:
262 description:
263 - The routing state.
264 returned: always
265 type: str
266 sample: null
267 bgp_connections:
268 description:
269 - List of references to Bgp Connections.
270 returned: always
271 type: list
272 contains:
273 id:
274 description:
275 - Resource ID.
276 returned: always
277 type: str
278 sample: null
279 ip_configurations:
280 description:
281 - List of references to IpConfigurations.
282 returned: always
283 type: list
284 contains:
285 id:
286 description:
287 - Resource ID.
288 returned: always
289 type: str
290 sample: null
291 virtual_router_asn:
292 description:
293 - VirtualRouter ASN.
294 returned: always
295 type: int
296 sample: null
297 virtual_router_ips:
298 description:
299 - VirtualRouter IPs.
300 returned: always
301 type: list
302 sample: null
303 enable_virtual_router_route_propogation:
304 description:
305 - Flag to control route propogation for VirtualRouter hub.
306 returned: always
307 type: bool
308 sample: null
309 value:
310 description:
311 - List of VirtualHubs.
312 returned: always
313 type: complex
314 contains:
315 virtual_wan:
316 description:
317 - The VirtualWAN to which the VirtualHub belongs.
318 returned: always
319 type: complex
320 contains:
321 id:
322 description:
323 - Resource ID.
324 returned: always
325 type: str
326 sample: null
327 vpn_gateway:
328 description:
329 - The VpnGateway associated with this VirtualHub.
330 returned: always
331 type: complex
332 contains:
333 id:
334 description:
335 - Resource ID.
336 returned: always
337 type: str
338 sample: null
339 p2_s_vpn_gateway:
340 description:
341 - The P2SVpnGateway associated with this VirtualHub.
342 returned: always
343 type: complex
344 contains:
345 id:
346 description:
347 - Resource ID.
348 returned: always
349 type: str
350 sample: null
351 express_route_gateway:
352 description:
353 - The expressRouteGateway associated with this VirtualHub.
354 returned: always
355 type: complex
356 contains:
357 id:
358 description:
359 - Resource ID.
360 returned: always
361 type: str
362 sample: null
363 azure_firewall:
364 description:
365 - The azureFirewall associated with this VirtualHub.
366 returned: always
367 type: complex
368 contains:
369 id:
370 description:
371 - Resource ID.
372 returned: always
373 type: str
374 sample: null
375 security_partner_provider:
376 description:
377 - The securityPartnerProvider associated with this VirtualHub.
378 returned: always
379 type: complex
380 contains:
381 id:
382 description:
383 - Resource ID.
384 returned: always
385 type: str
386 sample: null
387 address_prefix:
388 description:
389 - Address-prefix for this VirtualHub.
390 returned: always
391 type: str
392 sample: null
393 route_table:
394 description:
395 - The routeTable associated with this virtual hub.
396 returned: always
397 type: complex
398 contains:
399 routes:
400 description:
401 - List of all routes.
402 returned: always
403 type: list
404 contains:
405 address_prefixes:
406 description:
407 - List of all addressPrefixes.
408 returned: always
409 type: list
410 sample: null
411 next_hop_ip_address:
412 description:
413 - NextHop ip address.
414 returned: always
415 type: str
416 sample: null
417 security_provider_name:
418 description:
419 - The Security Provider name.
420 returned: always
421 type: str
422 sample: null
423 virtual_hub_route_table_v2_s:
424 description:
425 - List of all virtual hub route table v2s associated with this VirtualHub.
426 returned: always
427 type: complex
428 contains:
429 name:
430 description:
431 - The name of the resource that is unique within a resource group.
432 - This name can be used to access the resource.
433 returned: always
434 type: str
435 sample: null
436 routes:
437 description:
438 - List of all routes.
439 returned: always
440 type: list
441 contains:
442 destination_type:
443 description:
444 - The type of destinations.
445 returned: always
446 type: str
447 sample: null
448 destinations:
449 description:
450 - List of all destinations.
451 returned: always
452 type: list
453 sample: null
454 next_hop_type:
455 description:
456 - The type of next hops.
457 returned: always
458 type: str
459 sample: null
460 next_hops:
461 description:
462 - NextHops ip address.
463 returned: always
464 type: list
465 sample: null
466 attached_connections:
467 description:
468 - List of all connections attached to this route table v2.
469 returned: always
470 type: list
471 sample: null
472 sku:
473 description:
474 - The sku of this VirtualHub.
475 returned: always
476 type: str
477 sample: null
478 bgp_connections:
479 description:
480 - List of references to Bgp Connections.
481 returned: always
482 type: list
483 contains:
484 id:
485 description:
486 - Resource ID.
487 returned: always
488 type: str
489 sample: null
490 ip_configurations:
491 description:
492 - List of references to IpConfigurations.
493 returned: always
494 type: list
495 contains:
496 id:
497 description:
498 - Resource ID.
499 returned: always
500 type: str
501 sample: null
502 virtual_router_asn:
503 description:
504 - VirtualRouter ASN.
505 returned: always
506 type: int
507 sample: null
508 virtual_router_ips:
509 description:
510 - VirtualRouter IPs.
511 returned: always
512 type: list
513 sample: null
514 enable_virtual_router_route_propogation:
515 description:
516 - Flag to control route propogation for VirtualRouter hub.
517 returned: always
518 type: bool
519 sample: null
520 next_link:
521 description:
522 - URL to get the next set of operation list results if there are any.
523 returned: always
524 type: str
525 sample: null
526
527 '''
528
529 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase
530 try:
531 from azure.core.exceptions import ResourceNotFoundError
532 except ImportError:
533 # This is handled in azure_rm_common
534 pass
535
536
537 class AzureRMVirtualHubInfo(AzureRMModuleBase):
538 def __init__(self):
539 self.module_arg_spec = dict(
540 resource_group=dict(
541 type='str'
542 ),
543 name=dict(
544 type='str'
545 )
546 )
547
548 self.resource_group = None
549 self.name = None
550
551 self.results = dict(changed=False)
552 self.state = None
553 self.status_code = [200]
554
555 super(AzureRMVirtualHubInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False)
556
557 def exec_module(self, **kwargs):
558
559 for key in self.module_arg_spec:
560 setattr(self, key, kwargs[key])
561
562 if (self.resource_group is not None and self.name is not None):
563 self.results['virtual_hubs'] = self.format_item(self.get())
564 elif (self.resource_group is not None):
565 self.results['virtual_hubs'] = self.format_item(self.list_by_resource_group())
566 else:
567 self.results['virtual_hubs'] = self.format_item(self.list())
568 return self.results
569
570 def get(self):
571 response = None
572
573 try:
574 response = self.network_client.virtual_hubs.get(resource_group_name=self.resource_group,
575 virtual_hub_name=self.name)
576 except ResourceNotFoundError as e:
577 self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
578
579 return response
580
581 def list_by_resource_group(self):
582 response = None
583
584 try:
585 response = self.network_client.virtual_hubs.list_by_resource_group(resource_group_name=self.resource_group)
586 except ResourceNotFoundError as e:
587 self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
588
589 return response
590
591 def list(self):
592 response = None
593
594 try:
595 response = self.network_client.virtual_hubs.list()
596 except ResourceNotFoundError as e:
597 self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
598
599 return response
600
601 def format_item(self, item):
602 if item is None:
603 return None
604 elif hasattr(item, 'as_dict'):
605 return [item.as_dict()]
606 else:
607 result = []
608 items = list(item)
609 for tmp in items:
610 result.append(tmp.as_dict())
611 return result
612
613
614 def main():
615 AzureRMVirtualHubInfo()
616
617
618 if __name__ == '__main__':
619 main()