| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: azure_rm_virtualnetworkgatewayconnection_info |
| 14 |
|
| 15 |
version_added: "2.7.0" |
| 16 |
|
| 17 |
short_description: Gets or list the specified virtual network gateway connection |
| 18 |
|
| 19 |
description: |
| 20 |
- Gets or list the specified virtual network gateway connection. |
| 21 |
|
| 22 |
options: |
| 23 |
resource_group: |
| 24 |
description: |
| 25 |
- The name of the resource group. |
| 26 |
type: str |
| 27 |
required: true |
| 28 |
name: |
| 29 |
description: |
| 30 |
- The name of the virtual network gateway connection. |
| 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: Gets the specified local network gateway connection by name |
| 48 |
azure_rm_virtualnetworkgatewayconnection_info: |
| 49 |
resource_group: "{{ resource_group }}" |
| 50 |
name: "{{ local_networkgateway_name }}" |
| 51 |
|
| 52 |
- name: Gets all the virtual network gateway connection in a resource group |
| 53 |
azure_rm_virtualnetworkgatewayconnection_info: |
| 54 |
resource_group: "{{ resource_group }}" |
| 55 |
|
| 56 |
- name: Gets all the virtual network gateway connection in a resource group and filter by tags |
| 57 |
azure_rm_virtualnetworkgatewayconnection_info: |
| 58 |
resource_group: "{{ resource_group }}" |
| 59 |
tags: |
| 60 |
- foo |
| 61 |
''' |
| 62 |
|
| 63 |
RETURN = ''' |
| 64 |
state: |
| 65 |
description: |
| 66 |
- Current state of the Azure Virtual Network Gateway Connection resource. |
| 67 |
returned: always |
| 68 |
type: complex |
| 69 |
contains: |
| 70 |
id: |
| 71 |
description: |
| 72 |
- The resource ID. |
| 73 |
type: str |
| 74 |
returned: always |
| 75 |
sample: "/subscriptions/xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/connections/fredvnet" |
| 76 |
authorization_key: |
| 77 |
description: |
| 78 |
- The authorizationKey. |
| 79 |
type: str |
| 80 |
returned: always |
| 81 |
sample: "308201E806092A864886F*************B9FADDAC2D" |
| 82 |
connection_mode: |
| 83 |
description: |
| 84 |
- The connection mode for this connection. |
| 85 |
type: str |
| 86 |
returned: always |
| 87 |
sample: Default |
| 88 |
connection_protocol: |
| 89 |
description: |
| 90 |
- Connection protocol used for this connection. |
| 91 |
type: str |
| 92 |
returned: always |
| 93 |
sample: IKEv2 |
| 94 |
connection_type: |
| 95 |
description: |
| 96 |
- Gateway connection type. |
| 97 |
type: str |
| 98 |
returned: always |
| 99 |
sample: Vnet2Vnet |
| 100 |
dpd_timeout_seconds: |
| 101 |
description: |
| 102 |
- The dead peer detection timeout of this connection in seconds. |
| 103 |
type: int |
| 104 |
returned: always |
| 105 |
sample: 45 |
| 106 |
enable_bgp: |
| 107 |
description: |
| 108 |
- EnableBgp flag. |
| 109 |
type: bool |
| 110 |
returned: always |
| 111 |
sample: false |
| 112 |
etag: |
| 113 |
description: |
| 114 |
- A unique read-only string that changes whenever the resource is updated. |
| 115 |
type: str |
| 116 |
returned: always |
| 117 |
sample: 58b6f0c2-7d7c-4666-a62e-6416b4e00c83 |
| 118 |
express_route_gateway_bypass: |
| 119 |
description: |
| 120 |
- Bypass ExpressRoute Gateway for data forwarding. |
| 121 |
type: bool |
| 122 |
returned: always |
| 123 |
sample: false |
| 124 |
ipsec_policies: |
| 125 |
description: |
| 126 |
- The IPSec Policies to be considered by this connection. |
| 127 |
type: list |
| 128 |
returned: always |
| 129 |
sample: [] |
| 130 |
location: |
| 131 |
description: |
| 132 |
- The resource location. |
| 133 |
type: str |
| 134 |
returned: always |
| 135 |
sample: eastus |
| 136 |
name: |
| 137 |
description: |
| 138 |
- The resource name. |
| 139 |
type: str |
| 140 |
returned: always |
| 141 |
sample: fredvnetconnection |
| 142 |
provisioning_state: |
| 143 |
description: |
| 144 |
- The provisioning state of the virtual network gateway connection resource. |
| 145 |
type: str |
| 146 |
returned: always |
| 147 |
sample: Succeeded |
| 148 |
resource_group: |
| 149 |
description: |
| 150 |
- The resource group of the virtual network gateway connection. |
| 151 |
type: str |
| 152 |
returned: always |
| 153 |
sample: rg |
| 154 |
routing_weight: |
| 155 |
description: |
| 156 |
- The routing weight. |
| 157 |
type: int |
| 158 |
returned: always |
| 159 |
sample: 0 |
| 160 |
shared_key: |
| 161 |
description: |
| 162 |
- The IPSec shared key. |
| 163 |
type: str |
| 164 |
returned: always |
| 165 |
sample: null |
| 166 |
tags: |
| 167 |
description: |
| 168 |
- The resource tags. |
| 169 |
type: dict |
| 170 |
returned: always |
| 171 |
sample: {'key1': 'value1'} |
| 172 |
traffic_selector_policies: |
| 173 |
description: |
| 174 |
- The Traffic Selector Policies to be considered by this connection. |
| 175 |
type: list |
| 176 |
returned: always |
| 177 |
sample: [] |
| 178 |
use_local_azure_ip_address: |
| 179 |
description: |
| 180 |
- Use private local Azure IP for the connection. |
| 181 |
type: bool |
| 182 |
returned: always |
| 183 |
sample: false |
| 184 |
use_policy_based_traffic_selectors: |
| 185 |
description: |
| 186 |
- Enable policy-based traffic selectors. |
| 187 |
type: bool |
| 188 |
returned: always |
| 189 |
sample: false |
| 190 |
local_network_gateway2: |
| 191 |
description: |
| 192 |
- The reference to local network gateway resource. |
| 193 |
type: complex |
| 194 |
returned: when-used |
| 195 |
contains: |
| 196 |
id: |
| 197 |
description: |
| 198 |
- The ID of the local network gateway resource. |
| 199 |
type: str |
| 200 |
returned: always |
| 201 |
sample: /subscriptions/xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/localNetworkGateways/rpfx001 |
| 202 |
virtual_network_gateway1: |
| 203 |
description: |
| 204 |
- The reference to virtual network gateway resource. |
| 205 |
type: complex |
| 206 |
returned: always |
| 207 |
contains: |
| 208 |
id: |
| 209 |
description: |
| 210 |
- The ID of the virtul network gateway resource. |
| 211 |
type: str |
| 212 |
returned: always |
| 213 |
sample: /subscriptions/xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/virtualNetworkGateways/fredvng |
| 214 |
virtual_network_gateway2: |
| 215 |
description: |
| 216 |
- The reference to virtual network gateway resource. |
| 217 |
type: complex |
| 218 |
returned: always |
| 219 |
contains: |
| 220 |
id: |
| 221 |
description: |
| 222 |
- The ID of the virtul network gateway resource. |
| 223 |
type: str |
| 224 |
returned: always |
| 225 |
sample: /subscriptions/xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/virtualNetworkGateways/fredvng02 |
| 226 |
|
| 227 |
''' |
| 228 |
|
| 229 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 230 |
|
| 231 |
try: |
| 232 |
from azure.core.exceptions import HttpResponseError |
| 233 |
except Exception: |
| 234 |
|
| 235 |
pass |
| 236 |
|
| 237 |
|
| 238 |
class AzureRMVirutalNetworkGatewayConnectionInfo(AzureRMModuleBase): |
| 239 |
"""Gets or list the specified virtual network gateway connection facts""" |
| 240 |
|
| 241 |
def __init__(self): |
| 242 |
|
| 243 |
self.module_args = dict( |
| 244 |
name=dict(type='str'), |
| 245 |
resource_group=dict(type='str', required=True), |
| 246 |
tags=dict(type='list', elements='str'), |
| 247 |
) |
| 248 |
|
| 249 |
self.name = None |
| 250 |
self.tags = None |
| 251 |
self.resource_group = None |
| 252 |
|
| 253 |
self.results = dict( |
| 254 |
changed=False, |
| 255 |
state=[], |
| 256 |
) |
| 257 |
|
| 258 |
super(AzureRMVirutalNetworkGatewayConnectionInfo, self).__init__(derived_arg_spec=self.module_args, |
| 259 |
supports_check_mode=True, |
| 260 |
supports_tags=False, |
| 261 |
facts_module=True) |
| 262 |
|
| 263 |
def exec_module(self, **kwargs): |
| 264 |
|
| 265 |
for key in self.module_args: |
| 266 |
setattr(self, key, kwargs[key]) |
| 267 |
|
| 268 |
if self.name is not None: |
| 269 |
self.results['state'] = self.get_network_gateway_connection() |
| 270 |
else: |
| 271 |
self.results['state'] = self.list_network_gateway_connection() |
| 272 |
|
| 273 |
return self.results |
| 274 |
|
| 275 |
def get_network_gateway_connection(self): |
| 276 |
"""Gets the specified local network gateway connection in a resource group""" |
| 277 |
response = None |
| 278 |
|
| 279 |
try: |
| 280 |
response = self.network_client.virtual_network_gateway_connections.get(self.resource_group, self.name) |
| 281 |
except HttpResponseError as ec: |
| 282 |
self.log("Gets the specified local network gateway connection in a resource group Failed, Exception as {0}".format(ec)) |
| 283 |
if response and self.has_tags(response.tags, self.tags): |
| 284 |
return [self.format_response(response)] |
| 285 |
else: |
| 286 |
return [] |
| 287 |
|
| 288 |
def list_network_gateway_connection(self): |
| 289 |
"""Gets all the virtual network gateway connection in a resource group""" |
| 290 |
response = None |
| 291 |
|
| 292 |
try: |
| 293 |
response = self.network_client.virtual_network_gateway_connections.list(self.resource_group) |
| 294 |
except HttpResponseError as ec: |
| 295 |
self.log("Gets all the virtual network gateway connection in a resource group Failed, Exception as {0}".format(ec)) |
| 296 |
|
| 297 |
if response: |
| 298 |
results = [] |
| 299 |
for item in response: |
| 300 |
if self.has_tags(item.tags, self.tags): |
| 301 |
results.append(self.format_response(item)) |
| 302 |
return results |
| 303 |
else: |
| 304 |
return [] |
| 305 |
|
| 306 |
def format_response(self, vngwconn): |
| 307 |
|
| 308 |
result = dict( |
| 309 |
resource_group=self.resource_group, |
| 310 |
authorization_key=vngwconn.authorization_key, |
| 311 |
connection_mode=vngwconn.connection_mode, |
| 312 |
connection_protocol=vngwconn.connection_protocol, |
| 313 |
connection_type=vngwconn.connection_type, |
| 314 |
dpd_timeout_seconds=vngwconn.dpd_timeout_seconds, |
| 315 |
etag=vngwconn.etag, |
| 316 |
enable_bgp=vngwconn.enable_bgp, |
| 317 |
express_route_gateway_bypass=vngwconn.express_route_gateway_bypass, |
| 318 |
id=vngwconn.id, |
| 319 |
ipsec_policies=vngwconn.ipsec_policies, |
| 320 |
location=vngwconn.location, |
| 321 |
name=vngwconn.name, |
| 322 |
provisioning_state=vngwconn.provisioning_state, |
| 323 |
routing_weight=vngwconn.routing_weight, |
| 324 |
tags=vngwconn.tags, |
| 325 |
traffic_selector_policies=vngwconn.traffic_selector_policies, |
| 326 |
shared_key=vngwconn.shared_key, |
| 327 |
use_local_azure_ip_address=vngwconn.use_local_azure_ip_address, |
| 328 |
use_policy_based_traffic_selectors=vngwconn.use_policy_based_traffic_selectors, |
| 329 |
virtual_network_gateway1=None, |
| 330 |
virtual_network_gateway2=None, |
| 331 |
local_network_gateway2=None |
| 332 |
) |
| 333 |
if vngwconn.local_network_gateway2: |
| 334 |
result['local_network_gateway2'] = dict(id=vngwconn.local_network_gateway2.id) |
| 335 |
if vngwconn.virtual_network_gateway1: |
| 336 |
result['virtual_network_gateway1'] = dict(id=vngwconn.virtual_network_gateway1.id) |
| 337 |
if vngwconn.virtual_network_gateway2: |
| 338 |
result['virtual_network_gateway2'] = dict(id=vngwconn.virtual_network_gateway2.id) |
| 339 |
|
| 340 |
return result |
| 341 |
|
| 342 |
|
| 343 |
def main(): |
| 344 |
"""Main module execution code path""" |
| 345 |
|
| 346 |
AzureRMVirutalNetworkGatewayConnectionInfo() |
| 347 |
|
| 348 |
|
| 349 |
if __name__ == '__main__': |
| 350 |
main() |