Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import absolute_import, division, print_function
6 __metaclass__ = type
7
8
9 DOCUMENTATION = '''
10 ---
11 module: azure_rm_virtualnetworkgateway_info
12
13 version_added: "3.5.0"
14
15 short_description: Get or list Azure virtual network gateways
16
17 description:
18 - Get or list the Azure virtual network gateways.
19
20 options:
21 resource_group:
22 description:
23 - Name of a resource group where VPN Gateway exists or will be created.
24 required: true
25 type: str
26 name:
27 description:
28 - Name of VPN Gateway.
29 type: str
30 tags:
31 description:
32 - Limit results by providing a list of tags.
33 - Format tags as 'key' or 'key:value'.
34 type: list
35 elements: str
36
37 extends_documentation_fragment:
38 - azure.azcollection.azure
39
40 author:
41 - magodo (@magodo)
42 - xuzhang3 (@xuzhang3)
43 - Fred-sun (@Fred-sun)
44 '''
45
46 EXAMPLES = '''
47 - name: Get the virtual network gateway facts
48 azure_rm_virtualnetworkgateway_info:
49 resource_group: myResourceGroup
50 name: myVirtualNetworkGateway
51
52 - name: List virtual network gateway and filter by tags
53 azure_rm_virtualnetworkgateway_info:
54 resource_group: myResourceGroup
55 tags:
56 - key1
57 '''
58
59 RETURN = '''
60 virtual_network_gatways:
61 description:
62 - List the facts of the virtual network gateways.
63 type: complex
64 returned: always
65 contains:
66 bgp_settings:
67 description:
68 - Virtual network gateway's BGP speaker settings.
69 type: dict
70 returned: always
71 sample: {'asn':65515, 'bgp_peering_address':'10.0.2.254', 'peer_weight':0}
72 enable_bgp:
73 description:
74 - Whether BGP is enabled for this virtual network gateway or not.
75 type: bool
76 returned: always
77 sample: false
78 etag:
79 description:
80 - A unique read-only string that changes whenever the resource is updated.
81 type: str
82 returned: always
83 sample: 28a83384-dda9-435b-ba0c-4914c4fce18a
84 id:
85 description:
86 - Resource ID.
87 type: str
88 returned: always
89 sample: "/subscriptions/xxxx-xxxx/resourceGroups/testRG/providers/Microsoft.Network/virtualNetworkGateways/vng"
90 gateway_type:
91 description:
92 - The type of this virtual network gateway.
93 type: str
94 returned: always
95 sample: Vpn
96 ip_configurations:
97 description:
98 - IP configurations for virtual network gateway.
99 type: list
100 returned: always
101 sample: [
102 {
103 "etag": "28a83384-dda9-435b-ba0c-4914c4fce18a",
104 "id": "/subscriptions/xxxx-xxxx/resourceGroups/testRG/providers/Microsoft.Network/virtualNetworkGateways/vng/ipConfigurations/default",
105 "name": "default",
106 "private_ip_allocation_method": "Dynamic",
107 "provisioning_state": "Succeeded",
108 "public_ip_address": {
109 "id": "/subscriptions/xxxx-xxxx/resourceGroups/testRG/providers/Microsoft.Network/publicIPAddresses/testPublicIP"
110 },
111 "subnet": {
112 "id": "/subscriptions/xxxx-xxxxx/resourceGroups/testRG/providers/Microsoft.Network/virtualNetworks/vnet/subnets/GatewaySubnet"
113 }
114 }
115 ]
116 location:
117 description:
118 - Resource location.
119 type: str
120 returned: always
121 sample: eastus
122 name:
123 description:
124 - Resoure name.
125 type: str
126 returned: always
127 sample: vng
128 provisioning_state:
129 description:
130 - The provisioning state of the virtual network gateway resource.
131 type: str
132 returned: always
133 sample: Succeeded
134 resource_group:
135 description:
136 - Resource group name.
137 type: str
138 returned: always
139 sample: testRG
140 sku:
141 description:
142 - The reference to the VirtualNetworkGatewaySku resource which represents the SKU selected for Virtual network gateway.
143 type: dict
144 returned: always
145 sample: {'name':'VpnGw1AZ', 'tier':'VpnGw1AZ'}
146 tags:
147 description:
148 - Resource tags.
149 type: dict
150 returned: always
151 sample: {'common':'xyz'}
152 vpn_gateway_generation:
153 description:
154 - The generation for this VirtualNetworkGateway.
155 - Must be None if gatewayType is not VPN.
156 type: str
157 returned: always
158 sample: Generation1
159 vpn_type:
160 description:
161 - The type of this virtual network gateway.
162 type: str
163 returned: always
164 sample: RouteBaseg
165 '''
166
167 try:
168 from azure.core.exceptions import ResourceNotFoundError
169 except ImportError:
170 # This is handled in azure_rm_common
171 pass
172
173 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
174
175
176 class AzureRMVirtualNetworkGatewayInfo(AzureRMModuleBase):
177
178 def __init__(self):
179
180 self.module_arg_spec = dict(
181 resource_group=dict(type='str', required=True),
182 name=dict(type='str'),
183 tags=dict(type='list', elements='str')
184 )
185
186 self.resource_group = None
187 self.name = None
188 self.tags = None
189
190 self.results = dict(
191 changed=False,
192 virtual_network_gatways=[]
193 )
194
195 super(AzureRMVirtualNetworkGatewayInfo, self).__init__(derived_arg_spec=self.module_arg_spec,
196 supports_tags=False,
197 facts_module=True,
198 supports_check_mode=True)
199
200 def exec_module(self, **kwargs):
201
202 for key in list(self.module_arg_spec.keys()) + ['tags']:
203 setattr(self, key, kwargs[key])
204
205 if self.name is not None:
206 self.results['virtual_network_gatways'] = self.get_item()
207 else:
208 self.results['virtual_network_gatways'] = self.list_item()
209
210 return self.results
211
212 def get_item(self):
213 try:
214 response = self.network_client.virtual_network_gateways.get(self.resource_group, self.name)
215 if self.has_tags(response.tags, self.tags):
216 return [self.vgw_to_dict(response)]
217 except ResourceNotFoundError as ec:
218 self.log("The virtual network gatway {0} not exist, exception as {1}".format(self.name, ec))
219 return []
220
221 def list_item(self):
222 results = []
223 try:
224 response = self.network_client.virtual_network_gateways.list(self.resource_group)
225 for item in response:
226 if self.has_tags(item.tags, self.tags):
227 results.append(self.vgw_to_dict(item))
228 except Exception as ec:
229 self.log("List virtual network gatway catch exception as {0}".format(ec))
230 return results
231
232 def vgw_to_dict(self, vgw):
233 results = dict(
234 resource_group=self.resource_group,
235 id=vgw.id,
236 name=vgw.name,
237 location=vgw.location,
238 gateway_type=vgw.gateway_type,
239 vpn_type=vgw.vpn_type,
240 vpn_gateway_generation=vgw.vpn_gateway_generation,
241 enable_bgp=vgw.enable_bgp,
242 tags=vgw.tags,
243 provisioning_state=vgw.provisioning_state,
244 sku=dict(
245 name=vgw.sku.name,
246 tier=vgw.sku.tier
247 ),
248 bgp_settings=dict(
249 asn=vgw.bgp_settings.asn,
250 bgp_peering_address=vgw.bgp_settings.bgp_peering_address,
251 peer_weight=vgw.bgp_settings.peer_weight
252 ) if vgw.bgp_settings else None,
253 etag=vgw.etag,
254 ip_configurations=[item.as_dict() for item in vgw.ip_configurations] if vgw.ip_configurations else None
255 )
256 return results
257
258
259 def main():
260 AzureRMVirtualNetworkGatewayInfo()
261
262
263 if __name__ == '__main__':
264 main()